Created
December 18, 2011 00:13
-
-
Save icambridge/1491881 to your computer and use it in GitHub Desktop.
Controller testing lithium
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\tests\cases\controllers; | |
use app\controllers\ArticlesController; | |
use app\tests\mocks\MockArticlesController; | |
class ArticlesControllerTest extends \lithium\test\Unit { | |
protected $_controller; | |
public function setUp() { | |
$this->_controller = new MockArticlesController(); | |
} | |
public function tearDown() {} | |
public function testIndexList() { | |
$this->_controller->index(); | |
$render = $this->_controller->access('_render'); | |
$viewVars = $render['data']; | |
$this->assertTrue(isset($viewVars['test']),"The index 'test' isn't set"); | |
$this->assertEqual("test",$viewVars['test'],"The string should be 'test'"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\controllers; | |
class ArticlesController extends \lithium\action\Controller { | |
public function index() { | |
$this->set(array('test' => 'test')); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace app\tests\mocks; | |
use app\controllers\ArticlesController; | |
class MockArticlesController extends ArticlesController { | |
public function access($varName) { | |
return $this->{$varName}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment