public function TextimageFieldFormatterTest::testTextimageFieldFormatter in Textimage 7.3
Test Textimage formatter on node display.
File
- tests/
textimage.test, line 321 - Textimage - web test case script.
Class
- TextimageFieldFormatterTest
- Test class to check that Textimage formatter is working.
Code
public function testTextimageFieldFormatter() {
// Create a text field for Textimage test.
$field_name = strtolower($this
->randomName());
$this
->createTextimageField($field_name, 'article');
// Create a new node.
$field_value = $this
->randomName(20);
$nid = $this
->createTextimageNode($field_name, $field_value, 'article');
$node = node_load($nid, NULL, TRUE);
// Get Textimage URL.
$textimage_url = TextimageImager::getImageUrl('textimage_test', NULL, array(
$field_value,
), 'png', TRUE, $node);
// Test the textimage formatter - no link.
$instance = field_info_instance('node', $field_name, 'article');
$instance['display']['default']['type'] = 'textimage';
$instance['display']['default']['settings']['image_style'] = 'textimage_test';
$instance['display']['default']['settings']['image_link'] = '';
$instance['display']['default']['settings']['image_alt'] = 'Alternate text: [node:title]';
$instance['display']['default']['settings']['image_title'] = 'Title: [node:title]';
field_update_instance($instance);
$this
->drupalGet('node/' . $nid);
$elements = $this
->xpath('//img[@src = :src]', array(
':src' => $textimage_url,
));
$this
->assertTrue(!empty($elements), 'Unlinked Textimage displaying on full node view.');
$this
->assertEqual($elements[0]['alt'], 'Alternate text: ' . $field_value, 'Textimage has expected alt attribute.');
$this
->assertEqual($elements[0]['title'], 'Title: ' . $field_value, 'Textimage has expected title attribute.');
// Test the textimage formatter - linked to content.
$instance['display']['default']['settings']['image_link'] = 'content';
field_update_instance($instance);
$this
->drupalGet('node/' . $nid);
$elements = $this
->xpath('//a[contains(@href, :href)]/img[@src = :src]', array(
':href' => 'node/' . $nid,
':src' => $textimage_url,
));
$this
->assertTrue(!empty($elements), 'Textimage linked to content displaying on full node view.');
$this
->assertEqual($elements[0]['alt'], 'Alternate text: ' . $field_value, 'Textimage has expected alt attribute.');
$this
->assertEqual($elements[0]['title'], 'Title: ' . $field_value, 'Textimage has expected title attribute.');
// Test the textimage formatter - linked to Textimage file.
$instance['display']['default']['settings']['image_link'] = 'file';
$instance['display']['default']['settings']['image_alt'] = 'Alternate text: [node:author]';
$instance['display']['default']['settings']['image_title'] = 'Title: [node:author]';
field_update_instance($instance);
$this
->drupalGet('node/' . $nid);
$elements = $this
->xpath('//a[@href = :href]/img[@src = :src]', array(
':href' => $textimage_url,
':src' => $textimage_url,
));
$this
->assertTrue(!empty($elements), 'Textimage linked to image file displaying on full node view.');
$this
->assertEqual($elements[0]['alt'], 'Alternate text: ' . $this->admin_user->name, 'Textimage has expected alt attribute.');
$this
->assertEqual($elements[0]['title'], 'Title: ' . $this->admin_user->name, 'Textimage has expected title attribute.');
}