From 19abd0367826497b48df6274bda638527ce0c5dc Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Sat, 9 Mar 2024 16:14:42 -0400 Subject: [PATCH] Test out the query tagging for IP range statements. Bit of formatting, and using constants. --- tests/src/Kernel/IpRangeEmbargoTest.php | 29 +++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/tests/src/Kernel/IpRangeEmbargoTest.php b/tests/src/Kernel/IpRangeEmbargoTest.php index 60ef26a..a858416 100644 --- a/tests/src/Kernel/IpRangeEmbargoTest.php +++ b/tests/src/Kernel/IpRangeEmbargoTest.php @@ -5,6 +5,7 @@ use Drupal\embargo\EmbargoInterface; use Drupal\embargo\IpRangeInterface; use Drupal\node\NodeInterface; +use Drupal\Tests\islandora_test_support\Traits\DatabaseQueryTestTraits; /** * Test IpRange embargo. @@ -13,6 +14,8 @@ */ class IpRangeEmbargoTest extends EmbargoKernelTestBase { + use DatabaseQueryTestTraits; + /** * Embargo for test. * @@ -105,8 +108,16 @@ public function setUp(): void { $this->embargoedNodeWithDifferentIpRange = $this->createNode(); $this->currentIpRangeEntity = $this->createIpRangeEntity($this->ipRange); $this->embargoWithoutIpRange = $this->createEmbargo($this->embargoedNodeWithoutIpRange); - $this->embargoWithCurrentIpRange = $this->createEmbargo($this->embargoedNodeWithCurrentIpRange, 1, $this->currentIpRangeEntity); - $this->embargoWithDifferentIpRange = $this->createEmbargo($this->embargoedNodeWithDifferentIpRange, 1, $this->createIpRangeEntity('0.0.0.0.1/29')); + $this->embargoWithCurrentIpRange = $this->createEmbargo( + $this->embargoedNodeWithCurrentIpRange, + EmbargoInterface::EMBARGO_TYPE_NODE, + $this->currentIpRangeEntity, + ); + $this->embargoWithDifferentIpRange = $this->createEmbargo( + $this->embargoedNodeWithDifferentIpRange, + EmbargoInterface::EMBARGO_TYPE_NODE, + $this->createIpRangeEntity('0.0.0.1/29'), + ); } /** @@ -127,4 +138,18 @@ public function testIpRangeEmbargoNodeAccess() { $this->assertTrue($this->embargoedNodeWithCurrentIpRange->access('view', $this->user)); } + /** + * Test IP range query tagging. + */ + public function testIpRangeQueryTagging() { + $results = $this->generateNodeSelectAccessQuery($this->user)->execute()->fetchAll(); + + $ids = array_column($results, 'nid'); + + $this->assertContains($this->nonEmbargoedNode->id(), $ids, 'non-embargoed node present'); + $this->assertNotContains($this->embargoedNodeWithoutIpRange->id(), $ids, 'generally embargoed node absent'); + $this->assertNotContains($this->embargoedNodeWithDifferentIpRange->id(), $ids, 'node exempted to other ranges absent'); + $this->assertContains($this->embargoedNodeWithCurrentIpRange->id(), $ids, 'node exempted to our range present'); + } + }