Пример #1
0
 /**
  * @covers CHttpCookie::configure
  * @covers CHttpCookie::__construct
  */
 public function testConfigure()
 {
     //covers construct
     $cookie = new CHttpCookie('name', 'value');
     $this->assertEquals('name', $cookie->name, 'Constructor failure. Name should have been set there');
     $this->assertEquals('value', $cookie->value, 'Constructor failure. Value should have been set there');
     $this->assertEquals('', $cookie->domain, 'Default value for CHttpCookie::$domain has been touched');
     $this->assertEquals(0, $cookie->expire, 'Default value for CHttpCookie::$expire has been touched');
     $this->assertEquals('/', $cookie->path, 'Default value for CHttpCookie::$path has been touched');
     $this->assertFalse($cookie->secure, 'Default value for CHttpCookie::$secure has been touched');
     $this->assertFalse($cookie->httpOnly, 'Default value for CHttpCookie::$httpOnly has been touched');
     $options = array('expire' => 123123, 'httpOnly' => true);
     // create cookie with options
     $cookie2 = new CHttpCookie('name2', 'value2', $options);
     $this->assertEquals($options['expire'], $cookie2->expire, 'Configure inside the Constructor has been failed');
     $this->assertEquals($options['httpOnly'], $cookie2->httpOnly, 'Configure inside the Constructor has been failed');
     //configure afterwards
     $cookie->configure($options);
     $this->assertEquals($options['expire'], $cookie->expire);
     $this->assertEquals($options['httpOnly'], $cookie->httpOnly);
     // Set name and value via configure (should have no effect)
     $name = $cookie->name;
     $cookie->configure(array('name' => 'someNewName'));
     $this->assertEquals($name, $cookie->name);
     $value = $cookie->value;
     $cookie->configure(array('value' => 'someNewValue'));
     $this->assertEquals($value, $cookie->value);
     //new configure should not override already set configuration
     $this->assertEquals($options['httpOnly'], $cookie->httpOnly);
 }
Пример #2
0
 /**
  * Creates a new HttpCookie instance.
  *
  * @param string $name    The name of this cookie.
  * @param string $value   The cookie's value.
  * @param array  $options The configuration array consisting of name-value pairs that are used to configure this cookie.
  *
  * @return HttpCookie
  */
 public function __construct($name, $value, $options = array())
 {
     // Set the default cookie domain. A user can always override it, if they want.
     if (($defaultCookieDomain = craft()->config->get('defaultCookieDomain')) !== '') {
         $this->domain = $defaultCookieDomain;
     }
     parent::__construct($name, $value, $options);
 }
Пример #3
0
 /**
  * Creates a new HttpCookie instance.
  *
  * @param string $name    The name of this cookie.
  * @param string $value   The cookie's value.
  * @param array  $options The configuration array consisting of name-value pairs that are used to configure this cookie.
  *
  * @return HttpCookie
  */
 public function __construct($name, $value, $options = array())
 {
     // Set the default cookie domain. A user can always override it, if they want.
     if (($defaultCookieDomain = craft()->config->get('defaultCookieDomain')) !== '') {
         $this->domain = $defaultCookieDomain;
     }
     $this->httpOnly = true;
     $secureCookies = craft()->config->get('useSecureCookies');
     // If it's set to auto and a secure connection or it's set to true, set the secure flag.
     if ($secureCookies === 'auto' && craft()->request->isSecureConnection() || $secureCookies === true) {
         $this->secure = true;
     }
     parent::__construct($name, $value, $options);
 }