You are here

public function AdminTest::setUp in Image Replace 8

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

Overrides BrowserTestBase::setUp

File

src/Tests/AdminTest.php, line 38

Class

AdminTest
Tests the administrative interface of the image replace module.

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.
  $this
    ->createImageField('image_original', 'article');
  $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();
  $this->adminUser = $this
    ->drupalCreateUser([
    'access content',
    'administer content types',
    'administer image styles',
    'administer node fields',
    'administer nodes',
    'create article content',
    'delete any article content',
    'edit any article content',
  ]);
}