ModelTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. /**
  3. * Lithium: the most rad php framework
  4. *
  5. * @copyright Copyright 2013, Union of RAD (http://union-of-rad.org)
  6. * @license http://opensource.org/licenses/bsd-license.php The BSD License
  7. */
  8. namespace lithium\tests\cases\console\command\create;
  9. use lithium\console\command\create\Model;
  10. use lithium\console\Request;
  11. use lithium\core\Libraries;
  12. class ModelTest extends \lithium\test\Unit {
  13. public $request;
  14. protected $_backup = array();
  15. protected $_testPath = null;
  16. public function skip() {
  17. $this->_testPath = Libraries::get(true, 'resources') . '/tmp/tests';
  18. $this->skipIf(!is_writable($this->_testPath), "Path `{$this->_testPath}` is not writable.");
  19. }
  20. public function setUp() {
  21. $this->classes = array('response' => 'lithium\tests\mocks\console\MockResponse');
  22. $this->_backup['cwd'] = getcwd();
  23. $this->_backup['_SERVER'] = $_SERVER;
  24. $_SERVER['argv'] = array();
  25. Libraries::add('create_test', array('path' => $this->_testPath . '/create_test'));
  26. $this->request = new Request(array('input' => fopen('php://temp', 'w+')));
  27. $this->request->params = array('library' => 'create_test');
  28. }
  29. public function tearDown() {
  30. $_SERVER = $this->_backup['_SERVER'];
  31. chdir($this->_backup['cwd']);
  32. $this->_cleanUp();
  33. }
  34. public function testClass() {
  35. $this->request->params = array(
  36. 'command' => 'model', 'action' => 'Posts'
  37. );
  38. $model = new Model(array(
  39. 'request' => $this->request, 'classes' => $this->classes
  40. ));
  41. $expected = 'Posts';
  42. $result = $model->invokeMethod('_class', array($this->request));
  43. $this->assertEqual($expected, $result);
  44. }
  45. }
  46. ?>