From 065888cbd6c2d7b3aff840b48a3f1bd19ee76cc0 Mon Sep 17 00:00:00 2001
From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org>
Date: Fri, 15 Sep 2017 12:34:23 +0100
Subject: [PATCH] Issue #2905738 by vaplas, Wim Leers: Media::setOwnerId()
 doesn't return the Media entity

---
 core/modules/media/src/Entity/Media.php       |  2 +-
 .../media/tests/src/Kernel/MediaTest.php      | 23 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)
 create mode 100644 core/modules/media/tests/src/Kernel/MediaTest.php

diff --git a/core/modules/media/src/Entity/Media.php b/core/modules/media/src/Entity/Media.php
index f8f8d6bdd430..1f8c8d3a473b 100644
--- a/core/modules/media/src/Entity/Media.php
+++ b/core/modules/media/src/Entity/Media.php
@@ -152,7 +152,7 @@ public function getOwnerId() {
    * {@inheritdoc}
    */
   public function setOwnerId($uid) {
-    $this->set('uid', $uid);
+    return $this->set('uid', $uid);
   }
 
   /**
diff --git a/core/modules/media/tests/src/Kernel/MediaTest.php b/core/modules/media/tests/src/Kernel/MediaTest.php
new file mode 100644
index 000000000000..5971f6535302
--- /dev/null
+++ b/core/modules/media/tests/src/Kernel/MediaTest.php
@@ -0,0 +1,23 @@
+<?php
+
+namespace Drupal\Tests\media\Kernel;
+
+use Drupal\media\Entity\Media;
+
+/**
+ * Tests Media.
+ *
+ * @group media
+ */
+class MediaTest extends MediaKernelTestBase {
+
+  /**
+   * Tests various aspects of a Media entity.
+   */
+  public function testEntity() {
+    $media = Media::create(['bundle' => $this->testMediaType->id()]);
+
+    $this->assertSame($media, $media->setOwnerId($this->user->id()), 'setOwnerId() method returns its own entity.');
+  }
+
+}
-- 
GitLab