File size: 1,382 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
<?php

namespace Mautic\DashboardBundle\Tests\Entity;

use Mautic\CoreBundle\Security\Permissions\CorePermissions;
use Mautic\CoreBundle\Translation\Translator;
use Mautic\DashboardBundle\Entity\Widget;
use Mautic\DashboardBundle\Event\WidgetDetailEvent;
use PHPUnit\Framework\MockObject\MockObject;

class WidgetDetailEventTest extends \PHPUnit\Framework\TestCase
{
    private WidgetDetailEvent $widgetDetailEvent;
    private MockObject $translator;
    private MockObject $security;
    private MockObject $widget;

    protected function setUp(): void
    {
        parent::setUp();

        $this->translator            = $this->createMock(Translator::class);
        $this->security              = $this->createMock(CorePermissions::class);
        $this->widget                = $this->createMock(Widget::class);

        $this->widgetDetailEvent = new WidgetDetailEvent(
            $this->translator,
            $this->security,
            $this->widget
        );
    }

    public function testGetCacheKey(): void
    {
        $this->widget
            ->method('getParams')
            ->willReturn(['dateFrom' => [], 'dateTo' => []]);

        $this->translator->expects($this->once())
            ->method('getLocale')
            ->willReturn('en');
        $this->assertStringContainsString('dashboard.widget.', $this->widgetDetailEvent->getCacheKey());
    }
}