public function FeedValidationTest::testValidation in Zircon Profile 8.0
Same name and namespace in other branches
- 8 core/modules/aggregator/src/Tests/FeedValidationTest.php \Drupal\aggregator\Tests\FeedValidationTest::testValidation()
Tests the feed validation constraints.
File
- core/
modules/ aggregator/ src/ Tests/ FeedValidationTest.php, line 38 - Contains \Drupal\aggregator\Tests\FeedValidationTest.
Class
- FeedValidationTest
- Tests feed validation constraints.
Namespace
Drupal\aggregator\TestsCode
public function testValidation() {
// Add feed.
$feed = Feed::create([
'title' => 'Feed 1',
'url' => 'https://www.drupal.org/planet/rss.xml',
'refresh' => 900,
]);
$violations = $feed
->validate();
$this
->assertEqual(count($violations), 0);
$feed
->save();
// Add another feed.
/* @var \Drupal\aggregator\FeedInterface $feed */
$feed = Feed::create([
'title' => 'Feed 1',
'url' => 'https://www.drupal.org/planet/rss.xml',
'refresh' => 900,
]);
$violations = $feed
->validate();
$this
->assertEqual(count($violations), 2);
$this
->assertEqual($violations[0]
->getPropertyPath(), 'title');
$this
->assertEqual($violations[0]
->getMessage(), t('A feed named %value already exists. Enter a unique title.', [
'%value' => $feed
->label(),
]));
$this
->assertEqual($violations[1]
->getPropertyPath(), 'url');
$this
->assertEqual($violations[1]
->getMessage(), t('A feed with this URL %value already exists. Enter a unique URL.', [
'%value' => $feed
->getUrl(),
]));
}