You are here

public function MicrodataReferenceFieldsTestCase::testAttributesInMarkup in Microdata 7

Tests the placement of attributes in field markup.

File

./microdata.test, line 560
Tests for microdata.module.

Class

MicrodataReferenceFieldsTestCase
Test Field Collection microdata placement.

Code

public function testAttributesInMarkup() {
  $field_value = $this
    ->randomName();

  // Create node and save, then edit node to upload files.
  $node = $this
    ->drupalCreateNode(array(
    'type' => $this->bundleType,
    'promote' => 1,
  ));
  foreach ($this->field_names as $field_name => $subfield_name) {
    $edit = array();
    $path = 'field-collection/' . str_replace('_', '-', $field_name) . '/add/node/' . $node->nid;
    $edit["{$subfield_name}[und][0][value]"] = $field_value;
    $this
      ->drupalPost($path, $edit, t('Save'));
  }

  // Go back to main node.
  $this
    ->drupalGet('node/' . $node->nid);

  // Get mapping info for testing.
  $full_mapping = $this
    ->getMapping();
  $entity_mapping = $full_mapping[$this->entityType][$this->bundleType];
  $fieldcollection_mapping = $full_mapping['field_collection_item'][$this->fieldcollectionFieldName];
  $fieldgroup_mapping = $full_mapping['field_collection_item'][$this->fieldgroupFieldName];

  // Get the microdata result for the page.
  $md = $this
    ->parseMicrodata();
  $item = $md->items[0];
  $fieldcollection_itemprop = $entity_mapping[$this->fieldcollectionFieldName]['#itemprop'][0];
  $subfield_itemprop = $fieldcollection_mapping[$this->fieldcollectionSubfieldName]['#itemprop'][0];
  $this
    ->assertEqual($field_value, $item->properties[$fieldcollection_itemprop][0]->properties[$subfield_itemprop][0], t('Field collection is handled as an item with properties.'));
  $fieldgroup_subfield_itemprop = $fieldgroup_mapping[$this->fieldgroupSubfieldName]['#itemprop'][0];
  $this
    ->assertEqual($field_value, $item->properties[$fieldgroup_subfield_itemprop][0], t('Field group is not handled as an item.'));
}