function RdfaMarkupTest::testDrupalRdfaAttributes

Tests rdf_rdfa_attributes().

File

drupal/core/modules/rdf/lib/Drupal/rdf/Tests/RdfaMarkupTest.php, line 37
Definition of Drupal\rdf\Tests\RdfaMarkupTest.

Class

RdfaMarkupTest
Tests RDFa markup generation.

Namespace

Drupal\rdf\Tests

Code

function testDrupalRdfaAttributes() {

  // Same value as the one in the HTML tag (no callback function).
  $expected_attributes = array(
    'property' => array(
      'dc:title',
    ),
  );
  $mapping = rdf_mapping_load('test_entity', 'test_bundle');
  $attributes = rdf_rdfa_attributes($mapping['title']);
  ksort($expected_attributes);
  ksort($attributes);
  $this
    ->assertEqual($expected_attributes, $attributes);

  // Value different from the one in the HTML tag (callback function).
  $date = 1252750327;
  $isoDate = date('c', $date);
  $expected_attributes = array(
    'datatype' => 'xsd:dateTime',
    'property' => array(
      'dc:created',
    ),
    'content' => $isoDate,
  );
  $mapping = rdf_mapping_load('test_entity', 'test_bundle');
  $attributes = rdf_rdfa_attributes($mapping['created'], $date);
  ksort($expected_attributes);
  ksort($attributes);
  $this
    ->assertEqual($expected_attributes, $attributes);

  // Same value as the one in the HTML tag with datatype.
  $expected_attributes = array(
    'datatype' => 'foo:bar1type',
    'property' => array(
      'foo:bar1',
    ),
  );
  $mapping = rdf_mapping_load('test_entity', 'test_bundle');
  $attributes = rdf_rdfa_attributes($mapping['foobar1']);
  ksort($expected_attributes);
  ksort($attributes);
  $this
    ->assertEqual($expected_attributes, $attributes);

  // ObjectProperty mapping (rel).
  $expected_attributes = array(
    'rel' => array(
      'sioc:has_creator',
      'dc:creator',
    ),
  );
  $mapping = rdf_mapping_load('test_entity', 'test_bundle');
  $attributes = rdf_rdfa_attributes($mapping['foobar_objproperty1']);
  ksort($expected_attributes);
  ksort($attributes);
  $this
    ->assertEqual($expected_attributes, $attributes);

  // Inverse ObjectProperty mapping (rev).
  $expected_attributes = array(
    'rev' => array(
      'sioc:reply_of',
    ),
  );
  $mapping = rdf_mapping_load('test_entity', 'test_bundle');
  $attributes = rdf_rdfa_attributes($mapping['foobar_objproperty2']);
  ksort($expected_attributes);
  ksort($attributes);
  $this
    ->assertEqual($expected_attributes, $attributes);
}