View source
<?php
namespace Drupal\image_replace\Tests;
class EntityTest extends ImageReplaceTestBase {
protected $profile = 'standard';
protected $styleName;
public static function getInfo() {
return array(
'name' => 'Entity',
'description' => 'Tests core entity API integration for the replace image effect',
'group' => 'Image Replace',
);
}
public function setUp() {
parent::setUp(array(
'image',
'image_replace',
));
$this->styleName = 'image_replace_test';
$this
->createImageStyle($this->styleName);
$this
->createImageField('image_replacement', 'article');
$instance = $this
->createImageField('image_original', 'article', array(), array(
'image_replace' => array(
$this->styleName => array(
'source_field' => 'image_replacement',
),
),
));
$instance['display']['teaser']['type'] = 'image';
$instance['display']['teaser']['settings']['image_style'] = $this->styleName;
$instance['display']['full']['type'] = 'image';
$instance['display']['full']['settings']['image_style'] = NULL;
field_update_instance($instance);
field_bundle_settings('node', 'article', array(
'view_modes' => array(
'full' => array(
'custom_settings' => TRUE,
),
'teaser' => array(
'custom_settings' => TRUE,
),
),
));
}
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);
$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);
$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.');
$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);
$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.');
}
}