You are here

public function FileFieldPathsGeneralTest::testAddField in File (Field) Paths 8

Test that the File (Field) Paths UI works as expected.

File

tests/src/Functional/FileFieldPathsGeneralTest.php, line 18

Class

FileFieldPathsGeneralTest
Test general functionality.

Namespace

Drupal\Tests\filefield_paths\Functional

Code

public function testAddField() {
  $session = $this
    ->assertSession();

  // Create a File field.
  $field_name = mb_strtolower($this
    ->randomMachineName());
  $field_settings = [
    'file_directory' => "fields/{$field_name}",
  ];
  $this
    ->createFileField($field_name, 'node', $this->contentType, [], $field_settings);

  // Ensure File (Field) Paths settings are present.
  $this
    ->drupalGet("admin/structure/types/manage/{$this->contentType}/fields/node.{$this->contentType}.{$field_name}");

  // File (Field) Path settings are present.
  $session
    ->responseContains('Enable File (Field) Paths?');

  // Ensure that 'Enable File (Field) Paths?' is a direct sibling of
  // 'File (Field) Path settings'.

  /* @var \Behat\Mink\Element\NodeElement[] $element */
  $element = $this
    ->xpath('//div[contains(@class, :class)]/following-sibling::*[1][@id=\'edit-third-party-settings-filefield-paths--2\']', [
    ':class' => 'form-item-third-party-settings-filefield-paths-enabled',
  ]);
  $this
    ->assertNotEmpty($element, 'Enable checkbox is next to settings fieldset.');

  // Ensure that the File path used the File directory as it's default value.
  $session
    ->fieldValueEquals('third_party_settings[filefield_paths][file_path][value]', "fields/{$field_name}");
}