blob: 48105112f59989465fd015cbb5a9dff5b754158d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
<?php
if(!defined("PIWIK_PATH_TEST_TO_ROOT")) {
define('PIWIK_PATH_TEST_TO_ROOT', getcwd().'/../../..');
}
if(!defined('PIWIK_CONFIG_TEST_INCLUDED'))
{
require_once PIWIK_PATH_TEST_TO_ROOT . "/tests/config_test.php";
}
require_once "API/DocumentationGenerator.php";
class Test_Piwik_API_DocumentationGenerator extends UnitTestCase
{
function test_callableApiMethods_doNotFail()
{
Piwik::createConfigObject();
Zend_Registry::get('config')->setTestEnvironment();
Piwik::createLogObject();
Piwik::createAccessObject();
Piwik::createDatabaseObject();
Piwik::setUserIsSuperUser();
$pluginsManager = Piwik_PluginsManager::getInstance();
$pluginsManager->loadPlugins( Zend_Registry::get('config')->Plugins->Plugins->toArray() );
$apiGenerator = new Piwik_API_DocumentationGenerator_CallAllMethods();
$requestUrls = $apiGenerator->getAllRequestsWithParameters();
$this->assertTrue(count($requestUrls) > 20);
foreach($requestUrls as $url)
{
$call = new Piwik_API_Request($url);
$output = $call->process();
// var_dump($url);
// var_dump($output);
$this->assertTrue(!empty($output));
}
$this->pass();
}
}
class Piwik_API_DocumentationGenerator_CallAllMethods extends Piwik_API_DocumentationGenerator
{
function getAllRequestsWithParameters()
{
$requestUrls = array();
$parametersToSet = array(
'idSite' => '1',
'period' => 'week',
'date' => 'today',
'expanded' => '1',
);
foreach(Piwik_API_Proxy::getInstance()->getMetadata() as $class => $info)
{
$moduleName = Piwik_API_Proxy::getInstance()->getModuleNameFromClassName($class);
foreach($info as $methodName => $infoMethod)
{
$params = $this->getStrListParameters($class, $methodName);
$exampleUrl = $this->getExampleUrl($class, $methodName, $parametersToSet);
if($exampleUrl !== false)
{
$requestUrls[] = $exampleUrl;
}
}
}
return $requestUrls;
}
}
|