/** * Given a list of default parameters to set, returns the URLs of APIs to call * If any API was specified in $this->apiNotToCall we ensure only these are tested. * If any API is set as excluded (see list below) then it will be ignored. * * @param array $parametersToSet Parameters to set in api call * @param array $formats Array of 'format' to fetch from API * @param array $periods Array of 'period' to query API * @param bool $supertableApi * @param bool $setDateLastN If set to true, the 'date' parameter will be rewritten to query instead a range of dates, rather than one period only. * @param bool|string $language 2 letter language code, defaults to default piwik language * @param bool|string $fileExtension * * @throws Exception * * @return array of API URLs query strings */ protected function generateApiUrlPermutations($parametersToSet) { $formats = array($this->testConfig->format); $originalDate = $parametersToSet['date']; $requestUrls = array(); $apiMetadata = new DocumentationGenerator(); // Get the URLs to query against the API for all functions starting with get* foreach ($this->getAllApiMethods() as $apiMethodInfo) { list($class, $moduleName, $methodName) = $apiMethodInfo; $apiId = $moduleName . '.' . $methodName; foreach ($this->testConfig->periods as $period) { $parametersToSet['period'] = $period; // If date must be a date range, we process this date range by adding 6 periods to it if ($this->testConfig->setDateLastN) { if (!isset($parametersToSet['dateRewriteBackup'])) { $parametersToSet['dateRewriteBackup'] = $parametersToSet['date']; } $lastCount = $this->testConfig->setDateLastN; $secondDate = date('Y-m-d', strtotime("+{$lastCount} " . $period . "s", strtotime($originalDate))); $parametersToSet['date'] = $originalDate . ',' . $secondDate; } // Set response language if ($this->testConfig->language !== false) { $parametersToSet['language'] = $this->testConfig->language; } // set idSubtable if subtable API is set if ($this->testConfig->supertableApi !== false) { $request = new Request(array('module' => 'API', 'method' => $this->testConfig->supertableApi, 'idSite' => $parametersToSet['idSite'], 'period' => $parametersToSet['period'], 'date' => $parametersToSet['date'], 'format' => 'php', 'serialize' => 0)); $content = $request->process(); IntegrationTestCase::assertApiResponseHasNoError($content); // find first row w/ subtable foreach ($content as $row) { if (isset($row['idsubdatatable'])) { $parametersToSet['idSubtable'] = $row['idsubdatatable']; break; } } // if no subtable found, throw if (!isset($parametersToSet['idSubtable'])) { throw new Exception("Cannot find subtable to load for {$apiId} in {$this->testConfig->supertableApi}."); } } // Generate for each specified format foreach ($formats as $format) { $parametersToSet['format'] = $format; $parametersToSet['hideIdSubDatable'] = 1; $parametersToSet['serialize'] = 1; $exampleUrl = $apiMetadata->getExampleUrl($class, $methodName, $parametersToSet); if ($exampleUrl === false) { continue; } // Remove the first ? in the query string $exampleUrl = substr($exampleUrl, 1); $apiRequestId = $apiId; if (strpos($exampleUrl, 'period=') !== false) { $apiRequestId .= '_' . $period; } $apiRequestId .= '.' . $format; if ($this->testConfig->fileExtension) { $apiRequestId .= '.' . $this->testConfig->fileExtension; } $requestUrls[$apiRequestId] = UrlHelper::getArrayFromQueryString($exampleUrl); } } } return $requestUrls; }