Skip to content

Commit

Permalink
Added YiiCacheStorageTest
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Sep 18, 2020
1 parent 5cef138 commit d708dcc
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/_craft/config/app.php
@@ -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',
],
],
];
99 changes: 99 additions & 0 deletions tests/unit/drivers/YiiCacheStorageTest.php
@@ -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);
}
}

0 comments on commit d708dcc

Please sign in to comment.