-
Notifications
You must be signed in to change notification settings - Fork 1
Adds changes to send CustomAlerts via Slack, #PG-4530 #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e129da2
Adds changes to send CustomAlerts via Slack, #PG-4530
AltamashShaikh a2f1ada
default return for transformAlertCondition added
AltamashShaikh 8f88759
Fixes PHPCS errors
AltamashShaikh 7452f1a
Adds depenedent plugin to add tests for CustomAlerts plugin
AltamashShaikh a20acab
Fixes failing test
AltamashShaikh b0be934
Fixes load plugin issue
AltamashShaikh 21ea8a5
Adds dependednt plugin changes in github workflow:
AltamashShaikh 6e51220
Adds test for CustomAlerts
AltamashShaikh 6530310
Fixes for UI test
AltamashShaikh d7d9035
adds new UI screenshot and test fixes
AltamashShaikh 7017116
Adds new UI screenshot
AltamashShaikh 57b299c
Applied PR feedback
AltamashShaikh 555467d
Fixes for PHPCS
AltamashShaikh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,26 @@ | ||
| <?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\Slack; | ||
|
|
||
| use Piwik\Container\StaticContainer; | ||
| use Piwik\Plugins\CustomAlerts\Controller; | ||
|
|
||
| class EnrichTriggeredAlerts extends Controller | ||
| { | ||
| public function __construct() | ||
| { | ||
| parent::__construct(StaticContainer::get('Piwik\Plugins\API\ProcessedReport')); | ||
| } | ||
|
|
||
| public function enrichTriggeredAlerts($triggeredAlerts) | ||
| { | ||
| return parent::enrichTriggeredAlerts($triggeredAlerts); | ||
| } | ||
| } |
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 | ||
|
|
||
| /** | ||
| * 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\Slack\tests; | ||
|
|
||
| use Piwik\Tests\Framework\Fixture; | ||
| use Piwik\Tests\Framework\TestCase\IntegrationTestCase; | ||
| use Piwik\Tests\Framework\TestingEnvironmentManipulator; | ||
| use Piwik\Plugins\CustomAlerts\API; | ||
|
|
||
| /** | ||
| * @group Slack | ||
| * @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 testAddAlertShouldThrowExceptionIfEmptySlackChannelId() | ||
| { | ||
| $this->expectException(\Exception::class); | ||
| $this->expectExceptionMessage('Slack_SlackChannelIdRequiredErrorMessage'); | ||
| $this->addAlert(); | ||
| } | ||
|
|
||
| public function testAddAlertSuccess() | ||
| { | ||
| $id = $this->addAlert($slackChannelId = 'channelID'); | ||
| $this->assertEquals(1, $id); | ||
| $alert = $this->api->getAlert($id); | ||
| $this->assertEquals(['email','slack'], $alert['report_mediums']); | ||
| $this->assertEquals($slackChannelId, $alert['slack_channel_id']); | ||
| } | ||
|
|
||
| public function testUpdateAlertShouldThrowExceptionIfEmptySlackChannelId() | ||
| { | ||
| $this->expectException(\Exception::class); | ||
| $this->expectExceptionMessage('Slack_SlackChannelIdRequiredErrorMessage'); | ||
| $idAlert = $this->addAlert('channelID'); | ||
| $this->updateAlert($idAlert); | ||
| } | ||
|
|
||
| public function testUpdateAlertSuccess() | ||
| { | ||
| $idAlert = $this->addAlert('channelID'); | ||
| $this->updateAlert($idAlert, 'channelIDNew'); | ||
| $alert = $this->api->getAlert($idAlert); | ||
| $this->assertEquals(['email','slack'], $alert['report_mediums']); | ||
| $this->assertEquals('channelIDNew', $alert['slack_channel_id']); | ||
| } | ||
|
|
||
| private function addAlert($slackChannelId = '') | ||
| { | ||
| return $this->api->addAlert( | ||
| 'Test Slack and Email', | ||
| $this->idSite, | ||
| 'day', | ||
| 1, | ||
| [], | ||
| [], | ||
| 'nb_visits', | ||
| 'less_than', | ||
| $metricMatched = 5, | ||
| 1, | ||
| 'MultiSites_getOne', | ||
| 'matches_exactly', | ||
| 'Piwik', | ||
| ['email', 'slack'], | ||
| $slackChannelId | ||
| ); | ||
| } | ||
|
|
||
| private function updateAlert($idAlert, $slackChannelId = '') | ||
| { | ||
| return $this->api->editAlert( | ||
| $idAlert, | ||
| 'Test Slack and Email', | ||
| $this->idSite, | ||
| 'day', | ||
| 1, | ||
| [], | ||
| [], | ||
| 'nb_visits', | ||
| 'less_than', | ||
| $metricMatched = 5, | ||
| 1, | ||
| 'MultiSites_getOne', | ||
| 'matches_exactly', | ||
| 'Piwik', | ||
| ['email', 'slack'], | ||
| $slackChannelId | ||
| ); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.