Skip to content

Commit

Permalink
Update config to ignorelist. Add test coverage. Closes #19
Browse files Browse the repository at this point in the history
  • Loading branch information
chrispenny authored and adrhumphreys committed Oct 19, 2021
1 parent ae18ecd commit 3cad253
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions _config/blacklist.yml → _config/ignorelist.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/Extensions/CacheKeyExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
21 changes: 21 additions & 0 deletions tests/Extensions/CacheKeyExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
])
);
}

}

0 comments on commit 3cad253

Please sign in to comment.