You are here

public function InsertFileTest::testSingleStyle in Insert 8.2

File

tests/src/FunctionalJavaScript/InsertFileTest.php, line 76

Class

InsertFileTest
Tests Insert module's generic file insert capability.

Namespace

Drupal\Tests\insert\FunctionalJavascript

Code

public function testSingleStyle() {
  $fieldName = strtolower($this
    ->randomMachineName());
  $this
    ->createFileField($fieldName);
  $this
    ->updateInsertSettings($fieldName, [
    'styles' => [
      'link' => 'link',
    ],
    'default' => 'link',
  ]);
  $this
    ->drupalGet('node/add/article');
  $page = $this
    ->getSession()
    ->getPage();
  $files = $this
    ->drupalGetTestFiles('text');
  $page
    ->attachFileToField('files[' . $fieldName . '_0]', \Drupal::service('file_system')
    ->realpath($files[0]->uri));
  $this
    ->assertSession()
    ->waitForField($fieldName . '[0][fids]');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '.insert')), 'Insert container node exists');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '.insert > .insert-templates')), 'Insert templates exist');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '[name="' . $fieldName . '[0][insert_template][link]"]')), 'Insert link template exists');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '.insert > input.insert-filename')), 'Insert filename input node exists');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '.insert > input.insert-style')), 'Insert style input node exists');
  $this
    ->assertEquals('link', $page
    ->find('css', '.insert > .insert-style')
    ->getValue(), 'Insert style value is "link"');
  $this
    ->assertEquals(1, count($page
    ->findAll('css', '.insert input.insert-button')), 'Insert button exists');
}