public function test_CheckDocumentation() { $moduleToCheck = 'this is documentation which contains @hideExceptForSuperUser'; $documentationAfterCheck = 'this is documentation which contains '; $documentationGenerator = new DocumentationGenerator(); $this->assertEquals($documentationGenerator->checkDocumentation($moduleToCheck), $documentationAfterCheck); }
public function listAllAPI() { $view = new View("@API/listAllAPI"); $this->setGeneralVariablesView($view); $ApiDocumentation = new DocumentationGenerator(); $view->countLoadedAPI = Proxy::getInstance()->getCountRegisteredClasses(); $view->list_api_methods_with_links = $ApiDocumentation->getAllInterfaceString(); return $view->render(); }
/** * 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(); SystemTestCase::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; }
/** * 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 generateUrlsApi($parametersToSet, $formats, $periods, $supertableApi = false, $setDateLastN = false, $language = false, $fileExtension = false) { // Get the URLs to query against the API for all functions starting with get* $skipped = $requestUrls = array(); $apiMetadata = new DocumentationGenerator(); foreach (Proxy::getInstance()->getMetadata() as $class => $info) { $moduleName = Proxy::getInstance()->getModuleNameFromClassName($class); foreach ($info as $methodName => $infoMethod) { $apiId = $moduleName . '.' . $methodName; // If Api to test were set, we only test these if (!empty($this->apiToCall) && in_array($moduleName, $this->apiToCall) === false && in_array($apiId, $this->apiToCall) === false) { $skipped[] = $apiId; continue; } elseif (strpos($methodName, 'get') !== 0 && $methodName != 'generateReport' || in_array($moduleName, $this->apiNotToCall) === true || in_array($apiId, $this->apiNotToCall) === true || $methodName == 'getLogoUrl' || $methodName == 'getSVGLogoUrl' || $methodName == 'hasSVGLogo' || $methodName == 'getHeaderLogoUrl') { // Excluded modules from test $skipped[] = $apiId; continue; } foreach ($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 ($setDateLastN) { if (!isset($parametersToSet['dateRewriteBackup'])) { $parametersToSet['dateRewriteBackup'] = $parametersToSet['date']; } $lastCount = (int) $setDateLastN; if ($setDateLastN === true) { $lastCount = 6; } $firstDate = $parametersToSet['dateRewriteBackup']; $secondDate = date('Y-m-d', strtotime("+{$lastCount} " . $period . "s", strtotime($firstDate))); $parametersToSet['date'] = $firstDate . ',' . $secondDate; } // Set response language if ($language !== false) { $parametersToSet['language'] = $language; } // set idSubtable if subtable API is set if ($supertableApi !== false) { $request = new Request(array('module' => 'API', 'method' => $supertableApi, 'idSite' => $parametersToSet['idSite'], 'period' => $parametersToSet['period'], 'date' => $parametersToSet['date'], 'format' => 'php', 'serialize' => 0)); // find first row w/ subtable $content = $request->process(); $this->checkRequestResponse($content); 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 {$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) { $skipped[] = $apiId; continue; } // Remove the first ? in the query string $exampleUrl = substr($exampleUrl, 1); $apiRequestId = $apiId; if (strpos($exampleUrl, 'period=') !== false) { $apiRequestId .= '_' . $period; } $apiRequestId .= '.' . $format; if ($fileExtension) { $apiRequestId .= '.' . $fileExtension; } $requestUrls[$apiRequestId] = $exampleUrl; } } } } return $requestUrls; }