3 namespace Drupal\Tests\aggregator\Kernel;
5 use Drupal\aggregator\Entity\Feed;
6 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
9 * Tests feed validation constraints.
13 class FeedValidationTest extends EntityKernelTestBase {
20 public static $modules = ['aggregator', 'options'];
25 protected function setUp() {
27 $this->installEntitySchema('aggregator_feed');
31 * Tests the feed validation constraints.
33 public function testValidation() {
35 $feed = Feed::create([
37 'url' => 'https://www.drupal.org/planet/rss.xml',
41 $violations = $feed->validate();
42 $this->assertEqual(count($violations), 0);
47 /* @var \Drupal\aggregator\FeedInterface $feed */
48 $feed = Feed::create([
50 'url' => 'https://www.drupal.org/planet/rss.xml',
54 $violations = $feed->validate();
56 $this->assertEqual(count($violations), 2);
57 $this->assertEqual($violations[0]->getPropertyPath(), 'title');
58 $this->assertEqual($violations[0]->getMessage(), t('A feed named %value already exists. Enter a unique title.', [
59 '%value' => $feed->label(),
61 $this->assertEqual($violations[1]->getPropertyPath(), 'url');
62 $this->assertEqual($violations[1]->getMessage(), t('A feed with this URL %value already exists. Enter a unique URL.', [
63 '%value' => $feed->getUrl(),