|
10 | 10 | namespace Piwik\Plugins\Slack\tests; |
11 | 11 |
|
12 | 12 | use Piwik\Container\StaticContainer; |
| 13 | +use Piwik\Piwik; |
13 | 14 | use Piwik\Plugins\ScheduledReports\API; |
14 | 15 | use Piwik\Plugins\ScheduledReports\ScheduledReports; |
15 | 16 | use Piwik\Plugins\Slack\Slack; |
@@ -113,6 +114,72 @@ public function getAlertData() |
113 | 114 | ]; |
114 | 115 | } |
115 | 116 |
|
| 117 | + public function testValidateReportParametersSlackTokenNotSetShouldThrowOauthException() |
| 118 | + { |
| 119 | + $this->expectException(\Exception::class); |
| 120 | + $this->expectExceptionMessage('Slack_OauthTokenRequiredErrorMessage'); |
| 121 | + $parameters = [ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY]; |
| 122 | + Piwik::postEvent('ScheduledReports.validateReportParameters', [&$parameters, 'slack']); |
| 123 | + } |
| 124 | + |
| 125 | + public function testValidateReportParametersSlackTokenNotSetShouldThrowSlackChannelIdEmptyException() |
| 126 | + { |
| 127 | + $settings = StaticContainer::get(SystemSettings::class); |
| 128 | + $settings->slackOauthToken->setValue('test123'); |
| 129 | + $this->expectException(\Exception::class); |
| 130 | + $this->expectExceptionMessage('Slack_SlackChannelIdRequiredErrorMessage'); |
| 131 | + $parameters = [ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY]; |
| 132 | + Piwik::postEvent('ScheduledReports.validateReportParameters', [&$parameters, 'slack']); |
| 133 | + } |
| 134 | + |
| 135 | + public function testValidateReportParametersSlackTokenNotSetShouldThrowSlackChannelIdEmptyException2() |
| 136 | + { |
| 137 | + $settings = StaticContainer::get(SystemSettings::class); |
| 138 | + $settings->slackOauthToken->setValue('test123'); |
| 139 | + $this->expectException(\Exception::class); |
| 140 | + $this->expectExceptionMessage('Slack_SlackChannelIdRequiredErrorMessage'); |
| 141 | + $parameters = [ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY, Slack::SLACK_CHANNEL_ID_PARAMETER => '']; |
| 142 | + Piwik::postEvent('ScheduledReports.validateReportParameters', [&$parameters, 'slack']); |
| 143 | + } |
| 144 | + |
| 145 | + public function testValidateReportParametersSlackTokenNotSetShouldThrowSlackChannelIdInvalidException() |
| 146 | + { |
| 147 | + $settings = StaticContainer::get(SystemSettings::class); |
| 148 | + $settings->slackOauthToken->setValue('test123'); |
| 149 | + $this->expectException(\Exception::class); |
| 150 | + $this->expectExceptionMessage('Slack_SlackChannelIdInvalidErrorMessage'); |
| 151 | + $parameters = [ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY, Slack::SLACK_CHANNEL_ID_PARAMETER => 'test123@11']; |
| 152 | + Piwik::postEvent('ScheduledReports.validateReportParameters', [&$parameters, 'slack']); |
| 153 | + } |
| 154 | + |
| 155 | + public function testValidateReportParametersSlackTokenNotSetShouldThrowSlackChannelIdInvalidException2() |
| 156 | + { |
| 157 | + $settings = StaticContainer::get(SystemSettings::class); |
| 158 | + $settings->slackOauthToken->setValue('test123'); |
| 159 | + $this->expectException(\Exception::class); |
| 160 | + $this->expectExceptionMessage('Slack_SlackChannelIdInvalidErrorMessage'); |
| 161 | + $parameters = [ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY, Slack::SLACK_CHANNEL_ID_PARAMETER => 'test123,Demo@11']; |
| 162 | + Piwik::postEvent('ScheduledReports.validateReportParameters', [&$parameters, 'slack']); |
| 163 | + } |
| 164 | + |
| 165 | + public function testValidateReportParametersSlackTokenShouldNotThrowAnyException() |
| 166 | + { |
| 167 | + $settings = StaticContainer::get(SystemSettings::class); |
| 168 | + $settings->slackOauthToken->setValue('test123'); |
| 169 | + $parameters = [ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY, Slack::SLACK_CHANNEL_ID_PARAMETER => 'test123']; |
| 170 | + Piwik::postEvent('ScheduledReports.validateReportParameters', [&$parameters, 'slack']); |
| 171 | + $this->assertNotEmpty($parameters); |
| 172 | + } |
| 173 | + |
| 174 | + public function testValidateReportParametersSlackTokenShouldNotThrowAnyException2() |
| 175 | + { |
| 176 | + $settings = StaticContainer::get(SystemSettings::class); |
| 177 | + $settings->slackOauthToken->setValue('test123'); |
| 178 | + $parameters = [ScheduledReports::DISPLAY_FORMAT_PARAMETER => ScheduledReports::DISPLAY_FORMAT_GRAPHS_ONLY, Slack::SLACK_CHANNEL_ID_PARAMETER => 'test123,dEmoA,abcd123']; |
| 179 | + Piwik::postEvent('ScheduledReports.validateReportParameters', [&$parameters, 'slack']); |
| 180 | + $this->assertNotEmpty($parameters); |
| 181 | + } |
| 182 | + |
116 | 183 | private function assertHasReport($login, $idSite) |
117 | 184 | { |
118 | 185 | $report = $this->getReport($login, $idSite); |
|
0 commit comments