You are here

public function ImportOpmlTest::validateImportFormFields in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/aggregator/tests/src/Functional/ImportOpmlTest.php \Drupal\Tests\aggregator\Functional\ImportOpmlTest::validateImportFormFields()

Submits form filled with invalid fields.

1 call to ImportOpmlTest::validateImportFormFields()
ImportOpmlTest::testOpmlImport in core/modules/aggregator/tests/src/Functional/ImportOpmlTest.php
Tests the import of an OPML file.

File

core/modules/aggregator/tests/src/Functional/ImportOpmlTest.php, line 59

Class

ImportOpmlTest
Tests OPML import.

Namespace

Drupal\Tests\aggregator\Functional

Code

public function validateImportFormFields() {
  $count_query = \Drupal::entityQuery('aggregator_feed')
    ->accessCheck(FALSE)
    ->count();
  $before = $count_query
    ->execute();
  $edit = [];
  $this
    ->drupalGet('admin/config/services/aggregator/add/opml');
  $this
    ->submitForm($edit, 'Import');
  $this
    ->assertSession()
    ->pageTextContains('Either upload a file or enter a URL.');
  $path = $this
    ->getEmptyOpml();
  $edit = [
    'files[upload]' => $path,
    'remote' => \Drupal::service('file_url_generator')
      ->generateAbsoluteString($path),
  ];
  $this
    ->drupalGet('admin/config/services/aggregator/add/opml');
  $this
    ->submitForm($edit, 'Import');
  $this
    ->assertSession()
    ->pageTextContains('Either upload a file or enter a URL.');

  // Error if the URL is invalid.
  $edit = [
    'remote' => 'invalidUrl://empty',
  ];
  $this
    ->drupalGet('admin/config/services/aggregator/add/opml');
  $this
    ->submitForm($edit, 'Import');
  $this
    ->assertSession()
    ->pageTextContains('The URL invalidUrl://empty is not valid.');
  $after = $count_query
    ->execute();
  $this
    ->assertEquals($before, $after, 'No feeds were added during the three last form submissions.');
}