function ImportOpmlTest::submitImportForm

Same name in other branches
  1. 8.9.x core/modules/aggregator/tests/src/Functional/ImportOpmlTest.php \Drupal\Tests\aggregator\Functional\ImportOpmlTest::submitImportForm()

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

1 call to ImportOpmlTest::submitImportForm()
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 91

Class

ImportOpmlTest
Tests OPML import.

Namespace

Drupal\Tests\aggregator\Functional

Code

protected function submitImportForm() {
    $count_query = \Drupal::entityQuery('aggregator_feed')->accessCheck(FALSE)
        ->count();
    $before = $count_query->execute();
    // Attempting to upload invalid XML.
    $form['files[upload]'] = $this->getInvalidOpml();
    $this->drupalGet('admin/config/services/aggregator/add/opml');
    $this->submitForm($form, 'Import');
    $this->assertSession()
        ->pageTextContains('No new feed has been added.');
    // Attempting to load empty OPML from remote URL
    $edit = [
        'remote' => \Drupal::service('file_url_generator')->generateAbsoluteString($this->getEmptyOpml()),
    ];
    $this->drupalGet('admin/config/services/aggregator/add/opml');
    $this->submitForm($edit, 'Import');
    $this->assertSession()
        ->pageTextContains('No new feed has been added.');
    $after = $count_query->execute();
    $this->assertEquals($before, $after, 'No feeds were added during the two last form submissions.');
    foreach (Feed::loadMultiple() as $feed) {
        $feed->delete();
    }
    $feeds[0] = $this->getFeedEditArray();
    $feeds[1] = $this->getFeedEditArray();
    $feeds[2] = $this->getFeedEditArray();
    $edit = [
        'files[upload]' => $this->getValidOpml($feeds),
        'refresh' => '900',
    ];
    $this->drupalGet('admin/config/services/aggregator/add/opml');
    $this->submitForm($edit, 'Import');
    // Verify that a duplicate URL was identified.
    $this->assertSession()
        ->pageTextContains('A feed with the URL ' . $feeds[0]['url[0][value]'] . ' already exists.');
    // Verify that a duplicate title was identified.
    $this->assertSession()
        ->pageTextContains('A feed named ' . $feeds[1]['title[0][value]'] . ' already exists.');
    $after = $count_query->execute();
    $this->assertEquals(2, $after, 'Verifying that two distinct feeds were added.');
    $feed_entities = Feed::loadMultiple();
    $refresh = TRUE;
    foreach ($feed_entities as $feed_entity) {
        $title[$feed_entity->getUrl()] = $feed_entity->label();
        $url[$feed_entity->label()] = $feed_entity->getUrl();
        $refresh = $refresh && $feed_entity->getRefreshRate() == 900;
    }
    $this->assertEquals($title[$feeds[0]['url[0][value]']], $feeds[0]['title[0][value]'], 'First feed was added correctly.');
    $this->assertEquals($url[$feeds[1]['title[0][value]']], $feeds[1]['url[0][value]'], 'Second feed was added correctly.');
    $this->assertTrue($refresh, 'Refresh times are correct.');
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.