class GetRdfNamespacesTest
Same name and namespace in other branches
- 8.9.x core/modules/rdf/tests/src/Functional/GetRdfNamespacesTest.php \Drupal\Tests\rdf\Functional\GetRdfNamespacesTest
Tests hook_rdf_namespaces().
@group rdf @group legacy
Hierarchy
- class \Drupal\Tests\BrowserTestBase uses \Drupal\Core\Test\FunctionalTestSetupTrait, \Drupal\Tests\UiHelperTrait, \Drupal\Core\Test\TestSetupTrait, \Drupal\Tests\block\Traits\BlockCreationTrait, \Drupal\FunctionalTests\AssertLegacyTrait, \Drupal\Tests\RandomGeneratorTrait, \Drupal\Tests\node\Traits\NodeCreationTrait, \Drupal\Tests\node\Traits\ContentTypeCreationTrait, \Drupal\Tests\ConfigTestTrait, \Drupal\Tests\TestRequirementsTrait, \Drupal\Tests\user\Traits\UserCreationTrait, \Drupal\Tests\XdebugRequestTrait, \Drupal\Tests\Traits\PhpUnitWarnings, \Drupal\Tests\PhpUnitCompatibilityTrait, \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, \Drupal\Tests\ExtensionListTestTrait extends \PHPUnit\Framework\TestCase
- class \Drupal\Tests\rdf\Functional\GetRdfNamespacesTest extends \Drupal\Tests\BrowserTestBase
Expanded class hierarchy of GetRdfNamespacesTest
File
-
core/
modules/ rdf/ tests/ src/ Functional/ GetRdfNamespacesTest.php, line 13
Namespace
Drupal\Tests\rdf\FunctionalView source
class GetRdfNamespacesTest extends BrowserTestBase {
/**
* Modules to enable.
*
* @var array
*/
protected static $modules = [
'rdf',
'rdf_test_namespaces',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Tests getting RDF namespaces.
*/
public function testGetRdfNamespaces() {
// Fetches the front page and extracts RDFa 1.1 prefixes.
$this->drupalGet('');
// We have to use the find() method on the driver directly because //html is
// prepended to all xpath queries otherwise.
$driver = $this->getSession()
->getDriver();
$element = $driver->find('//html[contains(@prefix, "rdfs: http://www.w3.org/2000/01/rdf-schema#")]');
$this->assertCount(1, $element, 'A prefix declared once is displayed.');
$element = $driver->find('//html[contains(@prefix, "foaf: http://xmlns.com/foaf/0.1/")]');
$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.');
$element = $driver->find('//html[contains(@prefix, "foaf1: http://xmlns.com/foaf/0.1/")]');
$this->assertCount(1, $element, 'Two prefixes can be assigned the same namespace.');
$element = $driver->find('//html[contains(@prefix, "dc: http://purl.org/dc/terms/")]');
$this->assertCount(1, $element, 'When a prefix has conflicting namespaces, the first declared one is used.');
// Get all RDF namespaces.
$ns = rdf_get_namespaces();
$this->assertEquals('http://www.w3.org/2000/01/rdf-schema#', $ns['rdfs'], 'A prefix declared once is included.');
$this->assertEquals('http://xmlns.com/foaf/0.1/', $ns['foaf'], 'The same prefix declared in several implementations of hook_rdf_namespaces() is valid as long as all the namespaces are the same.');
$this->assertEquals('http://xmlns.com/foaf/0.1/', $ns['foaf1'], 'Two prefixes can be assigned the same namespace.');
// Enable rdf_conflicting_namespaces to ensure that an exception is thrown
// when RDF namespaces are conflicting.
\Drupal::service('module_installer')->install([
'rdf_conflicting_namespaces',
], TRUE);
try {
$ns = rdf_get_namespaces();
$this->fail('Expected exception not thrown for conflicting namespace declaration.');
} catch (\Exception $e) {
// Expected exception; just continue testing.
}
}
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.