1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OroCRM\Bundle\AccountBundle\Tests\Unit\Entity; |
4
|
|
|
|
5
|
|
|
use OroCRM\Bundle\AccountBundle\Entity\Account; |
6
|
|
|
use OroCRM\Bundle\ContactBundle\Entity\Contact; |
7
|
|
|
|
8
|
|
|
use Oro\Bundle\UserBundle\Entity\User; |
9
|
|
|
use Oro\Bundle\OrganizationBundle\Entity\Organization; |
10
|
|
|
|
11
|
|
|
class AccountTest extends \PHPUnit_Framework_TestCase |
12
|
|
|
{ |
13
|
|
|
public function testGettersSetters() |
14
|
|
|
{ |
15
|
|
|
$entity = new Account(); |
16
|
|
|
$entity->setName('Test'); |
17
|
|
|
|
18
|
|
|
$this->assertEquals('Test', $entity->getName()); |
19
|
|
|
$this->assertEquals('Test', (string)$entity); |
20
|
|
|
|
21
|
|
|
$organization = new Organization(); |
22
|
|
|
$this->assertNull($entity->getOrganization()); |
23
|
|
|
$entity->setOrganization($organization); |
24
|
|
|
$this->assertSame($organization, $entity->getOrganization()); |
25
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testBeforeSave() |
29
|
|
|
{ |
30
|
|
|
$entity = new Account(); |
31
|
|
|
$entity->beforeSave(); |
32
|
|
|
$this->assertInstanceOf('\DateTime', $entity->getCreatedAt()); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function testDoPreUpdate() |
36
|
|
|
{ |
37
|
|
|
$entity = new Account(); |
38
|
|
|
$entity->doPreUpdate(); |
39
|
|
|
$this->assertInstanceOf('\DateTime', $entity->getUpdatedAt()); |
40
|
|
|
} |
41
|
|
|
|
42
|
|
View Code Duplication |
public function testAddContact() |
|
|
|
|
43
|
|
|
{ |
44
|
|
|
$account = new Account(); |
45
|
|
|
$account->setId(1); |
46
|
|
|
|
47
|
|
|
$contact = new Contact(); |
48
|
|
|
$contact->setId(2); |
49
|
|
|
|
50
|
|
|
$this->assertEmpty($account->getContacts()->toArray()); |
51
|
|
|
|
52
|
|
|
$account->addContact($contact); |
53
|
|
|
$actualContacts = $account->getContacts()->toArray(); |
54
|
|
|
$this->assertCount(1, $actualContacts); |
55
|
|
|
$this->assertEquals($contact, current($actualContacts)); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
View Code Duplication |
public function testRemoveContact() |
|
|
|
|
59
|
|
|
{ |
60
|
|
|
$account = new Account(); |
61
|
|
|
$account->setId(1); |
62
|
|
|
|
63
|
|
|
$contact = new Contact(); |
64
|
|
|
$contact->setId(2); |
65
|
|
|
|
66
|
|
|
$account->addContact($contact); |
67
|
|
|
$this->assertCount(1, $account->getContacts()->toArray()); |
68
|
|
|
|
69
|
|
|
$account->removeContact($contact); |
70
|
|
|
$this->assertEmpty($account->getContacts()->toArray()); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
View Code Duplication |
public function testOwners() |
|
|
|
|
74
|
|
|
{ |
75
|
|
|
$entity = new Account(); |
76
|
|
|
$user = new User(); |
77
|
|
|
|
78
|
|
|
$this->assertEmpty($entity->getOwner()); |
79
|
|
|
|
80
|
|
|
$entity->setOwner($user); |
81
|
|
|
|
82
|
|
|
$this->assertEquals($user, $entity->getOwner()); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function testGetEmail() |
86
|
|
|
{ |
87
|
|
|
$account = new Account(); |
88
|
|
|
$contact = $this->getMockBuilder('OroCRM\Bundle\ContactBundle\Entity\Contact') |
89
|
|
|
->disableOriginalConstructor() |
90
|
|
|
->getMock(); |
91
|
|
|
|
92
|
|
|
$this->assertNull($account->getEmail()); |
93
|
|
|
|
94
|
|
|
$account->setDefaultContact($contact); |
95
|
|
|
$contact->expects($this->once()) |
96
|
|
|
->method('getEmail') |
97
|
|
|
->will($this->returnValue('[email protected]')); |
98
|
|
|
$this->assertEquals('[email protected]', $account->getEmail()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
public function testSetDefaultContact() |
102
|
|
|
{ |
103
|
|
|
$account = new Account(); |
104
|
|
|
$this->assertNull($account->getDefaultContact()); |
105
|
|
|
|
106
|
|
|
$contact = new Contact(); |
107
|
|
|
$account->setDefaultContact($contact); |
108
|
|
|
$this->assertSame($contact, $account->getDefaultContact()); |
109
|
|
|
$this->assertCount(1, $contact->getDefaultInAccounts()); |
110
|
|
|
$this->assertSame($account, $contact->getDefaultInAccounts()->first()); |
111
|
|
|
|
112
|
|
|
$contact2 = new Contact(); |
113
|
|
|
$account->setDefaultContact($contact2); |
114
|
|
|
$this->assertCount(0, $contact->getDefaultInAccounts()); |
115
|
|
|
$this->assertCount(1, $contact2->getDefaultInAccounts()); |
116
|
|
|
$this->assertSame($contact2, $account->getDefaultContact()); |
117
|
|
|
$this->assertSame($account, $contact2->getDefaultInAccounts()->first()); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.