GetRdfNamespacesTest.php 1.58 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php

/**
 * @file
 * Definition of Drupal\rdf\Tests\GetRdfNamespacesTest.
 */

namespace Drupal\rdf\Tests;

use Drupal\simpletest\WebTestBase;

/**
 * Tests for RDF namespaces declaration with hook_rdf_namespaces().
 */
class GetRdfNamespacesTest extends WebTestBase {
16 17 18 19 20 21

  /**
   * Modules to enable.
   *
   * @var array
   */
22
  public static $modules = array('rdf', 'rdf_test_namespaces');
23

24 25 26
  public static function getInfo() {
    return array(
      'name' => 'RDF namespaces',
27
      'description' => 'Test hook_rdf_namespaces().',
28 29 30 31 32
      'group' => 'RDF',
    );
  }

  /**
33
   * Tests getting RDF namespaces.
34 35 36 37 38
   */
  function testGetRdfNamespaces() {
    // Get all RDF namespaces.
    $ns = rdf_get_namespaces();

39 40 41
    $this->assertEqual($ns['rdfs'], 'http://www.w3.org/2000/01/rdf-schema#', 'A prefix declared once is included.');
    $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.');
    $this->assertEqual($ns['foaf1'], 'http://xmlns.com/foaf/0.1/', 'Two prefixes can be assigned the same namespace.');
42 43 44 45 46 47 48 49 50 51 52

    // Enable rdf_conflicting_namespaces to ensure that an exception is thrown
    // when RDF namespaces are conflicting.
    \Drupal::moduleHandler()->install(array('rdf_conflicting_namespaces'), TRUE);
    try {
      $ns = rdf_get_namespaces();
      $this->fail('Expected exception not thrown for conflicting namespace declaration.');
    }
    catch (\Exception $e) {
      $this->pass('Expected exception thrown: ' . $e->getMessage());
    }
53 54
  }
}