Skip to content

Commit

Permalink
Merge pull request #5 from sulu/bugfix/api-creator-null
Browse files Browse the repository at this point in the history
Fixed task-api if creator is null
  • Loading branch information
danrot authored Feb 14, 2017
2 parents ec561b4 + ee2226f commit 26f89f8
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
14 changes: 12 additions & 2 deletions Entity/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,24 @@ public function setTaskId($taskId)
*/
public function getCreatorFullName()
{
return $this->getCreator()->getFullName();
$creator = $this->getCreator();
if (!$creator) {
return '';
}

return $creator->getFullName();
}

/**
* {@inheritdoc}
*/
public function getChangerFullName()
{
return $this->getChanger()->getFullName();
$changer = $this->getChanger();
if (!$changer) {
return '';
}

return $changer->getFullName();
}
}
25 changes: 25 additions & 0 deletions Tests/Functional/Controller/TaskControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 26f89f8

Please sign in to comment.