You are here

public function MicrodataCompoundFieldsMarkupTestCase::testAttributesInMarkup in Microdata 7

Tests the placement of attributes in field markup.

File

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

Class

MicrodataCompoundFieldsMarkupTestCase

Code

public function testAttributesInMarkup() {
  $edit = array();
  $locality = 'Pittsburgh';

  // Create node and save, then edit node to add fields. We want to test that
  // the second field contains the proper value to ensure that they aren't
  // all combined on the first field.
  $node = $this
    ->drupalCreateNode(array(
    'type' => $this->bundleType,
    'promote' => 1,
  ));
  $node_load = node_load($node->nid);
  $node_load->{$this->addressfieldFieldName}[LANGUAGE_NONE][0]['country'] = 'US';
  $node_load->{$this->addressfieldFieldName}[LANGUAGE_NONE][0]['thoroughfare'] = $this
    ->randomName();
  $node_load->{$this->addressfieldFieldName}[LANGUAGE_NONE][0]['locality'] = 'NotCorrect';
  $node_load->{$this->addressfieldFieldName}[LANGUAGE_NONE][1]['country'] = 'US';
  $node_load->{$this->addressfieldFieldName}[LANGUAGE_NONE][1]['thoroughfare'] = $this
    ->randomName();
  $node_load->{$this->addressfieldFieldName}[LANGUAGE_NONE][1]['locality'] = $locality;
  node_save($node_load);

  // Get the microdata result for the page.
  $this
    ->drupalGet('node/' . $node->nid);
  $md = $this
    ->parseMicrodata();
  $item = $md->items[0];

  // Get mapping info for testing.
  $full_mapping = $this
    ->getMapping();
  $mapping = $full_mapping[$this->entityType][$this->bundleType];
  $field_itemprop = $mapping[$this->addressfieldFieldName]['#itemprop'][0];
  $subfield_itemprop = $mapping[$this->addressfieldFieldName][$this->subfieldName]['#itemprop'][0];

  // Test that the correct locality is found on the second item.
  $this
    ->assertEqual($locality, $item->properties[$field_itemprop][1]->properties[$subfield_itemprop][0], t('Compound field AddressField is handled as an item with properties.'));
}