From 5a58ba9f6b177bb387110df5fd57b43f8c1a4533 Mon Sep 17 00:00:00 2001
From: Alex Pott <alex.a.pott@googlemail.com>
Date: Fri, 13 Mar 2015 23:03:50 +0000
Subject: [PATCH] Issue #2449709 by banviktor: ContentEntityBase::set() does
 not respect its interface

---
 core/lib/Drupal/Core/Entity/ContentEntityBase.php  |  1 +
 .../Core/Entity/ContentEntityBaseUnitTest.php      | 14 ++++++++++++++
 2 files changed, 15 insertions(+)

diff --git a/core/lib/Drupal/Core/Entity/ContentEntityBase.php b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
index 8d37a63ee438..d315b27139bd 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityBase.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityBase.php
@@ -409,6 +409,7 @@ public function set($name, $value, $notify = TRUE) {
     // notified to handle changes afterwards. We can ignore notify as there is
     // no parent to notify anyway.
     $this->get($name)->setValue($value, TRUE);
+    return $this;
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
index 0960d4347b73..b3bd6bd784c0 100644
--- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityBaseUnitTest.php
@@ -166,6 +166,9 @@ protected function setUp() {
     $this->fieldTypePluginManager->expects($this->any())
       ->method('getDefaultFieldSettings')
       ->will($this->returnValue(array()));
+    $this->fieldTypePluginManager->expects($this->any())
+      ->method('createFieldItemList')
+      ->will($this->returnValue($this->getMock('Drupal\Core\Field\FieldItemListInterface')));
 
     $container = new ContainerBuilder();
     $container->set('entity.manager', $this->entityManager);
@@ -536,4 +539,15 @@ public function testGetFields($expected, $include_computed, $is_computed, $field
     );
   }
 
+  /**
+   * @covers ::set
+   */
+  public function testSet() {
+    // Exercise set(), check if it returns $this
+    $this->assertSame(
+      $this->entity,
+      $this->entity->set('id', 0)
+    );
+  }
+
 }
-- 
GitLab