|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Matomo - free/libre analytics platform |
| 5 | + * |
| 6 | + * @link https://matomo.org |
| 7 | + * @license https://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later |
| 8 | + */ |
| 9 | + |
| 10 | +namespace Piwik\Plugins\TreemapVisualization\tests\Integration; |
| 11 | + |
| 12 | +use Piwik\Http\BadRequestException; |
| 13 | +use Piwik\Plugins\TreemapVisualization\API; |
| 14 | +use Piwik\Tests\Framework\Fixture; |
| 15 | +use Piwik\Tests\Framework\TestCase\IntegrationTestCase; |
| 16 | + |
| 17 | +/** |
| 18 | + * @group TreemapVisualization |
| 19 | + * @group ApiTest |
| 20 | + * @group Plugins |
| 21 | + */ |
| 22 | +class ApiTest extends IntegrationTestCase |
| 23 | +{ |
| 24 | + private $api; |
| 25 | + |
| 26 | + public function setUp(): void |
| 27 | + { |
| 28 | + parent::setUp(); |
| 29 | + |
| 30 | + Fixture::createSuperUser(); |
| 31 | + $this->api = API::getInstance(); |
| 32 | + } |
| 33 | + |
| 34 | + /** |
| 35 | + * @dataProvider validMethod |
| 36 | + */ |
| 37 | + public function testGetTreemapDataAllowsValidApiMethod($method): void |
| 38 | + { |
| 39 | + $result = $this->api->getTreemapData( |
| 40 | + $method, |
| 41 | + 'nb_visits', |
| 42 | + 'day', |
| 43 | + '2025-02-03' |
| 44 | + ); |
| 45 | + |
| 46 | + $this->assertIsArray($result); |
| 47 | + } |
| 48 | + |
| 49 | + /** |
| 50 | + * @dataProvider inValidMethod |
| 51 | + */ |
| 52 | + public function testGetTreemapDataRejectsInvalidApiMethod($method): void |
| 53 | + { |
| 54 | + $this->expectException(BadRequestException::class); |
| 55 | + $this->api->getTreemapData( |
| 56 | + $method, |
| 57 | + 'nb_visits', |
| 58 | + 'day', |
| 59 | + '2025-02-03' |
| 60 | + ); |
| 61 | + } |
| 62 | + |
| 63 | + public function validMethod() |
| 64 | + { |
| 65 | + return [ |
| 66 | + ['API.getMatomoVersion'], |
| 67 | + ['API.getPhpVersion'], |
| 68 | + ]; |
| 69 | + } |
| 70 | + |
| 71 | + public function inValidMethod() |
| 72 | + { |
| 73 | + return [ |
| 74 | + ['API.getBulkRequest'], |
| 75 | + ['UsersManager.deleteUser'], |
| 76 | + ]; |
| 77 | + } |
| 78 | +} |
0 commit comments