Skip to content

Commit

Permalink
Merge pull request #12541 from mollux/11256-for-4.4
Browse files Browse the repository at this point in the history
re-add missing commit to fix incorrect reporting dates
  • Loading branch information
escopecz committed Jul 10, 2023
2 parents 8e728f2 + bc10586 commit 5c4a0ff
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 10 deletions.
71 changes: 71 additions & 0 deletions app/bundles/ReportBundle/Tests/Unit/Model/ReportModelTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

declare(strict_types=1);

namespace Mautic\ReportBundle\Tests\Unit\Model;

use Mautic\CoreBundle\Entity\IpAddress;
use Mautic\CoreBundle\Test\MauticMysqlTestCase;
use Mautic\FormBundle\Entity\Form;
use Mautic\FormBundle\Entity\Submission;
use Mautic\ReportBundle\Entity\Report;
use Mautic\ReportBundle\Model\ReportModel;
use PHPUnit\Framework\Assert;

final class ReportModelTest extends MauticMysqlTestCase
{
public function testThatGetReportDataUsesCorrectDataRange(): void
{
$report = new Report();
$report->setName('Test Report');
$report->setSource('form.submissions');
$report->setColumns(['fs.date_submitted']);
$report->setSettings([]);

$form = new Form();
$form->setName('Test Form');
$form->setAlias('create_a_c');

$ip = new IpAddress('127.0.0.1');

$this->em->persist($ip);
$this->em->persist($report);
$this->em->persist($form);
$this->em->flush();

// I know I can use \DateTimeImmutable, but getReportData expects \DateTime
$now = new \DateTime('now', new \DateTimeZone('UTC'));
$aDayAgo = (clone $now)->modify('-1 day');
$twoDaysAgo = (clone $now)->modify('-2 days');

$this->em->persist($this->makeSubmission($form, $ip, $twoDaysAgo));
$this->em->persist($this->makeSubmission($form, $ip, $aDayAgo));
$this->em->persist($this->makeSubmission($form, $ip, $now));

$this->em->flush();

$reportModel = self::$container->get('mautic.report.model.report');
\assert($reportModel instanceof ReportModel);

$aDayAgoBeginningOfTheDay = (clone $aDayAgo)->setTime(0, 0, 0);

$reportData = $reportModel->getReportData($report, null, [
'dateFrom' => $aDayAgoBeginningOfTheDay,
'dateTo' => clone $aDayAgoBeginningOfTheDay,
]);

Assert::assertSame(1, $reportData['totalResults']);
Assert::assertCount(1, $reportData['data']);
}

private function makeSubmission(Form $form, IpAddress $ipAddress, \DateTime $dateSubmitted): Submission
{
$submission = new Submission();
$submission->setForm($form);
$submission->setIpAddress($ipAddress);
$submission->setDateSubmitted($dateSubmitted);
$submission->setReferer('');

return $submission;
}
}
22 changes: 12 additions & 10 deletions app/bundles/ReportBundle/Views/Report/details_data.html.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,18 @@ function getTotal($a, $f, $t, $allrows, $ac)
}
?>
<?php
switch ($cellType) {
case 'datetime':
echo $view['date']->toFullConcat($cellVal, 'UTC');
break;
case 'date':
echo $view['date']->toShort($cellVal, 'UTC');
break;
default:
echo $view['formatter']->_($cellVal, $cellType);
break;
if ('' !== $cellVal && !is_null($cellVal)) {
switch ($cellType) {
case 'datetime':
echo $view['date']->toFullConcat($cellVal, 'UTC');
break;
case 'date':
echo $view['date']->toShort($cellVal, 'UTC');
break;
default:
echo $view['formatter']->_($cellVal, $cellType);
break;
}
}
?>
<?php if ($closeLink): ?></a><?php endif; ?>
Expand Down

0 comments on commit 5c4a0ff

Please sign in to comment.