File size: 3,191 Bytes
d2897cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php

declare(strict_types=1);

namespace MauticPlugin\MauticFocusBundle\Tests\Model;

use Doctrine\ORM\EntityManagerInterface;
use Mautic\CoreBundle\Helper\CoreParametersHelper;
use Mautic\CoreBundle\Helper\UserHelper;
use Mautic\CoreBundle\Security\Permissions\CorePermissions;
use Mautic\CoreBundle\Translation\Translator;
use Mautic\FormBundle\Model\FormModel;
use Mautic\LeadBundle\Model\FieldModel;
use Mautic\LeadBundle\Tracker\ContactTracker;
use Mautic\PageBundle\Model\TrackableModel;
use MauticPlugin\MauticFocusBundle\Model\FocusModel;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\MockObject\Rule\InvokedCount;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Twig\Environment;

class FocusModelTest extends TestCase
{
    /**
     * @var ContactTracker|MockObject
     */
    private MockObject $contactTracker;

    /**
     * @var MockObject|EventDispatcherInterface
     */
    private MockObject $dispatcher;

    /**
     * @var FormModel|MockObject
     */
    private MockObject $formModel;

    /**
     * @var FieldModel|MockObject
     */
    private MockObject $leadFieldModel;

    /**
     * @var Environment|mixed|MockObject
     */
    private MockObject $twig;

    /**
     * @var TrackableModel|mixed|MockObject
     */
    private MockObject $trackableModel;

    protected function setUp(): void
    {
        $this->formModel      = $this->createMock(FormModel::class);
        $this->trackableModel = $this->createMock(TrackableModel::class);
        $this->twig           = $this->createMock(Environment::class);
        $this->dispatcher     = $this->createMock(EventDispatcherInterface::class);
        $this->leadFieldModel = $this->createMock(FieldModel::class);
        $this->contactTracker = $this->createMock(ContactTracker::class);
        parent::setUp();
    }

    /**
     * @dataProvider focusTypeProvider
     */
    public function testGetContentWithForm(string $type, InvokedCount $count): void
    {
        $this->formModel->expects(self::once())->method('getPages')->willReturn(['', '']);

        $this->formModel->expects($count)->method('getEntity');

        $focusModel = new FocusModel(
            $this->formModel,
            $this->trackableModel,
            $this->twig,
            $this->leadFieldModel,
            $this->contactTracker,
            $this->createMock(EntityManagerInterface::class),
            $this->createMock(CorePermissions::class),
            $this->dispatcher,
            $this->createMock(UrlGeneratorInterface::class),
            $this->createMock(Translator::class),
            $this->createMock(UserHelper::class),
            $this->createMock(LoggerInterface::class),
            $this->createMock(CoreParametersHelper::class)
        );
        $focus = [
            'form' => 'xxx',
            'type' => $type,
        ];

        $focusModel->getContent($focus);
    }

    public function focusTypeProvider(): \Generator
    {
        yield ['form', self::once()];
        yield ['notice', self::never()];
    }
}