Skip to content

Commit

Permalink
Test out the query tagging for IP range statements.
Browse files Browse the repository at this point in the history
Bit of formatting, and using constants.
  • Loading branch information
adam-vessey committed Mar 9, 2024
1 parent 19bb47c commit 19abd03
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions tests/src/Kernel/IpRangeEmbargoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -13,6 +14,8 @@
*/
class IpRangeEmbargoTest extends EmbargoKernelTestBase {

use DatabaseQueryTestTraits;

/**
* Embargo for test.
*
Expand Down Expand Up @@ -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'),
);
}

/**
Expand All @@ -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');
}

}

0 comments on commit 19abd03

Please sign in to comment.