diff --git a/Entity/Task.php b/Entity/Task.php index 6f86a23..8248504 100644 --- a/Entity/Task.php +++ b/Entity/Task.php @@ -215,7 +215,12 @@ public function setTaskId($taskId) */ public function getCreatorFullName() { - return $this->getCreator()->getFullName(); + $creator = $this->getCreator(); + if (!$creator) { + return ''; + } + + return $creator->getFullName(); } /** @@ -223,6 +228,11 @@ public function getCreatorFullName() */ public function getChangerFullName() { - return $this->getChanger()->getFullName(); + $changer = $this->getChanger(); + if (!$changer) { + return ''; + } + + return $changer->getFullName(); } } diff --git a/Tests/Functional/Controller/TaskControllerTest.php b/Tests/Functional/Controller/TaskControllerTest.php index 421c8db..f0074f9 100644 --- a/Tests/Functional/Controller/TaskControllerTest.php +++ b/Tests/Functional/Controller/TaskControllerTest.php @@ -11,6 +11,7 @@ namespace Functional\Controller; +use Sulu\Bundle\AutomationBundle\Entity\Task; use Sulu\Bundle\AutomationBundle\Tests\Handler\FirstHandler; use Sulu\Bundle\AutomationBundle\Tests\Handler\SecondHandler; use Sulu\Bundle\TestBundle\Testing\SuluTestCase; @@ -334,6 +335,30 @@ public function testGet() $this->assertEquals($postData['locale'], $responseData['locale']); } + public function testGetWithoutCreator() + { + $task = new Task(); + $task->setEntityClass(Task::class); + $task->setEntityId(1); + $task->setLocale('de'); + $task->setHandlerClass(FirstHandler::class); + $task->setSchedule(new \DateTime()); + + $taskManager = $this->getContainer()->get('sulu_automation.tasks.manager'); + $taskManager->create($task); + $this->getEntityManager()->flush(); + + $client = $this->createAuthenticatedClient(); + $client->request('GET', '/api/tasks/' . $task->getId()); + $this->assertHttpStatusCode(200, $client->getResponse()); + + $responseData = json_decode($client->getResponse()->getContent(), true); + + $this->assertEquals($task->getId(), $responseData['id']); + $this->assertEquals('', $responseData['creator']); + $this->assertEquals('', $responseData['changer']); + } + public function testDelete() { $postData = $this->testPost();