RequestCookiesTest.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  5. * Licensed under The MIT License
  6. * Redistributions of files must retain the above copyright notice.
  7. *
  8. * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
  9. * @link http://cakephp.org CakePHP(tm) Project
  10. * @since 3.5.0
  11. * @license http://www.opensource.org/licenses/mit-license.php MIT License
  12. */
  13. namespace Cake\Test\TestCase\Http\Cookie;
  14. use Cake\Http\Cookie\Cookie;
  15. use Cake\Http\Cookie\RequestCookies;
  16. use Cake\Http\ServerRequest;
  17. use Cake\TestSuite\TestCase;
  18. /**
  19. * HTTP cookies test.
  20. */
  21. class RequestCookiesTest extends TestCase
  22. {
  23. /**
  24. * Server Request
  25. *
  26. * @var \Cake\Http\ServerRequest
  27. */
  28. public $request;
  29. /**
  30. * @inheritDoc
  31. */
  32. public function setUp()
  33. {
  34. $this->request = new ServerRequest([
  35. 'cookies' => [
  36. 'remember_me' => 'test',
  37. 'something' => 'test2'
  38. ]
  39. ]);
  40. }
  41. /**
  42. * Test testCreateFromRequest
  43. *
  44. * @return null
  45. */
  46. public function testCreateFromRequest()
  47. {
  48. $result = RequestCookies::createFromRequest($this->request);
  49. $this->assertInstanceOf(RequestCookies::class, $result);
  50. $this->assertInstanceOf(Cookie::class, $result->get('remember_me'));
  51. $this->assertInstanceOf(Cookie::class, $result->get('something'));
  52. $this->assertTrue($result->has('remember_me'));
  53. $this->assertTrue($result->has('something'));
  54. $this->assertFalse($result->has('does-not-exist'));
  55. }
  56. }