3 namespace Drupal\Tests\rdf\Functional;
5 use Drupal\Tests\BrowserTestBase;
8 * Tests hook_rdf_namespaces().
12 class GetRdfNamespacesTest extends BrowserTestBase {
19 public static $modules = ['rdf', 'rdf_test_namespaces'];
22 * Tests getting RDF namespaces.
24 public function testGetRdfNamespaces() {
25 // Fetches the front page and extracts RDFa 1.1 prefixes.
28 // We have to use the find() method on the driver directly because //html is
29 // prepended to all xpath queries otherwise.
30 $driver = $this->getSession()->getDriver();
32 $element = $driver->find('//html[contains(@prefix, "rdfs: http://www.w3.org/2000/01/rdf-schema#")]');
33 $this->assertCount(1, $element, 'A prefix declared once is displayed.');
35 $element = $driver->find('//html[contains(@prefix, "foaf: http://xmlns.com/foaf/0.1/")]');
36 $this->assertCount(1, $element, 'The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.');
38 $element = $driver->find('//html[contains(@prefix, "foaf1: http://xmlns.com/foaf/0.1/")]');
39 $this->assertCount(1, $element, 'Two prefixes can be assigned the same namespace.');
41 $element = $driver->find('//html[contains(@prefix, "dc: http://purl.org/dc/terms/")]');
42 $this->assertCount(1, $element, 'When a prefix has conflicting namespaces, the first declared one is used.');
44 // Get all RDF namespaces.
45 $ns = rdf_get_namespaces();
47 $this->assertEqual($ns['rdfs'], 'http://www.w3.org/2000/01/rdf-schema#', 'A prefix declared once is included.');
48 $this->assertEqual($ns['foaf'], 'http://xmlns.com/foaf/0.1/', 'The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.');
49 $this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', 'Two prefixes can be assigned the same namespace.');
51 // Enable rdf_conflicting_namespaces to ensure that an exception is thrown
52 // when RDF namespaces are conflicting.
53 \Drupal::service('module_installer')->install(['rdf_conflicting_namespaces'], TRUE);
55 $ns = rdf_get_namespaces();
56 $this->fail('Expected exception not thrown for conflicting namespace declaration.');
58 catch (\Exception $e) {
59 $this->pass('Expected exception thrown: ' . $e->getMessage());