You are here

public function SwaggerUiFieldFormatterTest::testFileFormatter in Swagger UI Field Formatter 8.3

Tests the file field formatter.

File

tests/src/FunctionalJavascript/SwaggerUiFieldFormatterTest.php, line 55

Class

SwaggerUiFieldFormatterTest
Tests file and link field formatters.

Namespace

Drupal\Tests\swagger_ui_formatter\FunctionalJavascript

Code

public function testFileFormatter() : void {
  $page = $this
    ->getSession()
    ->getPage();
  $assert = $this
    ->assertSession();
  $this
    ->drupalLogin($this->rootUser);
  $this
    ->drupalGet(Url::fromRoute('node.add', [
    'node_type' => 'api_doc',
  ]));
  $petstore_path = $this->fileSystem
    ->realpath('public://petstore-expanded.yaml');
  $uspto_path = $this->fileSystem
    ->realpath('public://uspto.yaml');
  $page
    ->attachFileToField('files[field_api_spec_0][]', $petstore_path);
  $assert
    ->waitForField('field_api_spec_0_remove_button');
  $page
    ->attachFileToField('files[field_api_spec_1][]', $uspto_path);
  $assert
    ->waitForField('field_api_spec_1_remove_button');
  $this
    ->createScreenshot(__FUNCTION__ . '-after-file-upload');
  $this
    ->drupalPostForm(NULL, [
    'title[0][value]' => 'Testing the file field formatter',
  ], 'Save');
  $this
    ->createScreenshot(__FUNCTION__ . '-after-save');
  $assert
    ->waitForField('swagger-ui-field_api_spec-0');
  $assert
    ->pageTextContains('Swagger Petstore');
  $assert
    ->waitForField('swagger-ui-field_api_spec-1');
  $assert
    ->pageTextContains('USPTO Data Set API');
  $this
    ->validateSwaggerUiErrorMessage(__FUNCTION__);
}