public function EntityTest::testNodeView in Image Replace 7
Same name and namespace in other branches
- 8 src/Tests/EntityTest.php \Drupal\image_replace\Tests\EntityTest::testNodeView()
Tests image replacement on node entities.
File
- src/
Tests/ EntityTest.php, line 69
Class
- EntityTest
- Tests functionality of the replace image effect.
Namespace
Drupal\image_replace\TestsCode
public function testNodeView() {
list($original_file, $replacement_file) = $this
->createTestFiles();
$node = (object) array(
'type' => 'article',
);
node_object_prepare($node);
$node->title = $this
->randomName(16);
$node->promote = 1;
$node->language = LANGUAGE_NONE;
$node->image_original[LANGUAGE_NONE][0] = (array) $original_file;
$node->image_replacement[LANGUAGE_NONE][0] = (array) $replacement_file;
node_save($node);
// Check teaser.
$this
->drupalGet('node');
$generated_url = image_style_url($this->styleName, $node->image_original[LANGUAGE_NONE][0]['uri']);
$this
->assertRaw(check_plain($generated_url), format_string('Image displayed using style @style.', array(
'@style' => $this->styleName,
)));
$generated_image_data = $this
->drupalGet($generated_url);
$this
->assertResponse(200);
// Assert that the result is the replacement image.
$generated_uri = file_unmanaged_save_data($generated_image_data);
$this
->assertTrue($this
->imageIsReplacement($generated_uri), 'The generated file should be the same as the replacement file on teaser.');
// Check full view.
$this
->drupalGet('node/' . $node->nid);
$generated_url = file_create_url($node->image_original[LANGUAGE_NONE][0]['uri']);
$this
->assertRaw(check_plain($generated_url), 'Original image displayed');
$generated_image_data = $this
->drupalGet($generated_url);
$this
->assertResponse(200);
// Assert that the result is the original image.
$generated_uri = file_unmanaged_save_data($generated_image_data);
$this
->assertTrue($this
->imageIsOriginal($generated_uri), 'The generated file should be the same as the original file on full node view.');
}