1 | <?php |
||||||
2 | |||||||
3 | namespace Mautic\LeadBundle\Tests\Helper; |
||||||
4 | |||||||
5 | use Mautic\CoreBundle\Helper\PathsHelper; |
||||||
6 | use Mautic\CoreBundle\Templating\Helper\AssetsHelper; |
||||||
7 | use Mautic\CoreBundle\Templating\Helper\GravatarHelper; |
||||||
8 | use Mautic\LeadBundle\Entity\Lead; |
||||||
9 | use Mautic\LeadBundle\Templating\Helper\AvatarHelper; |
||||||
10 | use Mautic\LeadBundle\Templating\Helper\DefaultAvatarHelper; |
||||||
11 | |||||||
12 | class AvatarHelperTest extends \PHPUnit\Framework\TestCase |
||||||
13 | { |
||||||
14 | /** |
||||||
15 | * @var \PHPUnit\Framework\MockObject\MockObject|AssetsHelper |
||||||
16 | */ |
||||||
17 | private $assetsHelperMock; |
||||||
18 | |||||||
19 | /** |
||||||
20 | * @var \PHPUnit\Framework\MockObject\MockObject|PathsHelper |
||||||
21 | */ |
||||||
22 | private $pathsHelperMock; |
||||||
23 | |||||||
24 | /** |
||||||
25 | * @var \PHPUnit\Framework\MockObject\MockObject|GravatarHelper |
||||||
26 | */ |
||||||
27 | private $gravatarHelperMock; |
||||||
28 | |||||||
29 | /** |
||||||
30 | * @var \PHPUnit\Framework\MockObject\MockObject|DefaultAvatarHelper |
||||||
31 | */ |
||||||
32 | private $defaultAvatarHelperMock; |
||||||
33 | |||||||
34 | /** |
||||||
35 | * @var \PHPUnit\Framework\MockObject\MockObject|Lead |
||||||
36 | */ |
||||||
37 | private $leadMock; |
||||||
38 | |||||||
39 | /** |
||||||
40 | * @var \PHPUnit\Framework\MockObject\MockObject|AvatarHelper |
||||||
41 | */ |
||||||
42 | private $avatarHelper; |
||||||
43 | |||||||
44 | protected function setUp(): void |
||||||
45 | { |
||||||
46 | $this->assetsHelperMock = $this->createMock(AssetsHelper::class); |
||||||
47 | $this->pathsHelperMock = $this->createMock(PathsHelper::class); |
||||||
48 | $this->gravatarHelperMock = $this->createMock(GravatarHelper::class); |
||||||
49 | $this->defaultAvatarHelperMock = $this->createMock(DefaultAvatarHelper::class); |
||||||
50 | $this->leadMock = $this->createMock(Lead::class); |
||||||
51 | $this->avatarHelper = new AvatarHelper($this->assetsHelperMock, $this->pathsHelperMock, $this->gravatarHelperMock, $this->defaultAvatarHelperMock); |
||||||
52 | } |
||||||
53 | |||||||
54 | /** |
||||||
55 | * Test to get gravatar. |
||||||
56 | */ |
||||||
57 | public function testGetAvatarWhenGravatar() |
||||||
58 | { |
||||||
59 | $this->leadMock->method('getPreferredProfileImage') |
||||||
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
60 | ->willReturn('gravatar'); |
||||||
61 | $this->leadMock->method('getSocialCache') |
||||||
62 | ->willReturn([]); |
||||||
63 | $this->leadMock->method('getEmail') |
||||||
64 | ->willReturn('[email protected]'); |
||||||
65 | $this->gravatarHelperMock->method('getImage') |
||||||
0 ignored issues
–
show
The method
method() does not exist on Mautic\CoreBundle\Templating\Helper\GravatarHelper .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
66 | ->with('[email protected]') |
||||||
67 | ->willReturn('gravatarImage'); |
||||||
68 | $avatar = $this->avatarHelper->getAvatar($this->leadMock); |
||||||
69 | $this->assertSame('gravatarImage', $avatar, 'Gravatar image should be returned'); |
||||||
70 | } |
||||||
71 | |||||||
72 | /** |
||||||
73 | * Test to get default image. |
||||||
74 | */ |
||||||
75 | public function testGetAvatarWhenDefault() |
||||||
76 | { |
||||||
77 | $this->leadMock->method('getPreferredProfileImage') |
||||||
78 | ->willReturn('gravatar'); |
||||||
79 | $this->leadMock->method('getSocialCache') |
||||||
80 | ->willReturn([]); |
||||||
81 | $this->leadMock->method('getEmail') |
||||||
82 | ->willReturn(''); |
||||||
83 | $this->defaultAvatarHelperMock->method('getDefaultAvatar') |
||||||
0 ignored issues
–
show
The method
method() does not exist on Mautic\LeadBundle\Templa...per\DefaultAvatarHelper .
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed.
Loading history...
|
|||||||
84 | ->willReturn('defaultImage'); |
||||||
85 | $avatar = $this->avatarHelper->getAvatar($this->leadMock); |
||||||
86 | $this->assertSame('defaultImage', $avatar, 'Default image image should be returned'); |
||||||
87 | } |
||||||
88 | } |
||||||
89 |