From ffd4d6a8f763820f9b001f86e215da3d65f73451 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Tue, 17 Jan 2017 12:57:45 +0000
Subject: [PATCH] Issue #2840595 by amateescu, Berdir: The 'Source feed' field
 of aggregator items has to be updated and marked as required

---
 core/modules/aggregator/aggregator.install    | 21 ++++++++++
 .../src/Tests/Update/AggregatorUpdateTest.php | 41 +++++++++++++++++++
 2 files changed, 62 insertions(+)
 create mode 100644 core/modules/aggregator/src/Tests/Update/AggregatorUpdateTest.php

diff --git a/core/modules/aggregator/aggregator.install b/core/modules/aggregator/aggregator.install
index cd7203f17d15..5edc50318152 100644
--- a/core/modules/aggregator/aggregator.install
+++ b/core/modules/aggregator/aggregator.install
@@ -37,3 +37,24 @@ function aggregator_update_8001() {
 /**
  * @} End of "addtogroup updates-8.0.0-rc".
  */
+
+/**
+ * @addtogroup updates-8.2.x
+ * @{
+ */
+
+/**
+ * Make the 'Source feed' field for aggregator items required.
+ */
+function aggregator_update_8200() {
+  // aggregator_update_8001() did not update the last installed field storage
+  // definition for the aggregator item's 'Source feed' field.
+  $definition_update_manager = \Drupal::entityDefinitionUpdateManager();
+  $field_definition = $definition_update_manager->getFieldStorageDefinition('fid', 'aggregator_item');
+  $field_definition->setRequired(TRUE);
+  $definition_update_manager->updateFieldStorageDefinition($field_definition);
+}
+
+/**
+ * @} End of "addtogroup updates-8.2.x".
+ */
diff --git a/core/modules/aggregator/src/Tests/Update/AggregatorUpdateTest.php b/core/modules/aggregator/src/Tests/Update/AggregatorUpdateTest.php
new file mode 100644
index 000000000000..374a38e89a96
--- /dev/null
+++ b/core/modules/aggregator/src/Tests/Update/AggregatorUpdateTest.php
@@ -0,0 +1,41 @@
+<?php
+
+namespace Drupal\aggregator\Tests\Update;
+
+use Drupal\system\Tests\Update\UpdatePathTestBase;
+
+/**
+ * Tests that node settings are properly updated during database updates.
+ *
+ * @group aggregator
+ */
+class AggregatorUpdateTest extends UpdatePathTestBase {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function setDatabaseDumpFiles() {
+    $this->databaseDumpFiles = [
+      __DIR__ . '/../../../../system/tests/fixtures/update/drupal-8.filled.standard.php.gz',
+    ];
+  }
+
+  /**
+   * Tests that the 'Source feed' field is required.
+   *
+   * @see aggregator_update_8200()
+   */
+  public function testSourceFeedRequired() {
+    // Check that the 'fid' field is not required prior to the update.
+    $field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('fid', 'aggregator_item');
+    $this->assertFalse($field_definition->isRequired());
+
+    // Run updates.
+    $this->runUpdates();
+
+    // Check that the 'fid' field is now required.
+    $field_definition = \Drupal::entityDefinitionUpdateManager()->getFieldStorageDefinition('fid', 'aggregator_item');
+    $this->assertTrue($field_definition->isRequired());
+  }
+
+}
-- 
GitLab