Chris@0
|
1 <?php
|
Chris@0
|
2
|
Chris@0
|
3 namespace Drupal\Tests\rdf\Functional;
|
Chris@0
|
4
|
Chris@0
|
5 use Drupal\Tests\BrowserTestBase;
|
Chris@0
|
6
|
Chris@0
|
7 /**
|
Chris@0
|
8 * Tests hook_rdf_namespaces().
|
Chris@0
|
9 *
|
Chris@0
|
10 * @group rdf
|
Chris@0
|
11 */
|
Chris@0
|
12 class GetRdfNamespacesTest extends BrowserTestBase {
|
Chris@0
|
13
|
Chris@0
|
14 /**
|
Chris@0
|
15 * Modules to enable.
|
Chris@0
|
16 *
|
Chris@0
|
17 * @var array
|
Chris@0
|
18 */
|
Chris@0
|
19 public static $modules = ['rdf', 'rdf_test_namespaces'];
|
Chris@0
|
20
|
Chris@0
|
21 /**
|
Chris@0
|
22 * Tests getting RDF namespaces.
|
Chris@0
|
23 */
|
Chris@0
|
24 public function testGetRdfNamespaces() {
|
Chris@16
|
25 // Fetches the front page and extracts RDFa 1.1 prefixes.
|
Chris@16
|
26 $this->drupalGet('');
|
Chris@16
|
27
|
Chris@16
|
28 // We have to use the find() method on the driver directly because //html is
|
Chris@16
|
29 // prepended to all xpath queries otherwise.
|
Chris@16
|
30 $driver = $this->getSession()->getDriver();
|
Chris@16
|
31
|
Chris@16
|
32 $element = $driver->find('//html[contains(@prefix, "rdfs: http://www.w3.org/2000/01/rdf-schema#")]');
|
Chris@16
|
33 $this->assertCount(1, $element, 'A prefix declared once is displayed.');
|
Chris@16
|
34
|
Chris@16
|
35 $element = $driver->find('//html[contains(@prefix, "foaf: http://xmlns.com/foaf/0.1/")]');
|
Chris@16
|
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.');
|
Chris@16
|
37
|
Chris@16
|
38 $element = $driver->find('//html[contains(@prefix, "foaf1: http://xmlns.com/foaf/0.1/")]');
|
Chris@16
|
39 $this->assertCount(1, $element, 'Two prefixes can be assigned the same namespace.');
|
Chris@16
|
40
|
Chris@16
|
41 $element = $driver->find('//html[contains(@prefix, "dc: http://purl.org/dc/terms/")]');
|
Chris@16
|
42 $this->assertCount(1, $element, 'When a prefix has conflicting namespaces, the first declared one is used.');
|
Chris@16
|
43
|
Chris@0
|
44 // Get all RDF namespaces.
|
Chris@0
|
45 $ns = rdf_get_namespaces();
|
Chris@0
|
46
|
Chris@0
|
47 $this->assertEqual($ns['rdfs'], 'http://www.w3.org/2000/01/rdf-schema#', 'A prefix declared once is included.');
|
Chris@0
|
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.');
|
Chris@0
|
49 $this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', 'Two prefixes can be assigned the same namespace.');
|
Chris@0
|
50
|
Chris@0
|
51 // Enable rdf_conflicting_namespaces to ensure that an exception is thrown
|
Chris@0
|
52 // when RDF namespaces are conflicting.
|
Chris@0
|
53 \Drupal::service('module_installer')->install(['rdf_conflicting_namespaces'], TRUE);
|
Chris@0
|
54 try {
|
Chris@0
|
55 $ns = rdf_get_namespaces();
|
Chris@0
|
56 $this->fail('Expected exception not thrown for conflicting namespace declaration.');
|
Chris@0
|
57 }
|
Chris@0
|
58 catch (\Exception $e) {
|
Chris@0
|
59 $this->pass('Expected exception thrown: ' . $e->getMessage());
|
Chris@0
|
60 }
|
Chris@0
|
61 }
|
Chris@0
|
62
|
Chris@0
|
63 }
|