You are here

public function ImageClassFormatterTest::testClassFormatter in Element Class Formatter 8

File

tests/src/Functional/ImageClassFormatterTest.php, line 20

Class

ImageClassFormatterTest
Functional tests for the image link with class formatter.

Namespace

Drupal\Tests\element_class_formatter\Functional

Code

public function testClassFormatter() {
  $formatter_settings = [
    'class' => self::TEST_CLASS,
  ];
  $field_config = $this
    ->createEntityField('image_class', 'image', $formatter_settings);
  $image = current($this
    ->getTestFiles('image'));
  $file = File::create([
    'uri' => $image->uri,
    'status' => 1,
  ]);
  $file
    ->save();
  $entity = EntityTest::create([
    $field_config
      ->getName() => [
      [
        'target_id' => $file
          ->id(),
      ],
    ],
  ]);
  $entity
    ->save();
  $this
    ->drupalGet($entity
    ->toUrl());
  $assert_session = $this
    ->assertSession();
  $assert_session
    ->elementExists('css', 'img.' . self::TEST_CLASS);
}