قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-22 15:07:44 +00:00

* [Coding Style] Enable rule PSR1.Methods.CamelCapsMethodName.NotCamelCaps * [Coding Style] Use camel case for method names in API plugin tests (#22145) * [Coding Style] Use camel case for method names in Core* plugin tests (#22147) * [Coding Style] Use camel case for method names in core Unit tests (#22149) * [Coding Style] Use camel case for method names in Actions and BulkTracking plugin tests (#22146) * [Coding Style] Use camel case for method names in CustomDimensions and CustomJSTracker plugin tests (#22148) * [Coding Style] Use camel case for method names in core Integration tests (#22151) * [Coding Style] Use camel case for method names in more core plugin tests (#22153) * [Coding Style] Use camel case for method names in more core plugin tests (#22157) * [Coding Style] Use camel case for method names in more core plugin tests * Update plugins/Monolog/tests/Unit/Processor/ExceptionToTextProcessorTest.php Co-authored-by: Michal Kleiner <michal@innocraft.com> --------- Co-authored-by: Michal Kleiner <michal@innocraft.com> * [Coding Style] Use camel case for method names in more core plugin tests (#22159) * [Coding Style] Use camel case for method names in remaining tests (#22160) * [Coding Style] Use camel case for method names in remaining tests * rename expected test files --------- Co-authored-by: Michal Kleiner <michal@innocraft.com>
134 خطوط
3.5 KiB
PHP
134 خطوط
3.5 KiB
PHP
<?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\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()
|
|
);
|
|
}
|
|
}
|