示例#1
0
 public function testFacadeCookie()
 {
     $_COOKIE = ['name' => 'test', 'email' => '*****@*****.**'];
     // Get and add cookies
     $this->assertCount(2, CookieManager::get()->cookies);
     $addCookies = array_merge(CookieManager::get()->cookies, ['age' => new CookieContainer('age', '20'), 'ageFind' => new CookieContainer('ageFind', '20', time() + 3600), 'token' => 'un---token']);
     $this->assertCount(5, $addCookies);
     Cookie::setCookies($addCookies);
     $this->assertCount(4, CookieManager::get()->cookies);
     // Check cookie exist
     $this->assertTrue(Cookie::exist('name'));
     $this->assertTrue(Cookie::exist('email'));
     $this->assertFalse(Cookie::exist('age'));
     $this->assertTrue(Cookie::exist('ageFind'));
     $this->assertFalse(Cookie::exist('token'));
     // Check value get
     $this->assertInstanceOf(CookieContainer::class, Cookie::getCookie('name'));
     $this->assertEquals('*****@*****.**', Cookie::get('email'));
     $this->assertNull(Cookie::get('age'));
     $this->assertNull(Cookie::get('token'));
     // Check unset cookie
     $this->assertCount(4, CookieManager::get()->cookies);
     Cookie::remove('age');
     $this->assertCount(3, CookieManager::get()->cookies);
     Cookie::remove('email');
     $this->assertCount(3, CookieManager::get()->cookies);
     // Check set cookie
     $this->assertCount(3, CookieManager::get()->cookies);
     Cookie::setValue('age', '21');
     $this->assertCount(4, CookieManager::get()->cookies);
     Cookie::set('email', '*****@*****.**');
     $this->assertCount(4, CookieManager::get()->cookies);
 }
示例#2
0
 /**
  * Permet d'initialiser les cookies récupérés
  */
 public function initCookies()
 {
     foreach ($_COOKIE as $name => $value) {
         Cookie::set($name, $value, time() + 3600);
     }
 }