Spaces:
Paused

matomo / plugins /CustomAlerts /tests /Fixtures /CustomAlerts.php
Leon4gr45's picture
Upload folder using huggingface_hub (part 15)
a7a7ba9 verified
Raw History Blame Contribute Delete
2.89 kB
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\CustomAlerts\tests\Fixtures;
use Piwik\Piwik;
use Piwik\Plugins\CustomAlerts\Model;
use Piwik\Tests\Framework\Fixture;
use Piwik\Plugins\Goals\API;
/**
* Tracks custom events
*/
class CustomAlerts extends Fixture
{
public $dateTime = '2010-01-03 11:22:33';
public $idSite = 1;
public function setUp(): void
{
$this->setUpWebsites();
$this->addAlerts();
}
private function setUpWebsites()
{
// tests run in UTC, the Tracker in UTC
if (!self::siteCreated($idSite = 1)) {
self::createWebsite($this->dateTime);
}
// tests run in UTC, the Tracker in UTC
if (!self::siteCreated($idSite = 2)) {
self::createWebsite($this->dateTime);
}
API::getInstance()->addGoal($idSite, 'Goal for idSite 2', 'title', 'normal title', 'exact', true, 50, true);
}
private function addAlerts()
{
$this->createAlert('Test Alert 1', 'day', array($this->idSite), 'nb_visits', 'VisitsSummary_get');
$this->createAlert('Test Alert 2', 'week', array($this->idSite), 'nb_uniq_visitors', 'Referrers_getSearchEngines');
$this->createAlert('Test Alert 3', 'month', array($this->idSite), 'nb_hits', 'Actions_getPageUrls');
// should not show up as different login
$this->createAlert('Test Alert 4', 'month', array($this->idSite), 'nb_hits', 'Actions_getPageUrls', 'loginnotmatching');
$this->triggerAlert(1, 10, 5, '2014-01-16 03:21:17');
$this->triggerAlert(1, 2999, 10, '2014-01-15 03:21:17');
$this->triggerAlert(2, 1004, 1, '2013-01-16 03:21:17');
$this->triggerAlert(2, 10, 5, '2013-10-16 03:21:17');
// should not show up as belongs to different login
$this->triggerAlert(4, 10, 5, '2013-10-16 03:21:17');
}
private function createAlert($name, $period, $idSites, $metric, $report, $login = false)
{
if (false === $login) {
$login = Piwik::getCurrentUserLogin();
}
$emails = array('test1@example.com', 'test2@example.com');
$phoneNumbers = array('0123456789');
$reportMatched = '';
if ('VisitsSummary_get' != $report) {
$reportMatched = 'Piwik';
}
$model = new Model();
$model->createAlert($name, $idSites, $login, $period, 0, $emails, $phoneNumbers, $metric, 'less_than', 5, $comparedTo = 1, $report, 'matches_exactly', $reportMatched, ['email', 'mobile'], '', '');
}
private function triggerAlert($idAlert, $valueNew, $valueOld, $datetime)
{
$model = new Model();
$model->triggerAlert($idAlert, $this->idSite, $valueNew, $valueOld, $datetime);
}
}