You are here

public function ResponsiveImageClassFormatterTest::testClassFormatter in Element Class Formatter 8

File

modules/element_class_formatter_responsive_image/tests/src/Functional/ResponsiveImageClassFormatterTest.php, line 28

Class

ResponsiveImageClassFormatterTest
Functional tests for the responsive image link with class formatter.

Namespace

Drupal\Tests\element_class_formatter_responsive_image\Functional

Code

public function testClassFormatter() {
  $formatter_settings = [
    'class' => self::TEST_CLASS,
  ];
  $field_config = $this
    ->createEntityField('responsive_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);
}