]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/ModuleInstall/PackageManager/Bug39980Test.php
Added unit tests.
[Github/sugarcrm.git] / tests / ModuleInstall / PackageManager / Bug39980Test.php
1 <?php
2 require_once 'ModuleInstall/PackageManager/PackageManager.php';
3
4 class Bug39980Test extends Sugar_PHPUnit_Framework_TestCase
5 {
6         
7     public function tearDown()
8     {
9         if (is_file(Bug39980PackageManger::$manifest_location))
10             unlink(Bug39980PackageManger::$manifest_location);
11     }
12
13     public function testGetinstalledPackagesUninstallable()
14     {  
15         $pm = new Bug39980PackageManger();
16         $pm->extractManifest(0, 0);
17         $packs = $pm->getinstalledPackages();
18         //Its confusing, but "UNINSTALLABLE" in file_install means the package is NOT uninstallable
19         $this->assertEquals("UNINSTALLABLE", $packs[0]['file_install']);
20     }
21
22 }
23
24 class Bug39980PackageManger extends PackageManager {
25         static $manifest_location = "cache/Bug39980manifest.php";
26         
27         public function __construct() {
28            parent::__construct();
29            $this->manifest_content = <<<EOQ
30 <?php
31 \$manifest = array (
32          'acceptable_sugar_versions' => 
33           array (
34             '6.1.0'
35           ),
36           'acceptable_sugar_flavors' =>
37           array(
38             'ENT'
39           ),
40           'readme'=>'',
41           'key'=>'tf1',
42           'author' => '',
43           'description' => '',
44           'icon' => '',
45           'is_uninstallable' => false,
46           'name' => 'test_file_1',
47           'published_date' => '2010-10-20 22:10:01',
48           'type' => 'module',
49           'version' => '1287612601',
50           'remove_tables' => 'prompt',
51           );
52 \$installdefs = array (
53   'id' => 'asdfqq',
54   'copy' => 
55   array (
56      0 => array (
57       'from' => '<basepath>/Extension/modules/Cases/Ext/Vardefs/dummy_extension2.php',
58       'to' => 'custom/Extension/modules/Cases/Ext/Vardefs/dummy_extension2.php',
59     ),
60   ),
61 );    
62         
63 EOQ;
64         }
65
66         public function getInstalled($types)
67         {
68                 include($this->extractManifest(0,0));
69                 $sm = array(
70                     'manifest'         => (isset($manifest) ? $manifest : ''),
71             'installdefs'      => (isset($installdefs) ? $installdefs : ''),
72             'upgrade_manifest' => (isset($upgrade_manifest) ? $upgrade_manifest : '')
73                 );
74                 return array (
75                         (object) array(
76                             'filename' => Bug39980PackageManger::$manifest_location,
77                             'manifest' => base64_encode(serialize($sm)),
78                             'date_entered' => '1/1/2010',
79                             'new_schema' => '1',
80                             'module_dir' => 'Administration' ,
81                             'id' => 'b4d22740-4e96-65b3-b712-4ca230d95987' ,
82                             'md5sum' => 'fe221d731d8c624f15712878300aa907' ,
83                             'type' => 'module' ,
84                             'version' => '1285697780' ,
85                             'status' => 'installed' ,
86                             'name' => 'test_file_1' ,
87                             'description' => '' ,
88                             'id_name' => 'tf1' ,
89                             'enabled' => true ,
90                         )
91                 );
92         }
93         
94         public function extractManifest($filename, $base_tmp_upgrade_dir)
95         {
96            if (!is_file(Bug39980PackageManger::$manifest_location))
97                file_put_contents(Bug39980PackageManger::$manifest_location, $this->manifest_content);
98            
99            return Bug39980PackageManger::$manifest_location;
100         }
101 }