PageRenderTime 57ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/share/test/web/response/pagecacheadagent-test.php

https://github.com/php-tox/tox
PHP | 116 lines | 63 code | 11 blank | 42 comment | 0 complexity | afc56a67855ba0ed13c7a6043fada0de MD5 | raw file
Possible License(s): GPL-3.0
  1. <?php
  2. /**
  3. * Defines the test case for Tox\Web\Response\PageCacheAgent.
  4. *
  5. * This file is part of Tox.
  6. *
  7. * Tox is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation, either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * Tox is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with Tox. If not, see <http://www.gnu.org/licenses/>.
  19. *
  20. * @copyright Š 2012-2013 PHP-Tox.org
  21. * @license GNU General Public License, version 3
  22. */
  23. namespace Tox\Web\Response;
  24. use PHPUnit_Framework_TestCase;
  25. require_once __DIR__ . '/../../../../src/core/assembly.php';
  26. require_once __DIR__ . '/../../../../src/application/ioutputtask.php';
  27. require_once __DIR__ . '/../../../../src/web/ipagecacheagent.php';
  28. require_once __DIR__ . '/../../../../src/web/response/pagecacheagent.php';
  29. require_once __DIR__ . '/../../../../src/core/exception.php';
  30. require_once __DIR__ . '/../../../../src/web/response/responserequiredexception.php';
  31. require_once __DIR__ . '/../../../../src/application/ioutput.php';
  32. require_once __DIR__ . '/../../../../src/application/output/output.php';
  33. require_once __DIR__ . '/../../../../src/web/iresponse.php';
  34. require_once __DIR__ . '/../../../../src/web/response/response.php';
  35. require_once __DIR__ . '/../../../../src/web/ihttpheadersprocessor.php';
  36. require_once __DIR__ . '/../../../../src/web/response/httpheadersprocessor.php';
  37. require_once __DIR__ . '/../../../../src/web/ipagecache.php';
  38. require_once __DIR__ . '/../../../../src/application/iview.php';
  39. require_once __DIR__ . '/../../../../src/application/view/view.php';
  40. require_once __DIR__ . '/../../../../src/application/istreamingview.php';
  41. require_once __DIR__ . '/../../../../src/application/view/streamingview.php';
  42. /**
  43. * Tests Tox\Web\Response\PageCacheAgent.
  44. *
  45. * @internal
  46. *
  47. * @package tox.web.response
  48. * @author Snakevil Zen <zsnakevil@gmail.com>
  49. */
  50. class PageCacheAgentTest extends PHPUnit_Framework_TestCase
  51. {
  52. /**
  53. * @expectedException Tox\Web\Response\ResponseRequiredException
  54. */
  55. public function testConstructing()
  56. {
  57. new PageCacheAgent($this->getMock('Tox\\Application\\IOutput'));
  58. }
  59. public function testSettingPageCache()
  60. {
  61. $o_out = new Response;
  62. $o_pca = $this->getMock('Tox\\Web\\Response\\PageCacheAgent', array('attach'), array($o_out));
  63. $o_cache = $this->getMock('Tox\\Web\\IPageCache');
  64. $o_pca->expects($this->once())->method('attach')->with($this->equalTo($o_cache));
  65. $o_out->setPageCacheAgent($o_pca)->cacheTo($o_cache);
  66. }
  67. /**
  68. * @depends testSettingPageCache
  69. */
  70. public function testFetchingOutputtingBuffer()
  71. {
  72. $o_out = $this->getMock('Tox\\Web\\Response\\Response', array('getBuffer'));
  73. $o_out->setHeadersProcessor($this->getMock('Tox\\Web\\Response\\HTTPHeadersProcessor', array(), array($o_out)))
  74. ->cacheTo($this->getMock('Tox\\Web\\IPageCache'))
  75. ->expects($this->once())->method('getBuffer');
  76. ob_start();
  77. $o_out->writeClose('foo');
  78. ob_end_clean();
  79. }
  80. /**
  81. * @depends testFetchingOutputtingBuffer
  82. */
  83. public function testPageCacheRequired()
  84. {
  85. $o_out = $this->getMock('Tox\\Web\\Response\\Response', array('getBuffer'));
  86. $o_out->expects($this->never())->method('getBuffer');
  87. ob_start();
  88. $o_out->close();
  89. ob_end_clean();
  90. }
  91. /**
  92. * @depends testFetchingOutputtingBuffer
  93. */
  94. public function testFillingPageCache()
  95. {
  96. $s_buff = microtime();
  97. $o_out = new Response;
  98. $o_cache = $this->getMock('Tox\\Web\\IPageCache');
  99. $o_cache->expects($this->once())->method('put')->with($this->equalTo($s_buff));
  100. ob_start();
  101. $o_out->cacheTo($o_cache)->writeClose($s_buff);
  102. ob_end_clean();
  103. }
  104. }
  105. // vi:ft=php fenc=utf-8 ff=unix ts=4 sts=4 et sw=4 fen fdm=indent fdl=1 tw=120