1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Mautic\EmailBundle\Tests\Helper; |
4
|
|
|
|
5
|
|
|
use Mautic\CoreBundle\Factory\MauticFactory; |
6
|
|
|
use Mautic\EmailBundle\Entity\Email; |
7
|
|
|
use Mautic\EmailBundle\Helper\PointEventHelper; |
8
|
|
|
use Mautic\EmailBundle\Model\EmailModel; |
9
|
|
|
use Mautic\LeadBundle\Entity\Lead; |
10
|
|
|
use Mautic\LeadBundle\Model\LeadModel; |
11
|
|
|
|
12
|
|
|
class PointEventHelperTest extends \PHPUnit\Framework\TestCase |
13
|
|
|
{ |
14
|
|
|
public function testSendEmail() |
15
|
|
|
{ |
16
|
|
|
$helper = new PointEventHelper(); |
17
|
|
|
$lead = new Lead(); |
18
|
|
|
$lead->setFields([ |
19
|
|
|
'core' => [ |
20
|
|
|
'email' => [ |
21
|
|
|
'value' => '[email protected]', |
22
|
|
|
], |
23
|
|
|
], |
24
|
|
|
]); |
25
|
|
|
$event = [ |
26
|
|
|
'id' => 1, |
27
|
|
|
'properties' => [ |
28
|
|
|
'email' => 1, |
29
|
|
|
], |
30
|
|
|
]; |
31
|
|
|
|
32
|
|
|
$result = $helper->sendEmail($event, $lead, $this->getMockMauticFactory()); |
33
|
|
|
$this->assertEquals(true, $result); |
34
|
|
|
|
35
|
|
|
$result = $helper->sendEmail($event, $lead, $this->getMockMauticFactory(false)); |
36
|
|
|
$this->assertEquals(false, $result); |
37
|
|
|
|
38
|
|
|
$result = $helper->sendEmail($event, $lead, $this->getMockMauticFactory(true, false)); |
39
|
|
|
$this->assertEquals(false, $result); |
40
|
|
|
|
41
|
|
|
$result = $helper->sendEmail($event, new Lead(), $this->getMockMauticFactory(true, false)); |
42
|
|
|
$this->assertEquals(false, $result); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param bool $published |
47
|
|
|
* @param bool $success |
48
|
|
|
* |
49
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject |
50
|
|
|
*/ |
51
|
|
|
private function getMockMauticFactory($published = true, $success = true) |
52
|
|
|
{ |
53
|
|
|
$mock = $this->getMockBuilder(MauticFactory::class) |
|
|
|
|
54
|
|
|
->disableOriginalConstructor() |
55
|
|
|
->setMethods(['getModel']) |
56
|
|
|
->getMock() |
57
|
|
|
; |
58
|
|
|
|
59
|
|
|
$mock->expects($this->any()) |
60
|
|
|
->method('getModel') |
61
|
|
|
->willReturnCallback(function ($model) use ($published, $success) { |
62
|
|
|
switch ($model) { |
63
|
|
|
case 'email': |
64
|
|
|
return $this->getMockEmail($published, $success); |
65
|
|
|
case 'lead': |
66
|
|
|
return $this->getMockLead(); |
67
|
|
|
} |
68
|
|
|
}); |
69
|
|
|
|
70
|
|
|
return $mock; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject |
75
|
|
|
*/ |
76
|
|
|
private function getMockLead() |
77
|
|
|
{ |
78
|
|
|
$mock = $this->getMockBuilder(LeadModel::class) |
79
|
|
|
->disableOriginalConstructor() |
80
|
|
|
->getMock() |
81
|
|
|
; |
82
|
|
|
|
83
|
|
|
return $mock; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @param bool $published |
88
|
|
|
* @param bool $success |
89
|
|
|
* |
90
|
|
|
* @return \PHPUnit\Framework\MockObject\MockObject |
91
|
|
|
*/ |
92
|
|
|
private function getMockEmail($published = true, $success = true) |
93
|
|
|
{ |
94
|
|
|
$sendEmail = $success ? true : ['error' => 1]; |
95
|
|
|
|
96
|
|
|
$mock = $this->getMockBuilder(EmailModel::class) |
|
|
|
|
97
|
|
|
->disableOriginalConstructor() |
98
|
|
|
->setMethods(['getEntity', 'sendEmail']) |
99
|
|
|
->getMock() |
100
|
|
|
; |
101
|
|
|
|
102
|
|
|
$mock->expects($this->any()) |
103
|
|
|
->method('getEntity') |
104
|
|
|
->willReturnCallback(function ($id) use ($published) { |
|
|
|
|
105
|
|
|
$email = new Email(); |
106
|
|
|
$email->setIsPublished($published); |
107
|
|
|
|
108
|
|
|
return $email; |
109
|
|
|
}); |
110
|
|
|
|
111
|
|
|
$mock->expects($this->any()) |
112
|
|
|
->method('sendEmail') |
113
|
|
|
->willReturn($sendEmail); |
114
|
|
|
|
115
|
|
|
return $mock; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.