Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
bencroker
committed
Sep 18, 2020
1 parent
5cef138
commit d708dcc
Showing
2 changed files
with
115 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
return [ | ||
'components' => [ | ||
'redis' => [ | ||
'class' => yii\redis\Connection::class, | ||
'hostname' => 'localhost', | ||
'port' => 6379, | ||
'password' => '', | ||
], | ||
'cache' => [ | ||
'class' => yii\redis\Cache::class, | ||
'defaultDuration' => 86400, | ||
'keyPrefix' => 'CraftCMS', | ||
], | ||
], | ||
]; |
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,99 @@ | ||
<?php | ||
/** | ||
* @copyright Copyright (c) PutYourLightsOn | ||
*/ | ||
|
||
namespace putyourlightson\blitztests\unit; | ||
|
||
use Codeception\Test\Unit; | ||
use craft\helpers\FileHelper; | ||
use putyourlightson\blitz\Blitz; | ||
use putyourlightson\blitz\drivers\storage\YiiCacheStorage; | ||
use putyourlightson\blitz\models\SiteUriModel; | ||
use UnitTester; | ||
|
||
/** | ||
* @author PutYourLightsOn | ||
* @package Blitz | ||
* @since 3.6.9 | ||
*/ | ||
|
||
class YiiCacheStorageTest extends Unit | ||
{ | ||
// Properties | ||
// ========================================================================= | ||
|
||
/** | ||
* @var UnitTester | ||
*/ | ||
protected $tester; | ||
|
||
/** | ||
* @var YiiCacheStorage | ||
*/ | ||
private $cacheStorage; | ||
|
||
/** | ||
* @var SiteUriModel | ||
*/ | ||
private $siteUri; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $output = 'xyz'; | ||
|
||
// Protected methods | ||
// ========================================================================= | ||
|
||
protected function _before() | ||
{ | ||
parent::_before(); | ||
|
||
Blitz::$plugin->set('cacheStorage', YiiCacheStorage::class); | ||
|
||
Blitz::$plugin->generateCache->options->cachingEnabled = true; | ||
Blitz::$plugin->cacheStorage->deleteAll(); | ||
Blitz::$plugin->flushCache->flushAll(); | ||
|
||
$this->cacheStorage = Blitz::$plugin->cacheStorage; | ||
|
||
$this->siteUri = new SiteUriModel([ | ||
'siteId' => 1, | ||
'uri' => 'möbelträgerfüße', | ||
]); | ||
|
||
Blitz::$plugin->cacheStorage->save($this->output, $this->siteUri); | ||
} | ||
|
||
// Public methods | ||
// ========================================================================= | ||
|
||
public function testSave() | ||
{ | ||
$value = $this->cacheStorage->get($this->siteUri); | ||
$this->assertStringContainsString($this->output, $value); | ||
} | ||
|
||
public function testSaveDecoded() | ||
{ | ||
$this->siteUri->uri = rawurldecode($this->siteUri->uri); | ||
$value = $this->cacheStorage->get($this->siteUri); | ||
$this->assertStringContainsString($this->output, $value); | ||
} | ||
|
||
public function testDelete() | ||
{ | ||
$this->cacheStorage->deleteUris([$this->siteUri]); | ||
$value = $this->cacheStorage->get($this->siteUri); | ||
$this->assertEmpty($value); | ||
} | ||
|
||
public function testDeleteDecoded() | ||
{ | ||
$this->siteUri->uri = rawurldecode($this->siteUri->uri); | ||
$this->cacheStorage->deleteUris([$this->siteUri]); | ||
$value = $this->cacheStorage->get($this->siteUri); | ||
$this->assertEmpty($value); | ||
} | ||
} |