Download plugins/CoreAdminHome/tests/Integration/APITest.php from Leon4gr45/matomo: direct link, hf CLI and curl.
- Browser
- Download file 3.62 kB
-
https://huggingface.co/spaces/Leon4gr45/matomo/resolve/main/plugins/CoreAdminHome/tests/Integration/APITest.php
- Command line
-
hf download hf://spaces/Leon4gr45/matomo/plugins/CoreAdminHome/tests/Integration/APITest.php
-
curl -L -o APITest.php https://huggingface.co/spaces/Leon4gr45/matomo/resolve/main/plugins/CoreAdminHome/tests/Integration/APITest.php
3.62 kB
| /** | |
| * 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\CoreAdminHome\tests\Integration; | |
| use Piwik\Plugins\CoreAdminHome\API; | |
| use Piwik\Tests\Framework\Fixture; | |
| use Piwik\Tests\Framework\Mock\FakeAccess; | |
| /** | |
| * @group CoreAdminHome | |
| * @group APITest | |
| * @group API | |
| * @group Plugins | |
| */ | |
| class APITest extends \Piwik\Tests\Framework\TestCase\IntegrationTestCase | |
| { | |
| /** | |
| * @var int | |
| */ | |
| private $idSite; | |
| /** | |
| * @var API | |
| */ | |
| private $api; | |
| public function setUp(): void | |
| { | |
| parent::setUp(); | |
| $this->api = API::getInstance(); | |
| for ($i = 0; $i < 5; $i++) { | |
| Fixture::createWebsite('2014-01-02 03:04:05'); | |
| } | |
| } | |
| public function testGetTrackingFailuresFailsForViewUser() | |
| { | |
| $this->expectException(\Piwik\NoAccessException::class); | |
| $this->expectExceptionMessage('checkUserHasSomeAdminAccess'); | |
| $this->setUser(); | |
| $this->api->getTrackingFailures(); | |
| } | |
| public function testGetTrackingFailuresWorksForAdminAndSuperuser() | |
| { | |
| $this->setAdminUser(); | |
| $this->assertSame(array(), $this->api->getTrackingFailures()); | |
| $this->setSuperUser(); | |
| $this->api->getTrackingFailures(); | |
| $this->assertSame(array(), $this->api->getTrackingFailures()); | |
| } | |
| public function testDeleteAllTrackingFailuresFailsForViewUser() | |
| { | |
| $this->expectException(\Piwik\NoAccessException::class); | |
| $this->expectExceptionMessage('checkUserHasSomeAdminAccess'); | |
| $this->setUser(); | |
| $this->api->deleteAllTrackingFailures(); | |
| } | |
| public function testDeleteAllTrackingFailuresWorksForAdminAndSuperuser() | |
| { | |
| $this->expectNotToPerformAssertions(); | |
| $this->setAdminUser(); | |
| $this->api->deleteAllTrackingFailures(); | |
| $this->setSuperUser(); | |
| $this->api->deleteAllTrackingFailures(); | |
| } | |
| public function testDeleteTrackingFailureFailsForViewUser() | |
| { | |
| $this->expectException(\Piwik\NoAccessException::class); | |
| $this->expectExceptionMessage('checkUserHasAdminAccess'); | |
| $this->setUser(); | |
| $this->api->deleteTrackingFailure(1, 2); | |
| } | |
| public function testDeleteTrackingFailureFailsForAdminUserIfNotAdminAccessToThatSite() | |
| { | |
| $this->expectException(\Piwik\NoAccessException::class); | |
| $this->expectExceptionMessage('checkUserHasAdminAccess'); | |
| $this->setAdminUser(); | |
| $this->api->deleteTrackingFailure(2, 2); | |
| } | |
| public function testDeleteTrackingFailureWorksForAdminAndSuperuser() | |
| { | |
| $this->expectNotToPerformAssertions(); | |
| $this->setAdminUser(); | |
| $this->api->deleteTrackingFailure(1, 2); | |
| $this->setSuperUser(); | |
| $this->api->deleteTrackingFailure(1, 2); | |
| } | |
| protected function setSuperUser() | |
| { | |
| FakeAccess::clearAccess(true); | |
| } | |
| protected function setUser() | |
| { | |
| FakeAccess::clearAccess(false); | |
| FakeAccess::$identity = 'testUser'; | |
| FakeAccess::$idSitesView = array(1,3, $this->idSite); | |
| FakeAccess::$idSitesAdmin = array(); | |
| } | |
| protected function setAdminUser() | |
| { | |
| FakeAccess::clearAccess(false); | |
| FakeAccess::$identity = 'testUser'; | |
| FakeAccess::$idSitesView = array(); | |
| FakeAccess::$idSitesAdmin = array(1,3, $this->idSite); | |
| } | |
| public function provideContainerConfig() | |
| { | |
| return array( | |
| 'Piwik\Access' => new FakeAccess(), | |
| ); | |
| } | |
| } | |