قرینه از
https://github.com/matomo-org/matomo.git
synced 2025-08-22 23:17:46 +00:00

* Improve fault-tolerance of SEOTest integration test * Use safer empty check in case some parts of the nested array are not defined * Use static class variable in test * Fix CS * Revert user agent randomisation * Removed unused use statement * Remove retry mechanism from Bing metric * Skip Bing metric in SEOTest * Revert changes in Bing metric --------- Co-authored-by: caddoo <matthew.caddoo@gmail.com> Co-authored-by: Stefan Giehl <stefan@matomo.org>
75 خطوط
2.3 KiB
PHP
75 خطوط
2.3 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\SEO\tests\Integration;
|
|
|
|
use Piwik\DataTable\Renderer;
|
|
use Piwik\EventDispatcher;
|
|
use Piwik\Piwik;
|
|
use Piwik\Plugins\SEO\API;
|
|
use Piwik\Tests\Framework\Fixture;
|
|
use Piwik\Tests\Framework\Mock\FakeAccess;
|
|
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
|
|
|
|
/**
|
|
* @group SEO
|
|
* @group SEOTest
|
|
* @group Plugins
|
|
*/
|
|
class SEOTest extends IntegrationTestCase
|
|
{
|
|
public function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
// Setup the access layer
|
|
FakeAccess::setIdSitesView([1, 2]);
|
|
FakeAccess::setIdSitesAdmin([3, 4]);
|
|
|
|
// Finally we set the user as a Super User by default
|
|
FakeAccess::$superUser = true;
|
|
|
|
// Needed to load the Intl_NumberFormatNumber translation string used when formatting the ranking numbers
|
|
Fixture::loadAllTranslations();
|
|
|
|
// Bing may not show the indexed pages count for some user agents, This user agent string works as of 2023-06-26:
|
|
$_SERVER['HTTP_USER_AGENT'] = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36';
|
|
}
|
|
|
|
/**
|
|
* tell us when the API is broken
|
|
*/
|
|
public function testAPI()
|
|
{
|
|
// skip testing Bing metric as it's flaky
|
|
EventDispatcher::getInstance()->addObserver('SEO.getMetricsProviders', function (&$providers) {
|
|
unset($providers['Piwik\Plugins\SEO\Metric\Bing']);
|
|
});
|
|
|
|
$dataTable = API::getInstance()->getRank('http://matomo.org/');
|
|
$renderer = Renderer::factory('json');
|
|
$renderer->setTable($dataTable);
|
|
$ranks = json_decode($renderer->render(), true);
|
|
foreach ($ranks as $rank) {
|
|
if ($rank['rank'] == Piwik::translate('General_ErrorTryAgain')) {
|
|
$this->markTestSkipped('An exception raised when fetching data. Skipping this test for now.');
|
|
continue;
|
|
}
|
|
$this->assertNotEmpty($rank['rank'], $rank['id'] . ' expected non-zero rank, got [' . $rank['rank'] . ']');
|
|
}
|
|
}
|
|
|
|
public function provideContainerConfig()
|
|
{
|
|
return [
|
|
'Piwik\Access' => new FakeAccess()
|
|
];
|
|
}
|
|
}
|