-
-
Notifications
You must be signed in to change notification settings - Fork 836
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PHP 8 support, cookie unit tests (#2507)
- Loading branch information
Showing
7 changed files
with
89 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Flarum. | ||
* | ||
* For detailed copyright and license information, please view the | ||
* LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Flarum\Tests\unit\Http; | ||
|
||
use Carbon\Carbon; | ||
use Flarum\Foundation\Config; | ||
use Flarum\Http\CookieFactory; | ||
use Flarum\Tests\unit\TestCase; | ||
|
||
class CookieFactoryTest extends TestCase | ||
{ | ||
protected function factory(array $config = null): CookieFactory | ||
{ | ||
$config = new Config(array_merge([ | ||
'url' => 'http://flarum.test' | ||
], $config ?? [])); | ||
|
||
return new CookieFactory($config); | ||
} | ||
|
||
/** @test */ | ||
public function can_create_cookies() | ||
{ | ||
$cookie = $this->factory()->make('test', 'australia'); | ||
|
||
$this->assertEquals('flarum_test', $cookie->getName()); | ||
$this->assertEquals('australia', $cookie->getValue()); | ||
$this->assertEquals(0, $cookie->getExpires()); | ||
$this->assertFalse($cookie->getSecure()); | ||
$this->assertEquals('/', $cookie->getPath()); | ||
} | ||
|
||
/** @test */ | ||
public function can_override_cookie_settings_from_config() | ||
{ | ||
$cookie = $this->factory([ | ||
'cookie' => [ | ||
'name' => 'australia', | ||
'secure' => true, | ||
'domain' => 'flarum.com', | ||
'samesite' => 'none' | ||
] | ||
])->make('test', 'australia'); | ||
|
||
$this->assertEquals('australia_test', $cookie->getName()); | ||
$this->assertTrue($cookie->getSecure()); | ||
$this->assertEquals('flarum.com', $cookie->getDomain()); | ||
$this->assertEquals('SameSite=None', $cookie->getSameSite()->asString()); | ||
} | ||
|
||
/** @test */ | ||
public function can_expire_cookies() | ||
{ | ||
$cookie = $this->factory()->expire('test'); | ||
|
||
$this->assertLessThan(Carbon::now()->timestamp, $cookie->getExpires()); | ||
} | ||
} |