From 22716ab7fe87b53a732defaa0bd5c7f6802d26e7 Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Fri, 30 Oct 2015 22:48:31 +0000 Subject: [PATCH] Issue #2602662 by mikeryan, phenaproxima: Feed ID should be required base field for aggregator items --- core/modules/aggregator/aggregator.install | 16 +++++++ core/modules/aggregator/src/Entity/Item.php | 1 + .../src/Tests/ItemWithoutFeedTest.php | 46 +++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 core/modules/aggregator/src/Tests/ItemWithoutFeedTest.php diff --git a/core/modules/aggregator/aggregator.install b/core/modules/aggregator/aggregator.install index ad5f92f1fb94..a763639f8880 100644 --- a/core/modules/aggregator/aggregator.install +++ b/core/modules/aggregator/aggregator.install @@ -21,3 +21,19 @@ function aggregator_requirements($phase) { } return $requirements; } + +/** + * @addtogroup updates-8.0.0-rc + * @{ + */ + +/** + * The simple presence of this update function clears cached field definitions. + */ +function aggregator_update_8001() { + // Feed ID base field is now required. +} + +/** + * @} End of "addtogroup updates-8.0.0-rc". + */ diff --git a/core/modules/aggregator/src/Entity/Item.php b/core/modules/aggregator/src/Entity/Item.php index f175d3a9a474..4c6d10464d9e 100644 --- a/core/modules/aggregator/src/Entity/Item.php +++ b/core/modules/aggregator/src/Entity/Item.php @@ -60,6 +60,7 @@ public static function baseFieldDefinitions(EntityTypeInterface $entity_type) { $fields['fid'] = BaseFieldDefinition::create('entity_reference') ->setLabel(t('Source feed')) + ->setRequired(TRUE) ->setDescription(t('The aggregator feed entity associated with this item.')) ->setSetting('target_type', 'aggregator_feed') ->setDisplayOptions('view', array( diff --git a/core/modules/aggregator/src/Tests/ItemWithoutFeedTest.php b/core/modules/aggregator/src/Tests/ItemWithoutFeedTest.php new file mode 100644 index 000000000000..a6586b934d01 --- /dev/null +++ b/core/modules/aggregator/src/Tests/ItemWithoutFeedTest.php @@ -0,0 +1,46 @@ +<?php + +/** + * @file + * Contains \Drupal\aggregator\Tests\ItemWithoutFeedTest. + */ + +namespace Drupal\aggregator\Tests; + +use Drupal\aggregator\Entity\Item; +use Drupal\KernelTests\KernelTestBase; + +/** + * Tests clean handling of an item with a missing feed ID. + * + * @group aggregator + */ +class ItemWithoutFeedTest extends KernelTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['aggregator', 'options']; + + /** + * {@inheritdoc} + */ + protected function setUp() { + parent::setUp(); + $this->installEntitySchema('aggregator_feed'); + $this->installEntitySchema('aggregator_item'); + } + + /** + * Tests attempting to create a feed item without a feed. + */ + public function testEntityCreation() { + $entity = Item::create([ + 'title' => t('Llama 2'), + 'path' => 'https://groups.drupal.org/', + ]); + $violations = $entity->validate(); + $this->assertCount(1, $violations); + } + +} -- GitLab