function ImportOpmlTest::submitImportForm
Same name in other branches
- 9 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 85
Class
- ImportOpmlTest
- Tests OPML import.
Namespace
Drupal\Tests\aggregator\FunctionalCode
protected function submitImportForm() {
$count_query = \Drupal::entityQuery('aggregator_feed')->count();
$before = $count_query->execute();
$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 = [
'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 = $count_query->execute();
$this->assertEqual($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->drupalPostForm('admin/config/services/aggregator/add/opml', $edit, t('Import'));
$this->assertRaw(t('A feed with the URL %url already exists.', [
'%url' => $feeds[0]['url[0][value]'],
]), 'Verifying that a duplicate URL was identified');
$this->assertRaw(t('A feed named %title already exists.', [
'%title' => $feeds[1]['title[0][value]'],
]), 'Verifying that a duplicate title was identified');
$after = $count_query->execute();
$this->assertEqual($after, 2, '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->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.');
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.