]> CyberLeo.Net >> Repos - Github/sugarcrm.git/blob - tests/ModuleInstall/PackageManager/Bug39980Test.php
Release 6.2.0
[Github/sugarcrm.git] / tests / ModuleInstall / PackageManager / Bug39980Test.php
1 <?php
2 /*********************************************************************************
3  * SugarCRM Community Edition is a customer relationship management program developed by
4  * SugarCRM, Inc. Copyright (C) 2004-2011 SugarCRM Inc.
5  * 
6  * This program is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU Affero General Public License version 3 as published by the
8  * Free Software Foundation with the addition of the following permission added
9  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
10  * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
11  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
12  * 
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
16  * details.
17  * 
18  * You should have received a copy of the GNU Affero General Public License along with
19  * this program; if not, see http://www.gnu.org/licenses or write to the Free
20  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21  * 02110-1301 USA.
22  * 
23  * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
24  * SW2-130, Cupertino, CA 95014, USA. or at email address contact@sugarcrm.com.
25  * 
26  * The interactive user interfaces in modified source and object code versions
27  * of this program must display Appropriate Legal Notices, as required under
28  * Section 5 of the GNU Affero General Public License version 3.
29  * 
30  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
31  * these Appropriate Legal Notices must retain the display of the "Powered by
32  * SugarCRM" logo. If the display of the logo is not reasonably feasible for
33  * technical reasons, the Appropriate Legal Notices must display the words
34  * "Powered by SugarCRM".
35  ********************************************************************************/
36
37 require_once 'ModuleInstall/PackageManager/PackageManager.php';
38
39 class Bug39980Test extends Sugar_PHPUnit_Framework_TestCase
40 {
41         
42     public function tearDown()
43     {
44         if (is_file(Bug39980PackageManger::$manifest_location))
45             unlink(Bug39980PackageManger::$manifest_location);
46     }
47
48     public function testGetinstalledPackagesUninstallable()
49     {  
50         $pm = new Bug39980PackageManger();
51         $pm->extractManifest(0, 0);
52         $packs = $pm->getinstalledPackages();
53         //Its confusing, but "UNINSTALLABLE" in file_install means the package is NOT uninstallable
54         $this->assertEquals("UNINSTALLABLE", $packs[0]['file_install']);
55     }
56
57 }
58
59 class Bug39980PackageManger extends PackageManager {
60         static $manifest_location = "cache/Bug39980manifest.php";
61         
62         public function __construct() {
63            parent::__construct();
64            $this->manifest_content = <<<EOQ
65 <?php
66 \$manifest = array (
67          'acceptable_sugar_versions' => 
68           array (
69             '6.1.0'
70           ),
71           'acceptable_sugar_flavors' =>
72           array(
73             'ENT'
74           ),
75           'readme'=>'',
76           'key'=>'tf1',
77           'author' => '',
78           'description' => '',
79           'icon' => '',
80           'is_uninstallable' => false,
81           'name' => 'test_file_1',
82           'published_date' => '2010-10-20 22:10:01',
83           'type' => 'module',
84           'version' => '1287612601',
85           'remove_tables' => 'prompt',
86           );
87 \$installdefs = array (
88   'id' => 'asdfqq',
89   'copy' => 
90   array (
91      0 => array (
92       'from' => '<basepath>/Extension/modules/Cases/Ext/Vardefs/dummy_extension2.php',
93       'to' => 'custom/Extension/modules/Cases/Ext/Vardefs/dummy_extension2.php',
94     ),
95   ),
96 );    
97         
98 EOQ;
99         }
100
101         public function getInstalled($types)
102         {
103                 include($this->extractManifest(0,0));
104                 $sm = array(
105                     'manifest'         => (isset($manifest) ? $manifest : ''),
106             'installdefs'      => (isset($installdefs) ? $installdefs : ''),
107             'upgrade_manifest' => (isset($upgrade_manifest) ? $upgrade_manifest : '')
108                 );
109                 return array (
110                         (object) array(
111                             'filename' => Bug39980PackageManger::$manifest_location,
112                             'manifest' => base64_encode(serialize($sm)),
113                             'date_entered' => '1/1/2010',
114                             'new_schema' => '1',
115                             'module_dir' => 'Administration' ,
116                             'id' => 'b4d22740-4e96-65b3-b712-4ca230d95987' ,
117                             'md5sum' => 'fe221d731d8c624f15712878300aa907' ,
118                             'type' => 'module' ,
119                             'version' => '1285697780' ,
120                             'status' => 'installed' ,
121                             'name' => 'test_file_1' ,
122                             'description' => '' ,
123                             'id_name' => 'tf1' ,
124                             'enabled' => true ,
125                         )
126                 );
127         }
128         
129         public function extractManifest($filename, $base_tmp_upgrade_dir)
130         {
131            if (!is_file(Bug39980PackageManger::$manifest_location))
132                file_put_contents(Bug39980PackageManger::$manifest_location, $this->manifest_content);
133            
134            return Bug39980PackageManger::$manifest_location;
135         }
136 }