diff options
author | Peter Zhang <peter@innocraft.com> | 2021-10-08 04:02:01 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-08 04:02:01 +0300 |
commit | 52caa6e3bcfe4b9d66cf42825f5523510664c53e (patch) | |
tree | e2a009018be87042c359bf8e69bc146ac39fc6ca | |
parent | b9ba1e58d076708ccab251428b6d4d7a12ab3dc2 (diff) |
SEO ranking Plugin tests update (#18109)
-rw-r--r-- | plugins/SEO/tests/Integration/SEOTest.php | 26 |
1 files changed, 22 insertions, 4 deletions
diff --git a/plugins/SEO/tests/Integration/SEOTest.php b/plugins/SEO/tests/Integration/SEOTest.php index 2d640e0e75..3483b80101 100644 --- a/plugins/SEO/tests/Integration/SEOTest.php +++ b/plugins/SEO/tests/Integration/SEOTest.php @@ -41,10 +41,7 @@ class SEOTest extends IntegrationTestCase */ public function test_API() { - $dataTable = API::getInstance()->getRank('http://www.microsoft.com/'); - $renderer = Renderer::factory('json'); - $renderer->setTable($dataTable); - $ranks = json_decode($renderer->render(), true); + $ranks = $this->apiFunction(); foreach ($ranks as $rank) { if ($rank['rank'] == Piwik::translate('General_Error')) { $this->markTestSkipped('An exception raised when fetching data. Skipping this test for now.'); @@ -60,4 +57,25 @@ class SEOTest extends IntegrationTestCase 'Piwik\Access' => new FakeAccess() ); } + + /** + * this function rerun the API 3 times, to reduce the chance of failing. + */ + private function apiFunction($counter = 0, $ranks = []) + { + if ($counter > 3) { + return $ranks; + } + $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'] === 0 ) { + $this->apiFunction($counter++, $ranks); + } + } + return $ranks; + } + } |