You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
91 lines
2.9 KiB
91 lines
2.9 KiB
5 years ago
|
<?php
|
||
|
|
||
|
namespace Drupal\Tests\islandora\Functional;
|
||
|
|
||
|
/**
|
||
|
* Tests the NodeHasTerm condition.
|
||
|
*
|
||
|
* @package Drupal\Tests\islandora\Functional
|
||
|
* @group islandora
|
||
|
*/
|
||
|
class NodeHasTermTest extends IslandoraFunctionalTestBase {
|
||
|
|
||
|
/**
|
||
|
* {@inheritdoc}
|
||
|
*/
|
||
|
public function setUp() {
|
||
|
|
||
|
parent::setUp();
|
||
|
|
||
|
// Set up two tags so we can test the condition.
|
||
|
// Doesn't really matter what they are or what
|
||
|
// vocab they belong to.
|
||
|
$this->createImageTag();
|
||
|
$this->createPreservationMasterTag();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @covers \Drupal\islandora\Plugin\Condition\NodeHasTerm
|
||
|
*/
|
||
|
public function testNodeHasTerm() {
|
||
|
|
||
|
// Create a new node with the tag.
|
||
|
$node = $this->container->get('entity_type.manager')->getStorage('node')->create([
|
||
|
'type' => 'test_type',
|
||
|
'title' => 'Test Node',
|
||
|
'field_tags' => [$this->imageTerm->id()],
|
||
|
]);
|
||
|
|
||
|
// Create and execute the condition.
|
||
|
$condition_manager = $this->container->get('plugin.manager.condition');
|
||
|
$condition = $condition_manager->createInstance(
|
||
|
'node_has_term',
|
||
|
[
|
||
|
'uri' => 'http://purl.org/coar/resource_type/c_c513',
|
||
|
]
|
||
|
);
|
||
|
$condition->setContextValue('node', $node);
|
||
|
$this->assertTrue($condition->execute(), "Condition should pass if node has the term");
|
||
|
|
||
|
// Create a new node without the tag.
|
||
|
$node = $this->container->get('entity_type.manager')->getStorage('node')->create([
|
||
|
'type' => 'test_type',
|
||
|
'title' => 'Test Node',
|
||
|
]);
|
||
|
|
||
|
$condition->setContextValue('node', $node);
|
||
|
$this->assertFalse($condition->execute(), "Condition should fail if the node does not have any terms");
|
||
|
|
||
|
// Create a new node with the wrong tag.
|
||
|
$node = $this->container->get('entity_type.manager')->getStorage('node')->create([
|
||
|
'type' => 'test_type',
|
||
|
'title' => 'Test Node',
|
||
|
'field_tags' => [$this->preservationMasterTerm->id()],
|
||
|
]);
|
||
|
|
||
|
$condition->setContextValue('node', $node);
|
||
|
$this->assertFalse($condition->execute(), "Condition should fail if the node has terms, but not the one we want.");
|
||
|
|
||
|
// Check for two tags this time.
|
||
|
// Node still only has one.
|
||
|
$condition = $condition_manager->createInstance(
|
||
|
'node_has_term',
|
||
|
[
|
||
|
'uri' => 'http://purl.org/coar/resource_type/c_c513,http://pcdm.org/use#PreservationMasterFile',
|
||
|
]
|
||
|
);
|
||
|
$condition->setContextValue('node', $node);
|
||
|
$this->assertFalse($condition->execute(), "Condition should fail if node does not have both terms");
|
||
|
|
||
|
// Create a node with both tags.
|
||
|
$node = $this->container->get('entity_type.manager')->getStorage('node')->create([
|
||
|
'type' => 'test_type',
|
||
|
'title' => 'Test Node',
|
||
|
'field_tags' => [$this->imageTerm->id(), $this->preservationMasterTerm->id()],
|
||
|
]);
|
||
|
$condition->setContextValue('node', $node);
|
||
|
$this->assertTrue($condition->execute(), "Condition should pass if node has both terms");
|
||
|
}
|
||
|
|
||
|
}
|