You are here

public function EntityTest::setUp in Image Replace 8

Same name and namespace in other branches
  1. 7 src/Tests/EntityTest.php \Drupal\image_replace\Tests\EntityTest::setUp()

Overrides BrowserTestBase::setUp

File

src/Tests/EntityTest.php, line 31

Class

EntityTest
Tests core entity API integration for the replace image effect.

Namespace

Drupal\image_replace\Tests

Code

public function setUp() {
  parent::setUp();

  // Create an image style containing the replace effect.
  $this->styleName = 'image_replace_test';
  $this
    ->createImageStyle($this->styleName);

  // Add the replacement image field to the article bundle.
  $this
    ->drupalCreateContentType([
    'type' => 'article',
    'name' => 'Article',
  ]);
  $this
    ->createImageField('image_replacement', 'article');

  // Add the original image field to the article bundle and specify
  // the replacement image as replacement.
  $field = $this
    ->createImageField('image_original', 'article');
  $field
    ->setThirdPartySetting('image_replace', 'image_style_map', [
    $this->styleName => [
      'source_field' => 'image_replacement',
    ],
  ]);
  $field
    ->save();
  $entity_display_repository = \Drupal::service('entity_display.repository');
  $display = $entity_display_repository
    ->getViewDisplay('node', 'article', 'teaser');
  $display_options = $display
    ->getComponent('image_original');
  $display_options['type'] = 'image';
  $display_options['settings']['image_style'] = $this->styleName;
  $display
    ->set('status', TRUE);
  $display
    ->setComponent('image_original', $display_options);
  $display
    ->save();
  $display = $entity_display_repository
    ->getViewDisplay('node', 'article', 'full');
  $display_options = $display
    ->getComponent('image_original');
  $display_options['type'] = 'image';
  $display_options['settings']['image_style'] = NULL;
  $display
    ->set('status', TRUE);
  $display
    ->setComponent('image_original', $display_options);
  $display
    ->save();
}