-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathCustomAlertsApiTest.php
More file actions
139 lines (122 loc) · 4.28 KB
/
CustomAlertsApiTest.php
File metadata and controls
139 lines (122 loc) · 4.28 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\MicrosoftTeams\tests;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Tests\Framework\TestingEnvironmentManipulator;
use Piwik\Plugins\CustomAlerts\API;
/**
* @group MicrosoftTeams
* @group CustomAlertsApiTest
* @group Plugins
*/
class CustomAlertsApiTest extends IntegrationTestCase
{
/**
* @var \Piwik\Plugins\CustomAlerts\API
*/
protected $api;
protected $idSite;
public function setUp(): void
{
self::$fixture->extraPluginsToLoad = array('CustomAlerts');
TestingEnvironmentManipulator::$extraPluginsToLoad = self::$fixture->extraPluginsToLoad;
parent::setUp();
$pluginManager = \Piwik\Plugin\Manager::getInstance();
$pluginManager->loadPlugin('CustomAlerts');
$pluginManager->installLoadedPlugins();
$pluginManager->activatePlugin('CustomAlerts');
$this->api = API::getInstance();
$this->idSite = Fixture::createWebsite('2012-08-09 11:22:33');
}
public function testAddAlertShouldThrowExceptionIfSMicrosoftTeamsWebhookUrlEmpty()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('MicrosoftTeams_IncomingWebhookRequiredErrorMessage');
$this->addAlert('');
}
public function testAddAlertShouldThrowExceptionIfInvalidMicrosoftTeamsWebhookUrl()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('MicrosoftTeams_IncomingWebhookInvalidErrorMessage');
$this->addAlert('webhookURL');
}
public function testAddAlertSuccess()
{
$id = $this->addAlert($msTeamsWebhookUrl = 'https://webhook.microsft.com/webhook');
$this->assertEquals(1, $id);
$alert = $this->api->getAlert($id);
$this->assertEquals(['email','teams'], $alert['report_mediums']);
$this->assertEquals($msTeamsWebhookUrl, $alert['ms_teams_webhook_url']);
}
public function testUpdateAlertShouldThrowExceptionIfEmptyMicrosoftTeamsWebhookUrl()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('MicrosoftTeams_IncomingWebhookRequiredErrorMessage');
$idAlert = $this->addAlert('https://webhook.microsft.com/webhook');
$this->updateAlert($idAlert);
}
public function testUpdateAlertShouldThrowExceptionIfInvalidMicrosoftTeamsWebhookUrl()
{
$this->expectException(\Exception::class);
$this->expectExceptionMessage('MicrosoftTeams_IncomingWebhookInvalidErrorMessage');
$idAlert = $this->addAlert('https://webhook.microsft.com/webhook');
$this->updateAlert($idAlert, 'webhookURL');
}
public function testUpdateAlertSuccess()
{
$idAlert = $this->addAlert($msTeamsWebhookUrl = 'https://webhook.microsft.com/webhook');
$this->updateAlert($idAlert, $msTeamsWebhookUrl . 'new');
$alert = $this->api->getAlert($idAlert);
$this->assertEquals(['email','teams'], $alert['report_mediums']);
$this->assertEquals('https://webhook.microsft.com/webhooknew', $alert['ms_teams_webhook_url']);
}
private function addAlert($msTeamsWebhookUrl = '')
{
return $this->api->addAlert(
'Test teams and Email',
$this->idSite,
'day',
1,
[],
[],
'nb_visits',
'less_than',
$metricMatched = 5,
1,
'MultiSites_getOne',
'matches_exactly',
'Piwik',
['email', 'teams'],
'',
$msTeamsWebhookUrl
);
}
private function updateAlert($idAlert, $msTeamsWebhookUrl = '')
{
return $this->api->editAlert(
$idAlert,
'Test teams and Email',
$this->idSite,
'day',
1,
[],
[],
'nb_visits',
'less_than',
$metricMatched = 5,
1,
'MultiSites_getOne',
'matches_exactly',
'Piwik',
['email', 'teams'],
'',
$msTeamsWebhookUrl
);
}
}