From 3cad25360f913d2809b5d5900cbd23134084d8b1 Mon Sep 17 00:00:00 2001 From: Chris Penny Date: Wed, 20 Oct 2021 08:33:12 +1300 Subject: [PATCH] Update config to ignorelist. Add test coverage. Closes #19 --- _config/{blacklist.yml => ignorelist.yml} | 4 ++-- src/Extensions/CacheKeyExtension.php | 4 ++-- tests/Extensions/CacheKeyExtensionTest.php | 21 +++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) rename _config/{blacklist.yml => ignorelist.yml} (91%) diff --git a/_config/blacklist.yml b/_config/ignorelist.yml similarity index 91% rename from _config/blacklist.yml rename to _config/ignorelist.yml index e37a064..2ef14eb 100644 --- a/_config/blacklist.yml +++ b/_config/ignorelist.yml @@ -1,8 +1,8 @@ --- -Name: kfc-blacklist +Name: kfc-ignorelist --- Terraformers\KeysForCache\Models\CacheKey: - blacklist: + ignorelist: CacheKey: Terraformers\KeysForCache\Models\CacheKey ChangeSet: SilverStripe\Versioned\ChangeSet ChangeSetItem: SilverStripe\Versioned\ChangeSetItem diff --git a/src/Extensions/CacheKeyExtension.php b/src/Extensions/CacheKeyExtension.php index dafef9a..fa3fa44 100644 --- a/src/Extensions/CacheKeyExtension.php +++ b/src/Extensions/CacheKeyExtension.php @@ -91,9 +91,9 @@ public function onAfterUnpublish(): void protected function triggerEvent(bool $publishUpdates = false): void { - $blacklist = Config::forClass(CacheKey::class)->get('blacklist'); + $ignoreList = Config::forClass(CacheKey::class)->get('ignorelist'); - if (in_array($this->owner->ClassName, $blacklist)) { + if (in_array($this->owner->ClassName, $ignoreList)) { return; } diff --git a/tests/Extensions/CacheKeyExtensionTest.php b/tests/Extensions/CacheKeyExtensionTest.php index 3511c45..cc5e6e5 100644 --- a/tests/Extensions/CacheKeyExtensionTest.php +++ b/tests/Extensions/CacheKeyExtensionTest.php @@ -262,4 +262,25 @@ public function testUpdateCMSFieldsNoKeyConfig(): void $this->assertNull($fields->dataFieldByName('CacheKeys')); } + public function testIgnoreList(): void + { + // Add our CachePage to the ignorelist + $ignoreList = CacheKey::config()->get('ignorelist'); + $ignoreList['CachePage'] = CachePage::class; + CacheKey::config()->set('ignorelist', $ignoreList); + + // Create the Page + $page = CachePage::create(); + $page->write(); + + // No CacheKey should have been generated + $this->assertCount( + 0, + CacheKey::get()->filter([ + 'RecordClass' => $page->ClassName, + 'RecordID' => $page->ID, + ]) + ); + } + }