Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ApiGetReportMetadataTest.php « System « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 22ba6cfbd670ee926293434b2f15133cb6b4d0e7 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
 * Matomo - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */
namespace Piwik\Tests\System;

use Piwik\API\Proxy;
use Piwik\Tests\Framework\TestCase\SystemTestCase;
use Piwik\Tests\Fixtures\ThreeGoalsOnePageview;

/**
 * This tests the output of the API plugin API
 * It will return metadata about all API reports from all plugins
 * as well as the data itself, pre-processed and ready to be displayed
 *
 * @group Plugins
 * @group ApiGetReportMetadataTest
 */
class ApiGetReportMetadataTest extends SystemTestCase
{
    public static $fixture = null; // initialized below class definition

    public function setUp(): void
    {
        parent::setUp();

        // From Piwik 1.5, we hide Goals.getConversions and other get* methods via @ignore, but we
        // ensure that they still work. This hack allows the API proxy to let us generate example
        // URLs for the ignored functions
        Proxy::getInstance()->setHideIgnoredFunctions(false);

        if (version_compare(PHP_VERSION, '8.0.0') >= 0) {
            $this->markTestSkipped('Skipping for PHP8');
        }

    }

    public function tearDown(): void
    {
        parent::tearDown();

        // reset that value after the test
        Proxy::getInstance()->setHideIgnoredFunctions(true);
    }

    public static function getOutputPrefix()
    {
        return 'apiGetReportMetadata';
    }

    public function getApiForTesting()
    {
        $idSite = self::$fixture->idSite;
        $dateTime = self::$fixture->dateTime;

        return array(
            array('API', array('idSite' => $idSite, 'date' => $dateTime)),

            // test w/ hideMetricsDocs=true
            array('API.getMetadata', array('idSite'                 => $idSite, 'date' => $dateTime,
                                           'apiModule'              => 'Actions', 'apiAction' => 'get',
                                           'testSuffix'             => '_hideMetricsDoc',
                                           'otherRequestParameters' => array('hideMetricsDoc' => 1))),
            array('API.getProcessedReport', array('idSite'                 => $idSite, 'date' => $dateTime,
                                                  'apiModule'              => 'Actions', 'apiAction' => 'get',
                                                  'testSuffix'             => '_hideMetricsDoc',
                                                  'otherRequestParameters' => array('hideMetricsDoc' => 1))),

            // Test w/ showRawMetrics=true
            array('API.getProcessedReport', array('idSite'                 => $idSite, 'date' => $dateTime,
                                                  'apiModule'              => 'UserCountry', 'apiAction' => 'getCountry',
                                                  'testSuffix'             => '_showRawMetrics',
                                                  'otherRequestParameters' => array('showRawMetrics' => 1))),

            // Test w/ showRawMetrics=true
            array('Actions.getPageTitles', array('idSite'     => $idSite, 'date' => $dateTime,
                                                 'testSuffix' => '_pageTitleZeroString')),

            // Test w/ no format, should default to format=json
            ['Actions.getPageTitles', [
                'idSite'     => $idSite,
                'date' => $dateTime,
                'testSuffix' => '_defaultFormatValue',
                'format' => 'asldjkf',
            ]],
        );
    }

    /**
     * @dataProvider getApiForTesting
     */
    public function testApi($api, $params)
    {
        $this->runApiTests($api, $params);
    }
}

ApiGetReportMetadataTest::$fixture = new ThreeGoalsOnePageview();