Skip to content

Commit

Permalink
Updated to 1.1.6 version
Browse files Browse the repository at this point in the history
  • Loading branch information
josantonius committed Jan 6, 2018
1 parent f9d2c20 commit 8cf9e16
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 8 deletions.
22 changes: 20 additions & 2 deletions README-ES.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,22 @@ Cookie::destroy($key);

**# Return** (boolean)

### - Establecer prefijo para cookies:

```php
Cookie::setPrefix($prefix);
```

| Atributo | Descripción | Tipo | Requerido | Predeterminado
| --- | --- | --- | --- | --- |
| $prefix | Prefijo para las cookies. | string || |

**# Return** (boolean)

### - Obtener prefijo de cookies:

```php
Cookie::getCookiePrefix();
Cookie::getPrefix();
```

**# Return** (string) → prefijo de cookies
Expand Down Expand Up @@ -168,10 +180,16 @@ Cookie::destroy('cookie_name');
Cookie::destroy();
```

### - Establecer prefijo para cookies:

```php
Cookie::setPrefix('prefix_');
```

### - Obtener prefijo de cookies:

```php
Cookie::getCookiePrefix();
Cookie::getPrefix();
```

## Tests
Expand Down
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,22 @@ Cookie::destroy($key);

**# Return** (boolean)

### - Set cookie prefix:

```php
Cookie::setPrefix($prefix);
```

| Attribute | Description | Type | Required | Default
| --- | --- | --- | --- | --- |
| $prefix | Cookie prefix. | string | Yes | |

**# Return** (boolean)

### - Get cookie prefix:

```php
Cookie::getCookiePrefix();
Cookie::getPrefix();
```

**# Return** (string) → cookie prefix
Expand Down Expand Up @@ -168,10 +180,16 @@ Cookie::destroy('cookie_name');
Cookie::destroy();
```

### - Set cookie prefix:

```php
Cookie::setPrefix('prefix_');
```

### - Get cookie prefix:

```php
Cookie::getCookiePrefix();
Cookie::getPrefix();
```

## Tests
Expand Down
25 changes: 22 additions & 3 deletions src/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Cookie
* @param string $value → the data to save
* @param string $time → expiration time in days
*
* @return bool
* @return boolean
*/
public static function set($key, $value, $time = 365)
{
Expand Down Expand Up @@ -79,7 +79,7 @@ public static function pull($key)
*
* @param string $key → cookie name to destroy. Not set to delete all
*
* @return bool
* @return boolean
*/
public static function destroy($key = '')
{
Expand All @@ -100,14 +100,33 @@ public static function destroy($key = '')
return false;
}

/**
* Set cookie prefix.
*
* @since 1.1.6
*
* @param string $prefix → cookie prefix
*
* @return boolean
*/
public static function setPrefix($prefix)
{
if (!empty($prefix) && is_string($prefix)) {
self::$prefix = $prefix;
return true;
}

return false;
}

/**
* Get cookie prefix.
*
* @since 1.1.5
*
* @return string
*/
public static function getCookiePrefix()
public static function getPrefix()
{
return self::$prefix;
}
Expand Down
46 changes: 45 additions & 1 deletion tests/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function setUp()

$cookie = $this->Cookie;

$this->cookiePrefix = $cookie::getCookiePrefix();
$this->cookiePrefix = $cookie::getPrefix();
}

/**
Expand Down Expand Up @@ -197,4 +197,48 @@ public function testDestroyAllCookiesNonExistents()

$this->assertFalse($cookie::destroy());
}

/**
* Get cookie prefix.
*
* @runInSeparateProcess
*
* @since 1.1.6
*/
public function testGetCookiePrefix()
{
$cookie = $this->Cookie;

$this->assertContains($cookie::getPrefix(), 'jst_');
}

/**
* Set cookie prefix.
*
* @runInSeparateProcess
*
* @since 1.1.6
*/
public function testSetCookiePrefix()
{
$cookie = $this->Cookie;

$this->assertTrue($cookie::setPrefix('prefix_'));
}

/**
* Set cookie prefix incorrectly.
*
* @runInSeparateProcess
*
* @since 1.1.6
*/
public function testSetCookieIncorrectly()
{
$cookie = $this->Cookie;

$this->assertFalse($cookie::setPrefix(''));
$this->assertFalse($cookie::setPrefix(5));
$this->assertFalse($cookie::setPrefix(true));
}
}

0 comments on commit 8cf9e16

Please sign in to comment.