Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PhpCookieReaderTest.php
Go to the documentation of this file.
1 <?php
8 
9 class PhpCookieReaderTest extends \PHPUnit\Framework\TestCase
10 {
14  protected $preTestCookies;
15 
19  protected $model;
20 
21  const NAME = 'cookie-name';
22  const VALUE = 'cookie-val';
23  const DEFAULT_VAL = 'default-val';
24 
25  public function setUp()
26  {
27  $this->preTestCookies = $_COOKIE;
28  $_COOKIE = [];
29  $_COOKIE[self::NAME] = self::VALUE;
30  $this->model = new PhpCookieReader();
31  }
32 
33  public function testGetCookieExists()
34  {
35  $this->assertSame(self::VALUE, $this->model->getCookie(self::NAME, self::DEFAULT_VAL));
36  }
37 
38  public function testGetCookieDefault()
39  {
40  $this->assertSame(self::DEFAULT_VAL, $this->model->getCookie('cookies does not exist', self::DEFAULT_VAL));
41  $this->assertSame(self::DEFAULT_VAL, $this->model->getCookie(null, self::DEFAULT_VAL));
42  }
43 
44  public function testGetCookieNoDefault()
45  {
46  $this->assertNull($this->model->getCookie('cookies does not exist'));
47  $this->assertNull($this->model->getCookie(null));
48  }
49 
50  public function tearDown()
51  {
52  $_COOKIE = $this->preTestCookies;
53  }
54 }