| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 2004-2007 BIT(http://bit-creative.com) 7 * @license LGPL http://www.gnu.org/copyleft/lesser.html 8 */ 9 lmb_require('limb/web_app/src/controller/lmbStaticCommandController.class.php'); 10 lmb_require('limb/core/src/lmbObject.class.php'); 11 12 class TestingStaticCommandController extends lmbStaticCommandController 13 { 14 protected $default_action = 'admin_display'; 15 protected $name = 'testing'; 16 17 // To be able to set actions properties right from the tests 18 function setTestingActions($actions) 19 { 20 $this->actions = $actions; 21 } 22 } 23 24 class TestingStaticCommandControllerStubCommand implements lmbCommand 25 { 26 public $was_performed = false; 27 28 function perform() 29 { 30 $this->was_performed = true; 31 } 32 } 33 34 class lmbStaticCommandControllerTest extends UnitTestCase 35 { 36 function testGetDifferentProperties() 37 { 38 $controller = new TestingStaticCommandController(); 39 $controller->setTestingActions(array('action1' => array(), 40 'action2' => array('prop2' => 'any_other_value', 41 'p' => 1))); 42 43 $this->assertEqual($controller->getName(), 'testing'); 44 45 $this->assertEqual(array('action1', 'action2'), 46 $controller->getActionsList()); 47 48 $this->assertTrue($controller->actionExists('action1')); 49 $this->assertFalse($controller->actionExists('no_such_action')); 50 51 $this->assertEqual($controller->getActionProperties('action2'), 52 array('prop2' => 'any_other_value', 'p' => 1)); 53 54 $this->assertEqual($controller->getActionProperties('no-such-action'), 55 array()); 56 57 $this->assertEqual($controller->getDefaultAction(), 'admin_display'); 58 } 59 60 function testPerformActionThrowExceptionIfCommandNotDefined() 61 { 62 $controller = new TestingStaticCommandController(); 63 $controller->setCurrentAction($action = 'not_such_action'); 64 65 try 66 { 67 $command = $controller->performAction(); 68 $this->assertTrue(false); 69 } 70 catch(lmbException $e){} 71 } 72 73 function testPerformCommandOk() 74 { 75 $actions = array('display' => array('title' => 'Display Action', 76 'command' => $command = new TestingStaticCommandControllerStubCommand())); 77 78 $controller = new TestingStaticCommandController(); 79 $controller->setTestingActions($actions); 80 $controller->setCurrentAction($action = 'display'); 81 $controller->performAction(); 82 $this->assertTrue($command->was_performed); 83 } 84 85 function testGetActionCommand() 86 { 87 $actions = array('display' => array('title' => 'Display Action', 88 'command' => 'TestingStaticCommandControllerStubCommand')); 89 90 $controller = new TestingStaticCommandController(); 91 $controller->setTestingActions($actions); 92 $controller->setCurrentAction($action = 'display'); 93 $command = $controller->getActionCommand(); 94 $this->assertTrue($command instanceof TestingStaticCommandControllerStubCommand); 95 } 96 97 function testGetActionCommandAsHandleFromArray() 98 { 99 $actions = array('display' => array('title' => 'Display Action', 100 'command' => array('limb/web_app/src/command/lmbActionCommand', 101 $path = 'path.html'))); 102 103 $controller = new TestingStaticCommandController(); 104 $controller->setTestingActions($actions); 105 $controller->setCurrentAction($action = 'display'); 106 $command = $controller->getActionCommand(); 107 $this->assertEqual($command->getTemplatePath(), $path); 108 } 109 110 function testGetActionCommandAsProxyObject() 111 { 112 $actions = array('display' => array('title' => 'Display Action', 113 'command' => new lmbHandle('limb/web_app/src/command/lmbActionCommand', 114 array($path = 'path.html')))); 115 116 $controller = new TestingStaticCommandController(); 117 $controller->setTestingActions($actions); 118 $controller->setCurrentAction($action = 'display'); 119 $command = $controller->getActionCommand(); 120 $this->assertEqual($command->getTemplatePath(), $path); 121 } 122 123 function testGetActionThrowsExceptionOfInvalidCommandProperty() 124 { 125 $actions = array('display' => array('title' => 'Display Action', 126 'command' => new lmbObject())); 127 128 $controller = new TestingStaticCommandController(); 129 $controller->setTestingActions($actions); 130 $controller->setCurrentAction($action = 'display'); 131 try 132 { 133 $controller->getActionCommand(); 134 $this->assertTrue(false); 135 } 136 catch(lmbException $e){} 137 } 138 } 139 140 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Oct 15 04:31:08 2008 | Cross-referenced by PHPXref 0.7 |