You are here

protected function ImportOpmlTest::submitImportForm in Zircon Profile 8.0

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

Submits form with invalid, empty, and valid OPML files.

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

File

core/modules/aggregator/src/Tests/ImportOpmlTest.php, line 77
Contains \Drupal\aggregator\Tests\ImportOpmlTest.

Class

ImportOpmlTest
Tests OPML import.

Namespace

Drupal\aggregator\Tests

Code

protected function submitImportForm() {
  $before = db_query('SELECT COUNT(*) FROM {aggregator_feed}')
    ->fetchField();
  $form['files[upload]'] = $this
    ->getInvalidOpml();
  $this
    ->drupalPostForm('admin/config/services/aggregator/add/opml', $form, t('Import'));
  $this
    ->assertText(t('No new feed has been added.'), 'Attempting to upload invalid XML.');
  $edit = array(
    'remote' => file_create_url($this
      ->getEmptyOpml()),
  );
  $this
    ->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
  $this
    ->assertText(t('No new feed has been added.'), 'Attempting to load empty OPML from remote URL.');
  $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')
    ->fetchField();
  $this
    ->assertEqual($before, $after, 'No feeds were added during the two last form submissions.');
  db_delete('aggregator_feed')
    ->execute();
  $feeds[0] = $this
    ->getFeedEditArray();
  $feeds[1] = $this
    ->getFeedEditArray();
  $feeds[2] = $this
    ->getFeedEditArray();
  $edit = array(
    'files[upload]' => $this
      ->getValidOpml($feeds),
    'refresh' => '900',
  );
  $this
    ->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
  $this
    ->assertRaw(t('A feed with the URL %url already exists.', array(
    '%url' => $feeds[0]['url[0][value]'],
  )), 'Verifying that a duplicate URL was identified');
  $this
    ->assertRaw(t('A feed named %title already exists.', array(
    '%title' => $feeds[1]['title[0][value]'],
  )), 'Verifying that a duplicate title was identified');
  $after = db_query('SELECT COUNT(*) FROM {aggregator_feed}')
    ->fetchField();
  $this
    ->assertEqual($after, 2, 'Verifying that two distinct feeds were added.');
  $feeds_from_db = db_query("SELECT title, url, refresh FROM {aggregator_feed}");
  $refresh = TRUE;
  foreach ($feeds_from_db as $feed) {
    $title[$feed->url] = $feed->title;
    $url[$feed->title] = $feed->url;
    $refresh = $refresh && $feed->refresh == 900;
  }
  $this
    ->assertEqual($title[$feeds[0]['url[0][value]']], $feeds[0]['title[0][value]'], 'First feed was added correctly.');
  $this
    ->assertEqual($url[$feeds[1]['title[0][value]']], $feeds[1]['url[0][value]'], 'Second feed was added correctly.');
  $this
    ->assertTrue($refresh, 'Refresh times are correct.');
}