You are here

public function BlockAttributesTestCase::assertBlockAttributesDisplay in Block Attributes 7

Assert whether all HTML attributes display correctly in page's markup.

All attributes in all scopes (Block, title and content levels) are checked in the markup using xpath queries.

Parameters

array $block_attributes: An array containing test values for all the html attributes.

4 calls to BlockAttributesTestCase::assertBlockAttributesDisplay()
BlockAttributesAdminConfigTestCase::testAdminConfigForm in ./block_attributes.test
Create a block based on default settings and test disabling attributes.
BlockAttributesFeaturesTestCase::testFeatureDisplayAttributes in ./block_attributes.test
Test how Block Attributes reacts when exported to a Feature with FE Block.
BlockAttributesMenuBlockTestCase::testMenuBlockDisplayAttributes in ./block_attributes.test
Create, update and display a Menu Block to ensure attributes are found.
BlockAttributesTestCase::assertUpdateDisplayBlockAttributes in ./block_attributes.test
Update Block Attributes and assert whether they are found when displayed.

File

./block_attributes.test, line 142
Test the Block Attributes module.

Class

BlockAttributesTestCase
Provides common functionality for the Block Attributes test classes.

Code

public function assertBlockAttributesDisplay($block_attributes) {

  // Prepare string replacements arrays for xpath and format_string.
  foreach ($block_attributes as $key => $value) {

    // Remove the square brackets from the keys: they can't go through xpath.
    // Transform 'attributes[id]' into ':attributesid', for example.
    $xpath_replacements[':' . str_replace(array(
      '[',
      ']',
    ), '', $key)] = $value;

    // Transform 'attributes[id]' into '@attributes[id]', for example.
    $string_replacements['@' . $key] = $value;
  }

  // Test BLOCK_ATTRIBUTES_BLOCK and BLOCK_ATTRIBUTES_TITLE scopes:
  // Query the markup to find Block and Title level markup and attributes.
  $block_xpath = $this
    ->xpath('//div[@id = :attributesid][contains(@class, :attributesclass)][@accesskey = :attributesaccesskey][@align = :attributesalign][@style = :attributesstyle][@title = :attributestitle]/h2[@align = :title_attributesalign][contains(@class, :title_attributesclass)][@id = :title_attributesid][@style = :title_attributesstyle][@title = :title_attributestitle]', $xpath_replacements);

  // Test Block level and Title markup attributes and text.
  $this
    ->assertTrue(!empty($block_xpath[0]) && (string) $block_xpath[0] == $block_attributes['title'], format_string('The Block level HTML attributes have all been found:<br/>[ID: @attributes[id]], [class: @attributes[class]], [accesskey: @attributes[accesskey]], [align: @attributes[align]], [style: @attributes[style]], [title: @attributes[title]].<br/> The Block Title HTML attributes have all been found:<br/>[ID: @title_attributes[id]], [class: @title_attributes[class]], [align: @title_attributes[align]], [style: @title_attributes[style]], [title: @title_attributes[title]].<br/>The Block Title has been found: @title.', $string_replacements));

  // Test BLOCK_ATTRIBUTES_CONTENT scope:
  // Query the markup to find Block content attributes.
  $block_xpath = $this
    ->xpath('//div[@id = :attributesid][contains(@class, :attributesclass)][@accesskey = :attributesaccesskey][@align = :attributesalign][@style = :attributesstyle][@title = :attributestitle]/div[@align = :content_attributesalign][@class = "content"][@id = :content_attributesid][@style = :content_attributesstyle][@title = :content_attributestitle]', $xpath_replacements);

  // Test Block content attributes.
  $this
    ->assertTrue(!empty($block_xpath[0]), format_string('The Block content HTML attributes have all been found:<br/>[ID: @content_attributes[id]], [align: @content_attributes[align]], [style: @content_attributes[style]], [title: @content_attributes[title]].', $string_replacements));
}