ViewTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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\View;
  10. use lithium\console\Request;
  11. use lithium\core\Libraries;
  12. class ViewTest 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 testRun() {
  35. $this->request->params += array(
  36. 'command' => 'create', 'template' => 'test-view', 'action' => 'view',
  37. 'args' => array('Posts', 'index.html')
  38. );
  39. $plateFolder = $this->_testPath . '/create_test/extensions/command/create/template';
  40. if (!is_dir($plateFolder)) {
  41. mkdir($plateFolder, 0755, true);
  42. }
  43. file_put_contents($plateFolder . '/test-view.txt.php', '|{:name}|{:plural}|{:singular}|');
  44. $view = new View(array(
  45. 'request' => $this->request, 'classes' => $this->classes
  46. ));
  47. $view->path = $this->_testPath;
  48. $view->run('view');
  49. $expected = "index.html.php created in views/posts.\n";
  50. $result = $view->response->output;
  51. $this->assertEqual($expected, $result);
  52. $expected = '|Posts|posts|post|';
  53. $result = file_get_contents($this->_testPath . '/create_test/views/posts/index.html.php');
  54. $this->assertEqual($expected, $result);
  55. }
  56. }
  57. ?>