You are here

public function ImportOpmlTest::validateImportFormFields in Drupal 8

Same name and namespace in other branches
  1. 9 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 58

Class

ImportOpmlTest
Tests OPML import.

Namespace

Drupal\Tests\aggregator\Functional

Code

public function validateImportFormFields() {
  $count_query = \Drupal::entityQuery('aggregator_feed')
    ->count();
  $before = $count_query
    ->execute();
  $edit = [];
  $this
    ->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
  $this
    ->assertRaw(t('<em>Either</em> upload a file or enter a URL.'), 'Error if no fields are filled.');
  $path = $this
    ->getEmptyOpml();
  $edit = [
    'files[upload]' => $path,
    'remote' => file_create_url($path),
  ];
  $this
    ->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
  $this
    ->assertRaw(t('<em>Either</em> upload a file or enter a URL.'), 'Error if both fields are filled.');
  $edit = [
    'remote' => 'invalidUrl://empty',
  ];
  $this
    ->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
  $this
    ->assertText(t('The URL invalidUrl://empty is not valid.'), 'Error if the URL is invalid.');
  $after = $count_query
    ->execute();
  $this
    ->assertEqual($before, $after, 'No feeds were added during the three last form submissions.');
}