CookieHelperTest.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <?php
  2. namespace Tools\TestCase\View\Helper;
  3. use Cake\Datasource\ConnectionManager;
  4. use Cake\Network\Request;
  5. use Cake\ORM\Entity;
  6. use Cake\ORM\Table;
  7. use Cake\ORM\TableRegistry;
  8. use Cake\View\View;
  9. use Tools\TestSuite\TestCase;
  10. use Tools\View\Helper\CookieHelper;
  11. class CookieHelperTest extends TestCase {
  12. /**
  13. * @var \Tools\View\Helper\CookieHelper
  14. */
  15. public $Cookie;
  16. /**
  17. * @return void
  18. */
  19. public function setUp() {
  20. parent::setUp();
  21. $this->Cookie = new CookieHelper(new View(null));
  22. $this->Cookie->request = $this->getMock('Cake\Network\Request', ['cookie']);
  23. }
  24. /**
  25. * @return void
  26. */
  27. public function tearDown() {
  28. unset($this->Table);
  29. parent::tearDown();
  30. }
  31. /**
  32. * CookieHelperTest::testObject()
  33. *
  34. * @return void
  35. */
  36. public function testObject() {
  37. $this->assertInstanceOf('Tools\View\Helper\CookieHelper', $this->Cookie);
  38. }
  39. /**
  40. * CookieHelperTest::testCheck()
  41. *
  42. * @return void
  43. */
  44. public function testCheck() {
  45. $this->Cookie->request->expects($this->at(0))
  46. ->method('cookie')
  47. ->will($this->returnValue(null));
  48. $this->Cookie->request->expects($this->at(1))
  49. ->method('cookie')
  50. ->will($this->returnValue('val'));
  51. $this->assertFalse($this->Cookie->check('Foo.key'));
  52. $this->assertTrue($this->Cookie->check('Foo.key'));
  53. }
  54. /**
  55. * CookieHelperTest::testRead()
  56. *
  57. * @return void
  58. */
  59. public function testRead() {
  60. $this->Cookie->request->expects($this->once())
  61. ->method('cookie')
  62. ->will($this->returnValue('val'));
  63. $output = $this->Cookie->read('Foo.key');
  64. $this->assertTextEquals('val', $output);
  65. }
  66. }