PageRenderTime 48ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/cases/Application/UI/ControlTest.php

http://github.com/nella/framework
PHP | 137 lines | 98 code | 22 blank | 17 comment | 2 complexity | 6af360cea6a8d8c08c7ac0b9628f9ebf MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * This file is part of the Nella Framework (http://nellafw.org).
  4. *
  5. * Copyright (c) 2006, 2012 Patrik VotoƄ?ek (http://patrik.votocek.cz)
  6. *
  7. * For the full copyright and license information, please view the file LICENSE.txt that was distributed with this source code.
  8. */
  9. namespace NellaTests\Application\UI;
  10. class ControlTest extends \Nella\Testing\TestCase
  11. {
  12. /** @var Control\ControlMock */
  13. private $control;
  14. public function setup()
  15. {
  16. parent::setup();
  17. $context = $this->getContext();
  18. $formatter = new \Nella\Templating\TemplateFilesFormatter;
  19. $formatter->addDir(__DIR__, 5)
  20. ->addDir($context->parameters['appDir'], 999)
  21. ->addDir($context->expand('%appDir%/Nella'), 0);
  22. if (!$context->hasService('nella')) {
  23. $context->addService('nella', new \Nette\DI\NestedAccessor($context, 'nella'));
  24. }
  25. $context->removeService('nella.templateFilesFormatter');
  26. $context->addService('nella.templateFilesFormatter', $formatter);
  27. $this->control = new Control\ControlMock(new Control\PresenterMock($context), 'test');
  28. }
  29. public function dataFormatTemplateFiles()
  30. {
  31. $context = $this->getContext();
  32. return array(
  33. array('render', array(
  34. $context->parameters['appDir'] . "/Application/UI/Control/ControlMock.latte",
  35. $context->parameters['appDir'] . "/Application/UI/Control/ControlMock/@global.latte",
  36. $context->parameters['appDir'] . "/Application/UI/Control/@global.latte",
  37. __DIR__ . "/Application/UI/Control/ControlMock.latte",
  38. __DIR__ . "/Application/UI/Control/ControlMock/@global.latte",
  39. __DIR__ . "/Application/UI/Control/@global.latte",
  40. $context->expand('%appDir%/Nella') . "/Application/UI/Control/ControlMock.latte",
  41. $context->expand('%appDir%/Nella') . "/Application/UI/Control/ControlMock/@global.latte",
  42. $context->expand('%appDir%/Nella') . "/Application/UI/Control/@global.latte",
  43. )),
  44. array('renderTest', array(
  45. $context->parameters['appDir'] . "/Application/UI/Control/ControlMock/test.latte",
  46. $context->parameters['appDir'] . "/Application/UI/Control/ControlMock.test.latte",
  47. $context->parameters['appDir'] . "/Application/UI/Control/ControlMock/@global.latte",
  48. $context->parameters['appDir'] . "/Application/UI/Control/@global.latte",
  49. __DIR__ . "/Application/UI/Control/ControlMock/test.latte",
  50. __DIR__ . "/Application/UI/Control/ControlMock.test.latte",
  51. __DIR__ . "/Application/UI/Control/ControlMock/@global.latte",
  52. __DIR__ . "/Application/UI/Control/@global.latte",
  53. $context->expand('%appDir%/Nella') . "/Application/UI/Control/ControlMock/test.latte",
  54. $context->expand('%appDir%/Nella') . "/Application/UI/Control/ControlMock.test.latte",
  55. $context->expand('%appDir%/Nella') . "/Application/UI/Control/ControlMock/@global.latte",
  56. $context->expand('%appDir%/Nella') . "/Application/UI/Control/@global.latte",
  57. )),
  58. );
  59. }
  60. /**
  61. * @dataProvider dataFormatTemplateFiles
  62. */
  63. public function testFormatTemplateFiles($method, $eq)
  64. {
  65. $files = $this->control->formatTemplateFilesMock($method);
  66. $this->assertEquals($eq, $files, "->formatTemplateFiles('$method')");
  67. }
  68. public function testFormatTemplateFile()
  69. {
  70. $fixturesDir = $this->getContext()->parameters['fixturesDir'];
  71. $this->getContext()->getService('nella.templateFilesFormatter')
  72. ->addDir($fixturesDir);
  73. $this->assertEquals(
  74. $fixturesDir . "/Application/UI/Control/ControlMock.latte",
  75. $this->control->formatTemplateFileMock('render'),
  76. "->formatTemplateFile for default view"
  77. );
  78. }
  79. /**
  80. * @expectedException Nette\InvalidStateException
  81. */
  82. public function testFormatTemplateFileException()
  83. {
  84. $this->control->formatTemplateFileMock('renderFoo');
  85. }
  86. /**
  87. * @depends testFormatTemplateFile
  88. */
  89. public function testRender()
  90. {
  91. $this->getContext()->getService('nella.templateFilesFormatter')
  92. ->addDir($this->getContext()->parameters['fixturesDir']);
  93. ob_start();
  94. $this->control->render();
  95. $data = ob_get_clean();
  96. $this->assertEquals("TEST", $data, "->render()");
  97. }
  98. }
  99. namespace NellaTests\Application\UI\Control;
  100. class PresenterMock extends \Nella\Application\UI\Presenter { }
  101. class ControlMock extends \Nella\Application\UI\Control
  102. {
  103. public function formatTemplateFilesMock($method)
  104. {
  105. return $this->formatTemplateFiles($method);
  106. }
  107. public function formatTemplateFileMock($method)
  108. {
  109. return $this->formatTemplateFile($method);
  110. }
  111. public function render()
  112. {
  113. $this->_render(__METHOD__);
  114. }
  115. }