PageRenderTime 42ms CodeModel.GetById 15ms app.highlight 19ms RepoModel.GetById 2ms app.codeStats 0ms

/tests/include/MVC/Controller/SugarControllerTest.php

https://github.com/item/sugarcrm_dev
PHP | 180 lines | 141 code | 36 blank | 3 comment | 0 complexity | 238a589d2c5f9272fa143a959a5fd201 MD5 | raw file
  1<?php
  2require_once 'include/MVC/Controller/SugarController.php';
  3
  4class SugarControllerTest extends Sugar_PHPUnit_Framework_TestCase
  5{
  6    public function setUp()
  7    {
  8        $GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
  9    }
 10    
 11    public function tearDown()
 12    {
 13        SugarTestUserUtilities::removeAllCreatedAnonymousUsers();
 14        unset($GLOBALS['current_user']);
 15    }
 16    
 17    public function testCallLegacyCodeIfLegacyListViewFound()
 18    {
 19        $module_name = 'TestModule'.mt_rand();
 20        sugar_mkdir("modules/$module_name/",null,true);
 21        sugar_touch("modules/$module_name/ListView.php");
 22        
 23        $controller = new SugarControllerMock;
 24        $controller->setup($module_name);
 25        $controller->do_action = 'ListView';
 26        $controller->view = 'list';
 27        $controller->callLegacyCode();
 28        
 29        $this->assertEquals('classic',$controller->view);
 30        
 31        rmdir_recursive("modules/$module_name");
 32    }
 33    
 34    public function testCallLegacyCodeIfNewListViewFound()
 35    {
 36        $module_name = 'TestModule'.mt_rand();
 37        sugar_mkdir("modules/$module_name/views",null,true);
 38        sugar_touch("modules/$module_name/views/view.list.php");
 39        
 40        $controller = new SugarControllerMock;
 41        $controller->setup($module_name);
 42        $controller->do_action = 'ListView';
 43        $controller->view = 'list';
 44        $controller->callLegacyCode();
 45        
 46        $this->assertEquals('list',$controller->view);
 47        
 48        rmdir_recursive("modules/$module_name");
 49    }
 50    
 51    /**
 52     * @ticket 41755
 53     */
 54    public function testCallLegacyCodeIfLegacyListViewAndNewListViewFound()
 55    {
 56        $module_name = 'TestModule'.mt_rand();
 57        sugar_mkdir("modules/$module_name/views",null,true);
 58        sugar_touch("modules/$module_name/views/view.list.php");
 59        sugar_touch("modules/$module_name/ListView.php");
 60        
 61        $controller = new SugarControllerMock;
 62        $controller->setup($module_name);
 63        $controller->do_action = 'ListView';
 64        $controller->view = 'list';
 65        $controller->callLegacyCode();
 66        
 67        $this->assertEquals('list',$controller->view);
 68        
 69        rmdir_recursive("modules/$module_name");
 70    }
 71    
 72    public function testCallLegacyCodeIfCustomLegacyListViewAndNewListViewFound()
 73    {
 74        $module_name = 'TestModule'.mt_rand();
 75        sugar_mkdir("modules/$module_name/views",null,true);
 76        sugar_touch("modules/$module_name/views/view.list.php");
 77        sugar_mkdir("custom/modules/$module_name",null,true);
 78        sugar_touch("custom/modules/$module_name/ListView.php");
 79        
 80        $controller = new SugarControllerMock;
 81        $controller->setup($module_name);
 82        $controller->do_action = 'ListView';
 83        $controller->view = 'list';
 84        $controller->callLegacyCode();
 85        
 86        $this->assertEquals('classic',$controller->view);
 87        
 88        rmdir_recursive("modules/$module_name");
 89    }
 90    
 91    public function testCallLegacyCodeIfLegacyListViewAndCustomNewListViewFound()
 92    {
 93        $module_name = 'TestModule'.mt_rand();
 94        sugar_mkdir("custom/modules/$module_name/views",null,true);
 95        sugar_touch("custom/modules/$module_name/views/view.list.php");
 96        sugar_mkdir("modules/$module_name",null,true);
 97        sugar_touch("modules/$module_name/ListView.php");
 98        
 99        $controller = new SugarControllerMock;
100        $controller->setup($module_name);
101        $controller->do_action = 'ListView';
102        $controller->view = 'list';
103        $controller->callLegacyCode();
104        
105        $this->assertEquals('classic',$controller->view);
106        
107        rmdir_recursive("modules/$module_name");
108    }
109    
110    public function testCallLegacyCodeIfLegacyListViewAndNewListViewFoundAndCustomLegacyListViewFound()
111    {
112        $module_name = 'TestModule'.mt_rand();
113        sugar_mkdir("modules/$module_name/views",null,true);
114        sugar_touch("modules/$module_name/views/view.list.php");
115        sugar_touch("modules/$module_name/ListView.php");
116        sugar_mkdir("custom/modules/$module_name",null,true);
117        sugar_touch("custom/modules/$module_name/ListView.php");
118        
119        $controller = new SugarControllerMock;
120        $controller->setup($module_name);
121        $controller->do_action = 'ListView';
122        $controller->view = 'list';
123        $controller->callLegacyCode();
124        
125        $this->assertEquals('classic',$controller->view);
126        
127        rmdir_recursive("modules/$module_name");
128    }
129    
130    public function testCallLegacyCodeIfLegacyListViewAndNewListViewFoundAndCustomNewListViewFound()
131    {
132        $module_name = 'TestModule'.mt_rand();
133        sugar_mkdir("custom/modules/$module_name/views",null,true);
134        sugar_touch("custom/modules/$module_name/views/view.list.php");
135        sugar_mkdir("modules/$module_name/views",null,true);
136        sugar_touch("modules/$module_name/views/view.list.php");
137        sugar_touch("modules/$module_name/ListView.php");
138        
139        $controller = new SugarControllerMock;
140        $controller->setup($module_name);
141        $controller->do_action = 'ListView';
142        $controller->view = 'list';
143        $controller->callLegacyCode();
144        
145        $this->assertEquals('list',$controller->view);
146        
147        rmdir_recursive("modules/$module_name");
148    }
149    
150    public function testCallLegacyCodeIfLegacyListViewAndNewListViewFoundAndCustomLegacyListViewFoundAndCustomNewListViewFound()
151    {
152        $module_name = 'TestModule'.mt_rand();
153        sugar_mkdir("custom/modules/$module_name/views",null,true);
154        sugar_touch("custom/modules/$module_name/views/view.list.php");
155        sugar_touch("custom/modules/$module_name/ListView.php");
156        sugar_mkdir("modules/$module_name/views",null,true);
157        sugar_touch("modules/$module_name/views/view.list.php");
158        sugar_touch("modules/$module_name/ListView.php");
159        
160        $controller = new SugarControllerMock;
161        $controller->setup($module_name);
162        $controller->do_action = 'ListView';
163        $controller->view = 'list';
164        $controller->callLegacyCode();
165        
166        $this->assertEquals('list',$controller->view);
167        
168        rmdir_recursive("modules/$module_name");
169    }
170}
171
172class SugarControllerMock extends SugarController
173{
174    public $do_action;
175    
176    public function callLegacyCode()
177    {
178        return parent::callLegacyCode();
179    }
180}