public function AggregatorTestBase::createFeed in Drupal 8
Same name in this branch
- 8 core/modules/aggregator/src/Tests/AggregatorTestBase.php \Drupal\aggregator\Tests\AggregatorTestBase::createFeed()
- 8 core/modules/aggregator/tests/src/Functional/AggregatorTestBase.php \Drupal\Tests\aggregator\Functional\AggregatorTestBase::createFeed()
Creates an aggregator feed.
This method simulates the form submission on path aggregator/sources/add.
Parameters
string $feed_url: (optional) If given, feed will be created with this URL, otherwise /rss.xml will be used. Defaults to NULL.
array $edit: Array with additional form fields.
Return value
\Drupal\aggregator\FeedInterface Full feed object if possible.
See also
getFeedEditArray()
File
- core/
modules/ aggregator/ src/ Tests/ AggregatorTestBase.php, line 77
Class
- AggregatorTestBase
- Defines a base class for testing the Aggregator module.
Namespace
Drupal\aggregator\TestsCode
public function createFeed($feed_url = NULL, array $edit = []) {
$edit = $this
->getFeedEditArray($feed_url, $edit);
$this
->drupalPostForm('aggregator/sources/add', $edit, t('Save'));
$this
->assertText(t('The feed @name has been added.', [
'@name' => $edit['title[0][value]'],
]), new FormattableMarkup('The feed @name has been added.', [
'@name' => $edit['title[0][value]'],
]));
// Verify that the creation message contains a link to a feed.
$view_link = $this
->xpath('//div[@class="messages"]//a[contains(@href, :href)]', [
':href' => 'aggregator/sources/',
]);
$this
->assert(isset($view_link), 'The message area contains a link to a feed');
$fids = \Drupal::entityQuery('aggregator_feed')
->condition('title', $edit['title[0][value]'])
->condition('url', $edit['url[0][value]'])
->execute();
$this
->assertNotEmpty($fids, 'The feed found in database.');
return Feed::load(array_values($fids)[0]);
}