From d708dccf59b0877a869ed0102629f672f1c3632e Mon Sep 17 00:00:00 2001 From: bencroker Date: Fri, 18 Sep 2020 13:22:07 +0200 Subject: [PATCH] Added YiiCacheStorageTest --- tests/_craft/config/app.php | 16 ++++ tests/unit/drivers/YiiCacheStorageTest.php | 99 ++++++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 tests/_craft/config/app.php create mode 100644 tests/unit/drivers/YiiCacheStorageTest.php diff --git a/tests/_craft/config/app.php b/tests/_craft/config/app.php new file mode 100644 index 00000000..611962d3 --- /dev/null +++ b/tests/_craft/config/app.php @@ -0,0 +1,16 @@ + [ + 'redis' => [ + 'class' => yii\redis\Connection::class, + 'hostname' => 'localhost', + 'port' => 6379, + 'password' => '', + ], + 'cache' => [ + 'class' => yii\redis\Cache::class, + 'defaultDuration' => 86400, + 'keyPrefix' => 'CraftCMS', + ], + ], +]; diff --git a/tests/unit/drivers/YiiCacheStorageTest.php b/tests/unit/drivers/YiiCacheStorageTest.php new file mode 100644 index 00000000..9b639d9e --- /dev/null +++ b/tests/unit/drivers/YiiCacheStorageTest.php @@ -0,0 +1,99 @@ +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); + } +}