forked from mautic/mautic
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix:[DPMMA-2213] fix chart focus view statistics (mautic#13584)
* fix:[DPMMA-2213] fix focus views stats on the chart * fix:[DPMMA-2213] fix focus views stats on the chart - Functional UnitTest * feat:[DPMMA-2213] add unittest for FocusModel class getStats method when dates params are null * fix:[DPMMA-2213] remove testGetStatsWithNullDates. * Update plugins/MauticFocusBundle/Tests/Model/FocusModelFunctionalTest.php Co-authored-by: John Linhart <[email protected]> * Update - clear commet plugins/MauticFocusBundle/Tests/Model/FocusModelFunctionalTest.php Co-authored-by: John Linhart <[email protected]> --------- Co-authored-by: John Linhart <[email protected]>
- Loading branch information
1 parent
fade8e5
commit 27968c7
Showing
2 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
plugins/MauticFocusBundle/Tests/Model/FocusModelFunctionalTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MauticPlugin\MauticFocusBundle\Tests\Model; | ||
|
||
use Mautic\CoreBundle\Test\MauticMysqlTestCase; | ||
use Mautic\LeadBundle\Entity\Lead; | ||
use Mautic\PageBundle\Entity\Hit; | ||
use MauticPlugin\MauticFocusBundle\Entity\Focus; | ||
use MauticPlugin\MauticFocusBundle\Entity\Stat; | ||
use MauticPlugin\MauticFocusBundle\Model\FocusModel; | ||
|
||
class FocusModelFunctionalTest extends MauticMysqlTestCase | ||
{ | ||
private Lead $lead; | ||
|
||
private FocusModel $focusModel; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->focusModel = static::getContainer()->get('mautic.focus.model.focus'); | ||
$this->lead = $this->createLead(); | ||
} | ||
|
||
public function testGetStats(): void | ||
{ | ||
$focusPopupA = $this->createFocus('popup focus A'); | ||
$focusStatExpected = $this->setTestsData($this->lead, $focusPopupA); | ||
|
||
$to = new \DateTime('+1 day'); | ||
$from = new \DateTime('-1 month'); | ||
|
||
$focusStat = $this->focusModel->getStats($focusPopupA, null, $from, $to); | ||
|
||
$focusViewsCount = array_sum($focusStat['datasets'][0]['data']); | ||
$focusClickCount = array_sum($focusStat['datasets'][1]['data']); | ||
|
||
$this->assertEquals($focusStatExpected['view'], $focusViewsCount); | ||
$this->assertEquals($focusStatExpected['click'], $focusClickCount); | ||
} | ||
|
||
/** | ||
* @return array<string, int> | ||
*/ | ||
private function setTestsData(Lead $lead, Focus $focus): array | ||
{ | ||
$hitPopupA = new Hit(); | ||
$hitPopupA->setLead($lead); | ||
|
||
$this->focusModel->addStat($focus, Stat::TYPE_NOTIFICATION, null, $lead); | ||
$this->focusModel->addStat($focus, Stat::TYPE_CLICK, $hitPopupA, $lead); | ||
$this->focusModel->addStat($focus, Stat::TYPE_CLICK, $hitPopupA, $lead); | ||
$this->focusModel->addStat($focus, Stat::TYPE_CLICK, $hitPopupA, $lead); | ||
$this->focusModel->addStat($focus, Stat::TYPE_CLICK, $hitPopupA, $lead); | ||
|
||
return ['view' => 1, 'click' => 4]; | ||
} | ||
|
||
private function createFocus(string $name): Focus | ||
{ | ||
$focus = new Focus(); | ||
$focus->setName($name); | ||
$focus->setType('link'); | ||
$focus->setStyle('modal'); | ||
$focus->setProperties([ | ||
'bar' => [ | ||
'allow_hide' => 1, | ||
'push_page' => 1, | ||
'sticky' => 1, | ||
'size' => 'large', | ||
'placement' => 'top', | ||
], | ||
'modal' => [ | ||
'placement' => 'top', | ||
], | ||
'notification' => [ | ||
'placement' => 'top_left', | ||
], | ||
'page' => [], | ||
'animate' => 0, | ||
'link_activation' => 1, | ||
'colors' => [ | ||
'primary' => '4e5d9d', | ||
'text' => '000000', | ||
'button' => 'fdb933', | ||
'button_text' => 'ffffff', | ||
], | ||
'content' => [ | ||
'headline' => null, | ||
'tagline' => null, | ||
'link_text' => null, | ||
'link_url' => null, | ||
'link_new_window' => 1, | ||
'font' => 'Arial, Helvetica, sans-serif', | ||
'css' => null, | ||
], | ||
'when' => 'immediately', | ||
'timeout' => null, | ||
'frequency' => 'everypage', | ||
'stop_after_conversion' => 1, | ||
]); | ||
|
||
$this->focusModel->saveEntity($focus); | ||
|
||
return $focus; | ||
} | ||
|
||
private function createLead(): Lead | ||
{ | ||
$lead = new Lead(); | ||
$lead->setFirstname('Contact'); | ||
$lead->setEmail('[email protected]'); | ||
$this->em->persist($lead); | ||
$this->em->flush(); | ||
|
||
return $lead; | ||
} | ||
} |