MediaTest.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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\integration\net\http;
  9. use lithium\net\http\Media;
  10. use lithium\net\http\Response;
  11. class MediaTest extends \lithium\test\Integration {
  12. /**
  13. * This tests that setting custom paths and disabling layout
  14. * via `\lithium\net\http\Media::type()` is handled properly
  15. * by the default `\lithium\template\View` class and `File`
  16. * rendered adapter.
  17. */
  18. public function testMediaTypeViewRender() {
  19. Media::type('view-integration-test', 'lithium/viewtest', array(
  20. 'view' => 'lithium\template\View',
  21. 'paths' => array(
  22. 'layout' => false,
  23. 'template' => array(
  24. '{:library}/tests/mocks/template/view/adapters/{:template}.{:type}.php',
  25. '{:library}/tests/mocks/template/view/adapters/{:template}.html.php'
  26. )
  27. )
  28. ));
  29. // testing no layout with a custom type template
  30. $response = new Response();
  31. $response->type('view-integration-test');
  32. Media::render($response, array(), array(
  33. 'layout' => true,
  34. 'library' => 'lithium',
  35. 'template' => 'testTypeFile'
  36. ));
  37. $this->assertEqual('This is a type test.', $response->body());
  38. // testing the template falls back to the html template
  39. $response = new Response();
  40. $response->type('view-integration-test');
  41. Media::render($response, array(), array(
  42. 'layout' => true,
  43. 'library' => 'lithium',
  44. 'template' => 'testFile'
  45. ));
  46. $this->assertEqual('This is a test.', $response->body());
  47. // testing with a layout
  48. Media::type('view-integration-test', 'lithium/viewtest', array(
  49. 'view' => 'lithium\template\View',
  50. 'paths' => array(
  51. 'layout' => '{:library}/tests/mocks/template/view/adapters/testLayoutFile.html.php',
  52. 'template' => array(
  53. '{:library}/tests/mocks/template/view/adapters/{:template}.{:type}.php',
  54. '{:library}/tests/mocks/template/view/adapters/{:template}.html.php'
  55. )
  56. )
  57. ));
  58. $response = new Response();
  59. $response->type('view-integration-test');
  60. Media::render($response, array(), array(
  61. 'layout' => true,
  62. 'library' => 'lithium',
  63. 'template' => 'testTypeFile'
  64. ));
  65. $this->assertEqual("Layout top.\nThis is a type test.Layout bottom.", $response->body());
  66. }
  67. }
  68. ?>