d8804dd9c3792093de789545347e67fc45baec5f
[yaffs-website] / web / core / modules / aggregator / tests / src / Kernel / FeedValidationTest.php
1 <?php
2
3 namespace Drupal\Tests\aggregator\Kernel;
4
5 use Drupal\aggregator\Entity\Feed;
6 use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
7
8 /**
9  * Tests feed validation constraints.
10  *
11  * @group aggregator
12  */
13 class FeedValidationTest extends EntityKernelTestBase {
14
15   /**
16    * Modules to install.
17    *
18    * @var array
19    */
20   public static $modules = ['aggregator', 'options'];
21
22   /**
23    * {@inheritdoc}
24    */
25   protected function setUp() {
26     parent::setUp();
27     $this->installEntitySchema('aggregator_feed');
28   }
29
30   /**
31    * Tests the feed validation constraints.
32    */
33   public function testValidation() {
34     // Add feed.
35     $feed = Feed::create([
36       'title' => 'Feed 1',
37       'url' => 'https://www.drupal.org/planet/rss.xml',
38       'refresh' => 900,
39     ]);
40
41     $violations = $feed->validate();
42     $this->assertEqual(count($violations), 0);
43
44     $feed->save();
45
46     // Add another feed.
47     /* @var \Drupal\aggregator\FeedInterface $feed */
48     $feed = Feed::create([
49       'title' => 'Feed 1',
50       'url' => 'https://www.drupal.org/planet/rss.xml',
51       'refresh' => 900,
52     ]);
53
54     $violations = $feed->validate();
55
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(),
60     ]));
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(),
64     ]));
65   }
66
67 }