FeedValidationTest.php in Zircon Profile 8
File
core/modules/aggregator/src/Tests/FeedValidationTest.php
View source
<?php
namespace Drupal\aggregator\Tests;
use Drupal\aggregator\Entity\Feed;
use Drupal\system\Tests\Entity\EntityUnitTestBase;
class FeedValidationTest extends EntityUnitTestBase {
public static $modules = array(
'aggregator',
'options',
);
protected function setUp() {
parent::setUp();
$this
->installEntitySchema('aggregator_feed');
}
public function testValidation() {
$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();
$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(),
]));
}
}