Exemplo n.º 1
0
 /**
  * testMergeVars method
  *
  * @return void
  */
 public function testMergeVars()
 {
     $request = new CakeRequest('controller_posts/index');
     $TestController = new TestController($request);
     $TestController->constructClasses();
     $testVars = get_class_vars('TestController');
     $appVars = get_class_vars('ControllerTestAppController');
     $components = is_array($appVars['components']) ? array_merge($appVars['components'], $testVars['components']) : $testVars['components'];
     if (!in_array('Session', $components)) {
         $components[] = 'Session';
     }
     $helpers = is_array($appVars['helpers']) ? array_merge($appVars['helpers'], $testVars['helpers']) : $testVars['helpers'];
     $uses = is_array($appVars['uses']) ? array_merge($appVars['uses'], $testVars['uses']) : $testVars['uses'];
     $this->assertEquals(0, count(array_diff_key($TestController->helpers, array_flip($helpers))));
     $this->assertEquals(0, count(array_diff($TestController->uses, $uses)));
     $this->assertEquals(count(array_diff_assoc(Hash::normalize($TestController->components), Hash::normalize($components))), 0);
     $expected = array('ControllerComment', 'ControllerAlias', 'ControllerPost');
     $this->assertEquals($expected, $TestController->uses, '$uses was merged incorrectly, ControllerTestAppController models should be last.');
     $TestController = new AnotherTestController($request);
     $TestController->constructClasses();
     $appVars = get_class_vars('ControllerTestAppController');
     $testVars = get_class_vars('AnotherTestController');
     $this->assertTrue(in_array('ControllerPost', $appVars['uses']));
     $this->assertFalse($testVars['uses']);
     $this->assertFalse(property_exists($TestController, 'ControllerPost'));
     $TestController = new ControllerCommentsController($request);
     $TestController->constructClasses();
     $appVars = get_class_vars('ControllerTestAppController');
     $testVars = get_class_vars('ControllerCommentsController');
     $this->assertTrue(in_array('ControllerPost', $appVars['uses']));
     $this->assertEquals(array('ControllerPost'), $testVars['uses']);
     $this->assertTrue(isset($TestController->ControllerPost));
     $this->assertTrue(isset($TestController->ControllerComment));
 }
Exemplo n.º 2
0
 /**
  * testMergeVars method
  *
  * @access public
  * @return void
  */
 function testMergeVars()
 {
     if ($this->skipIf(defined('APP_CONTROLLER_EXISTS'), '%s Need a non-existent AppController')) {
         return;
     }
     $TestController = new TestController();
     $TestController->constructClasses();
     $testVars = get_class_vars('TestController');
     $appVars = get_class_vars('AppController');
     $components = is_array($appVars['components']) ? array_merge($appVars['components'], $testVars['components']) : $testVars['components'];
     if (!in_array('Session', $components)) {
         $components[] = 'Session';
     }
     $helpers = is_array($appVars['helpers']) ? array_merge($appVars['helpers'], $testVars['helpers']) : $testVars['helpers'];
     $uses = is_array($appVars['uses']) ? array_merge($appVars['uses'], $testVars['uses']) : $testVars['uses'];
     $this->assertEqual(count(array_diff($TestController->helpers, $helpers)), 0);
     $this->assertEqual(count(array_diff($TestController->uses, $uses)), 0);
     $this->assertEqual(count(array_diff_assoc(Set::normalize($TestController->components), Set::normalize($components))), 0);
     $TestController = new AnotherTestController();
     $TestController->constructClasses();
     $appVars = get_class_vars('AppController');
     $testVars = get_class_vars('AnotherTestController');
     $this->assertTrue(in_array('ControllerPost', $appVars['uses']));
     $this->assertNull($testVars['uses']);
     $this->assertFalse(isset($TestController->ControllerPost));
     $TestController = new ControllerCommentsController();
     $TestController->constructClasses();
     $appVars = get_class_vars('AppController');
     $testVars = get_class_vars('ControllerCommentsController');
     $this->assertTrue(in_array('ControllerPost', $appVars['uses']));
     $this->assertEqual(array('ControllerPost'), $testVars['uses']);
     $this->assertTrue(isset($TestController->ControllerPost));
     $this->assertTrue(isset($TestController->ControllerComment));
 }