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

test.php « config « Marketplace « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 8c21be15f80dab5c2ded9bebab46e8420f840576 (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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php

use Interop\Container\ContainerInterface;
use Piwik\Plugins\Marketplace\tests\Framework\Mock\Consumer as MockConsumer;
use Piwik\Plugins\Marketplace\LicenseKey;
use Piwik\Plugins\Marketplace\tests\Framework\Mock\Service as MockService;
use Piwik\Plugins\Marketplace\Input\PurchaseType;

return array(
    'MarketplaceEndpoint' => function (ContainerInterface $c) {
        // if you wonder why this here is configured here again, and the same as in `config.php`,
        // it is because someone might have overwritten MarketplaceEndpoit in local config.php and we want
        // to make sure system tests of marketplace are ran against plugins.piwik.org
        $domain = 'http://plugins.piwik.org';
        $updater = $c->get('Piwik\Plugins\CoreUpdater\Updater');

        if ($updater->isUpdatingOverHttps()) {
            $domain = str_replace('http://', 'https://', $domain);
        }

        return $domain;
    },
    'Piwik\Plugins\Marketplace\Consumer' => function (ContainerInterface $c) {
        $consumerTest = $c->get('test.vars.consumer');
        $licenseKey = new LicenseKey();

        if ($consumerTest == 'validLicense') {
            $consumer = MockConsumer::buildValidLicense();
            $licenseKey->set('123456789');
        } elseif ($consumerTest == 'exceededLicense') {
            $consumer = MockConsumer::buildExceededLicense();
            $licenseKey->set('1234567891');
        } elseif ($consumerTest == 'expiredLicense') {
            $consumer = MockConsumer::buildExpiredLicense();
            $licenseKey->set('1234567892');
        } else {
            $consumer = MockConsumer::buildNoLicense();
            $licenseKey->set(null);
        }

        return $consumer;
    },
    'Piwik\Plugins\Marketplace\Plugins' => DI\decorate(function ($previous, ContainerInterface $c) {
        /** @var \Piwik\Plugins\Marketplace\Plugins $previous */
        $previous->setPluginsHavingUpdateCache(null);

        $pluginNames = $c->get('test.vars.mockMarketplaceAssumePluginNamesActivated');

        if (!empty($pluginNames)) {
            /** @var \Piwik\Plugins\Marketplace\Plugins $previous */
            $previous->setActivatedPluginNames($pluginNames);
        }

        return $previous;
    }),
    'Piwik\Plugins\Marketplace\Api\Client' => DI\decorate(function ($previous) {
        /** @var \Piwik\Plugins\Marketplace\Api\Client $previous */
        $previous->clearAllCacheEntries();

        return $previous;
    }),
    'Piwik\Plugins\Marketplace\Plugins\InvalidLicenses' => DI\decorate(function ($previous, ContainerInterface $c) {

        $pluginNames = $c->get('test.vars.mockMarketplaceAssumePluginNamesActivated');

        if (!empty($pluginNames)) {
            /** @var \Piwik\Plugins\Marketplace\Plugins\InvalidLicenses $previous */
            $previous->setActivatedPluginNames($pluginNames);
            $previous->clearCache();
        }

        return $previous;

    }),
    'Piwik\Plugins\Marketplace\Api\Service' => DI\decorate(function ($previous, ContainerInterface $c) {
        if (!$c->get('test.vars.mockMarketplaceApiService')) {
            return $previous;
        }

        // for ui tests
        $service = new MockService();

        $key = new LicenseKey();
        $accessToken = $key->get();

        $service->authenticate($accessToken);

        function removeReviewsUrl($content)
        {
            $content = json_decode($content, true);
            if (!empty($content['shop']['reviews']['embedUrl'])) {
                $content['shop']['reviews']['embedUrl'] = '';
            }
            return json_encode($content);
        }

        $isExceededUser = $c->get('test.vars.consumer') === 'exceededLicense';
        $isExpiredUser = $c->get('test.vars.consumer') === 'expiredLicense';
        $isValidUser = $c->get('test.vars.consumer') === 'validLicense';

        $service->setOnDownloadCallback(function ($action, $params) use ($service, $isExceededUser, $isValidUser, $isExpiredUser) {
            if ($action === 'info') {
                return $service->getFixtureContent('v2.0_info.json');
            } elseif ($action === 'consumer' && $service->getAccessToken() === 'valid') {
                return $service->getFixtureContent('v2.0_consumer-access_token-consumer2_paid1.json');
            } elseif ($action === 'consumer/validate' && $service->getAccessToken() === 'valid') {
                return $service->getFixtureContent('v2.0_consumer_validate-access_token-consumer2_paid1.json');
            } elseif ($action === 'consumer' && $service->getAccessToken() === 'invalid') {
                return $service->getFixtureContent('v2.0_consumer-access_token-notexistingtoken.json');
            } elseif ($action === 'consumer/validate' && $service->getAccessToken() === 'invalid') {
                return $service->getFixtureContent('v2.0_consumer_validate-access_token-notexistingtoken.json');
            } elseif ($action === 'plugins' && empty($params['purchase_type']) && empty($params['query'])) {
                return $service->getFixtureContent('v2.0_plugins.json');
            } elseif ($action === 'plugins' && $isExceededUser && !empty($params['purchase_type']) && $params['purchase_type'] === PurchaseType::TYPE_PAID && empty($params['query'])) {
                return $service->getFixtureContent('v2.0_plugins-purchase_type-paid-num_users-201-access_token-consumer2_paid1.json');
            } elseif ($action === 'plugins' && $isExpiredUser && !empty($params['purchase_type']) && $params['purchase_type'] === PurchaseType::TYPE_PAID && empty($params['query'])) {
                return $service->getFixtureContent('v2.0_plugins-purchase_type-paid-access_token-consumer1_paid2_custom1.json');
            } elseif ($action === 'plugins' && ($service->hasAccessToken() || $isValidUser) && !empty($params['purchase_type']) && $params['purchase_type'] === PurchaseType::TYPE_PAID && empty($params['query'])) {
                return $service->getFixtureContent('v2.0_plugins-purchase_type-paid-access_token-consumer2_paid1.json');
            } elseif ($action === 'plugins' && !$service->hasAccessToken() && !empty($params['purchase_type']) && $params['purchase_type'] === PurchaseType::TYPE_PAID && empty($params['query'])) {
                return $service->getFixtureContent('v2.0_plugins-purchase_type-paid-access_token-notexistingtoken.json');
            } elseif ($action === 'themes' && empty($params['purchase_type']) && empty($params['query'])) {
                return $service->getFixtureContent('v2.0_themes.json');
            } elseif ($action === 'plugins/Barometer/info') {
                return $service->getFixtureContent('v2.0_plugins_Barometer_info.json');
            } elseif ($action === 'plugins/TreemapVisualization/info') {
                return $service->getFixtureContent('v2.0_plugins_TreemapVisualization_info.json');
            } elseif ($action === 'plugins/PaidPlugin1/info' && $service->hasAccessToken() && $isExceededUser) {
                $content = $service->getFixtureContent('v2.0_plugins_PaidPlugin1_info-purchase_type-paid-num_users-201-access_token-consumer2_paid1.json');
                return removeReviewsUrl($content);
            } elseif ($action === 'plugins/PaidPlugin1/info' && $service->hasAccessToken()) {
                $content = $service->getFixtureContent('v2.0_plugins_PaidPlugin1_info-access_token-consumer3_paid1_custom2.json');
                return removeReviewsUrl($content);
            } elseif ($action === 'plugins/PaidPlugin1/info' && !$service->hasAccessToken()) {
                $content = $service->getFixtureContent('v2.0_plugins_PaidPlugin1_info.json');
                return removeReviewsUrl($content);
            } elseif ($action === 'plugins/checkUpdates') {
                return $service->getFixtureContent('v2.0_plugins_checkUpdates-pluginspluginsnameAnonymousPi.json');
            }
        });

        return $service;
    })
);