Skip to content
This repository has been archived by the owner on Apr 11, 2018. It is now read-only.

Commit

Permalink
Merge branch 'APOLLO-3179' of https://github.com/ministryofjustice/op…
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyquinton committed Jul 24, 2014
2 parents 40f4017 + 44373c3 commit 3d15b16
Show file tree
Hide file tree
Showing 15 changed files with 89 additions and 68 deletions.
2 changes: 2 additions & 0 deletions src/Opg/Core/Model/Entity/Assignable/AssignableComposite.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Opg\Core\Model\Entity\PowerOfAttorney\PowerOfAttorney as PowerOfAttorneyEntity;
use JMS\Serializer\Annotation\Groups;
use JMS\Serializer\Annotation\Exclude;
use JMS\Serializer\Annotation\Type;
use JMS\Serializer\Annotation\ReadOnly;
use JMS\Serializer\Annotation\Accessor;

Expand All @@ -26,6 +27,7 @@
* @ORM\DiscriminatorMap({
* "assignee_user" = "Opg\Core\Model\Entity\User\User",
* "assignee_team" = "Opg\Core\Model\Entity\Assignable\Team",
* "assignee_null" = "Opg\Core\Model\Entity\Assignable\NullEntity"
* })
*
* Class Composite
Expand Down
10 changes: 9 additions & 1 deletion src/Opg/Core/Model/Entity/Assignable/NullEntity.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,26 @@
use Opg\Common\Model\Entity\Traits\ToArray;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;
use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
*
* Class NullEntity
* @package Opg\Core\Model\Entity\Assignable
*/
class NullEntity extends AssignableComposite implements EntityInterface, IsAssignee
{

const NULL_USER_ID = -1;
const NULL_USER_ID = null;

const NULL_USER_NAME = 'Unassigned';

public function __construct()
{
$this->name = self::NULL_USER_NAME;
$this->id = self::NULL_USER_ID;
}
/**
* @param int $id
* @return $this
Expand Down
1 change: 1 addition & 0 deletions src/Opg/Core/Model/Entity/CaseItem/CaseItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ abstract class CaseItem implements EntityInterface, \IteratorAggregate, CaseItem
protected $status;

/**
* @ORM\ManyToOne(cascade={"persist"}, targetEntity = "Opg\Core\Model\Entity\Assignable\AssignableComposite", fetch = "EAGER")
* @Serializer\MaxDepth(1)
* @var AssignableComposite
* @Type("Opg\Core\Model\Entity\Assignable\AssignableComposite")
Expand Down
6 changes: 1 addition & 5 deletions src/Opg/Core/Model/Entity/CaseItem/Document/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -307,11 +307,7 @@ public function getCreatedDate()
*/
public function getCreatedDateString()
{
if (null !== $this->createdDate) {
return $this->createdDate->format(OPGDateFormat::getDateTimeFormat());
}

return '';
return $this->createdDate->format(OPGDateFormat::getDateTimeFormat());
}

/**
Expand Down
26 changes: 5 additions & 21 deletions src/Opg/Core/Model/Entity/CaseItem/Lpa/Lpa.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,7 @@ public function setLpaDonorSignatureDateString($signatureDate)
{
if (!empty($signatureDate)) {
$signatureDate = OPGDateFormat::createDateTime($signatureDate);

if ($signatureDate) {
$this->setLpaDonorSignatureDate($signatureDate);
}
$this->setLpaDonorSignatureDate($signatureDate);
}

return $this;
Expand Down Expand Up @@ -257,10 +254,7 @@ public function setDonorDeclarationSignatureDateString($signatureDate)
{
if (!empty($signatureDate)) {
$signatureDate = OPGDateFormat::createDateTime($signatureDate);

if ($signatureDate) {
$this->setDonorDeclarationSignatureDate($signatureDate);
}
$this->setDonorDeclarationSignatureDate($signatureDate);
}

return $this;
Expand Down Expand Up @@ -418,11 +412,7 @@ public function setLpaCreatedDateString($lpaCreatedDate)
{
if (!empty($lpaCreatedDate)) {
$lpaCreatedDate = OPGDateFormat::createDateTime($lpaCreatedDate);

if ($lpaCreatedDate) {
return $this->setLpaCreatedDate($lpaCreatedDate);
}

return $this->setLpaCreatedDate($lpaCreatedDate);
}

return $this->setLpaCreatedDate(new \DateTime());
Expand Down Expand Up @@ -472,10 +462,7 @@ public function setLpaReceiptDateString($lpaReceiptDate)
{
if (!empty($lpaReceiptDate)) {
$lpaReceiptDate = OPGDateFormat::createDateTime($lpaReceiptDate);

if ($lpaReceiptDate) {
return $this->setLpaReceiptDate($lpaReceiptDate);
}
return $this->setLpaReceiptDate($lpaReceiptDate);
}

return $this->setLpaReceiptDate(new \DateTime($lpaReceiptDate));
Expand Down Expand Up @@ -556,10 +543,7 @@ public function setLifeSustainingTreatmentSignatureDateString($lifeSustainingTre
$lifeSustainingTreatmentSignatureDate = OPGDateFormat::createDateTime(
$lifeSustainingTreatmentSignatureDate
);

if ($lifeSustainingTreatmentSignatureDate) {
$this->setLifeSustainingTreatmentSignatureDate($lifeSustainingTreatmentSignatureDate);
}
return $this->setLifeSustainingTreatmentSignatureDate($lifeSustainingTreatmentSignatureDate);
}

return $this;
Expand Down
8 changes: 2 additions & 6 deletions src/Opg/Core/Model/Entity/CaseItem/Lpa/Party/Attorney.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ public function setLpa002SignatureDateString($lpa002SignatureDate)
{
if (!empty($lpa002SignatureDate)) {
$result = OPGDateFormat::createDateTime($lpa002SignatureDate);
if ($result) {
return $this->setLpa002SignatureDate($result);
}
return $this->setLpa002SignatureDate($result);
}

return $this;
Expand Down Expand Up @@ -183,9 +181,7 @@ public function setLpaPartCSignatureDateString($lpaPartCSignatureDate)
{
if (!empty($lpaPartCSignatureDate)) {
$result = OPGDateFormat::createDateTime($lpaPartCSignatureDate);
if ($result) {
return $this->setLpaPartCSignatureDate($result);
}
return $this->setLpaPartCSignatureDate($result);
}

return $this;
Expand Down
15 changes: 7 additions & 8 deletions src/Opg/Core/Model/Entity/CaseItem/Task/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ class Task implements EntityInterface, \IteratorAggregate, HasRagRating, IsAssig
protected $systemType;

/**
* @ORM\ManyToOne(
* cascade={"persist"},
* targetEntity = "Opg\Core\Model\Entity\Assignable\AssignableComposite",
* fetch = "EAGER"
* )
* @Serializer\MaxDepth(2)
* @Type("Opg\Core\Model\Entity\Assignable\AssignableComposite")
* @var User
Expand Down Expand Up @@ -245,10 +250,7 @@ public function setActiveDateString($activeDate)
{
if (!empty($activeDate)) {
$activeDate = OPGDateFormat::createDateTime($activeDate . ' 00:00:00');

if ($activeDate) {
return $this->setActiveDate($activeDate);
}
return $this->setActiveDate($activeDate);
}

return $this->setActiveDate();
Expand Down Expand Up @@ -626,10 +628,7 @@ public function setCompletedDateString($completedDate)
{
if (!empty($completedDate)) {
$completedDate = OPGDateFormat::createDateTime($completedDate);

if ($completedDate) {
return $this->setCompletedDate($completedDate);
}
return $this->setCompletedDate($completedDate);
}
return $this->setCompletedDate(new \DateTime());
}
Expand Down
12 changes: 2 additions & 10 deletions src/Opg/Core/Model/Entity/Correspondence/Correspondence.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,11 +309,7 @@ public function setCreatedDateString($createdDate)
{
if (!empty($createdDate)) {
$createdDate = OPGDateFormat::createDateTime($createdDate);

if ($createdDate) {
return $this->setCreatedDate($createdDate);
}

return $this->setCreatedDate($createdDate);
}

return $this->setCreatedDate(new \DateTime());
Expand All @@ -332,11 +328,7 @@ public function getCreatedDate()
*/
public function getCreatedDateString()
{
if (!empty($this->createdDate)) {
return $this->createdDate->format(OPGDateFormat::getDateTimeFormat());
}

return '';
return $this->createdDate->format(OPGDateFormat::getDateTimeFormat());
}

}
5 changes: 1 addition & 4 deletions src/Opg/Core/Model/Entity/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public function getOwningEntityClass()

/**
* @param \DateTime $createdOn
*
* @return Event
*/
public function setCreatedOn(\DateTime $createdOn = null)
Expand All @@ -128,9 +127,7 @@ public function setCreatedOnString($createdOn)
{
if (!empty($createdOn)) {
$result = OPGDateFormat::createDateTime($createdOn);
if ($result) {
return $this->setCreatedOn($result);
}
return $this->setCreatedOn($result);
}

return $this;
Expand Down
11 changes: 2 additions & 9 deletions src/Opg/Core/Model/Entity/Person/Person.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,7 @@ public function setDobString($dob)
{
if (!empty($dob)) {
$result = OPGDateFormat::createDateTime($dob);
if ($result) {
return $this->setDob($result);
}
return $this->setDob($result);
}

return $this;
Expand Down Expand Up @@ -458,13 +456,8 @@ public function setDateOfDeath(\DateTime $dateOfDeath = null)
public function setDateOfDeathString($dateOfDeath)
{
if (!empty($dateOfDeath)) {

$result = OPGDateFormat::createDateTime($dateOfDeath);

if ($result) {
return $this->setDateOfDeath($result);
}

return $this->setDateOfDeath($result);
}

return $this;
Expand Down
8 changes: 8 additions & 0 deletions tests/OpgTest/Core/Model/Entity/CaseItem/BusinessRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Opg\Core\Model\Entity\CaseItem\BusinessRule;
use Opg\Core\Model\Entity\CaseItem\Lpa\Lpa;
use Zend\InputFilter\InputFilter;


/**
Expand Down Expand Up @@ -68,4 +69,11 @@ public function testSetGetDatetime()

$this->assertEquals($now, $businessRuleMock->getCreatedOn());
}

public function testGetInputFilter()
{
$businessRuleMock = $this->getMockedClass();

$this->assertTrue($businessRuleMock->getInputFilter() instanceof InputFilter);
}
}
31 changes: 29 additions & 2 deletions tests/OpgTest/Core/Model/Entity/CaseItem/CaseItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,41 @@
namespace OpgTest\Core\Model\Entity\CaseItem;

use Doctrine\Common\Collections\ArrayCollection;
use Opg\Core\Model\Entity\CaseItem\CaseItem;
use Opg\Core\Model\Entity\CaseItem\Document\Document;
use Opg\Core\Model\Entity\CaseItem\Lpa\Lpa;
use Opg\Core\Model\Entity\CaseItem\Note\Note;
use Opg\Core\Model\Entity\CaseItem\Task\Task;
use Opg\Core\Model\Entity\Person\Person;
use Opg\Core\Model\Entity\User\User;
use Opg\Common\Model\Entity\DateFormat as OPGDateFormat;
use Opg\Core\Model\Entity\CaseItem\BusinessRule;

/**
* ToArray test case.
*/

class CaseItemStub extends CaseItem
{

public function __unset($key)
{
if ($key === 'tasks') {
$this->tasks = null;
}
}

/**
* @param Person $person
*
* @return CaseItem
*/
public function addPerson(Person $person)
{
// TODO: Implement addPerson() method.
}
}

class CaseItemTest extends \PHPUnit_Framework_TestCase
{

Expand Down Expand Up @@ -97,8 +121,9 @@ public function testSetGetAssignee()

$user = new User();
$user->setFirstname($name)->setSurname($secondName);

$this->assertFalse($caseItemMock->isAssigned());
$caseItemMock->assign($user);
$this->assertTrue($caseItemMock->isAssigned());

$this->assertEquals($name, $caseItemMock->getAssignee()->getFirstName());
}
Expand Down Expand Up @@ -134,8 +159,10 @@ public function testSetGetNotes()

public function testSetGetTasks()
{
$caseItemMock = $this->getMockedClass();
$caseItemMock = new CaseItemStub();

unset($caseItemMock->{'tasks'});

for ($i = 0; $i < 10; $i++) {
$task = new Task();
$task->setId($i);
Expand Down
4 changes: 4 additions & 0 deletions tests/OpgTest/Core/Model/Entity/CaseItem/Lpa/LpaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,10 @@ public function testGetSetTrustCorporationSignedAs()
$this->lpa->setTrustCorporationSignedAs($expected);

$this->assertEquals($expected, $this->lpa->getTrustCorporationSignedAs());

$this->lpa->setTrustCorporationSignedAs('We');

$this->assertNotEquals($expected, $this->lpa->getTrustCorporationSignedAs());
}

public function testGetRagRatingRed()
Expand Down
6 changes: 4 additions & 2 deletions tests/OpgTest/Core/Model/Entity/CaseItem/Task/TaskTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,12 +312,14 @@ public function testSetGetAssignedUser()
$user = new User();
$user->setSurname($name);

$this->task->setAssignedUser($user);
$this->assertFalse($this->task->isAssigned());
$this->task->assign($user);

$this->assertEquals(
$name,
$this->task->getAssignedUser()->getSurname()
$this->task->getAssignee()->getSurname()
);
$this->assertTrue($this->task->isAssigned());
}

public function testUnnasignUser()
Expand Down
12 changes: 12 additions & 0 deletions tests/OpgTest/Core/Model/Entity/User/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,4 +336,16 @@ public function testDefaultRoleRequirementsPassCOP() {
$this->user->addRole('COP User');
$this->assertTrue($this->user->isValid(array('roles')));
}

public function testGetDisplayName()
{
$firstName = 'Test';
$surname = 'User';

$expected = sprintf('%s %s', $firstName, $surname);

$this->user->setFirstname($firstName)->setSurname($surname);

$this->assertEquals($expected, $this->user->getDisplayName());
}
}

0 comments on commit 3d15b16

Please sign in to comment.