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

Consumer.php « Mock « Framework « tests « Marketplace « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9c72c20c51cd796257d3cd3be94df9063f49e320 (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
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link http://piwik.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 */

namespace Piwik\Plugins\Marketplace\tests\Framework\Mock;

use \Piwik\Plugins\Marketplace\Consumer as ActualConsumer;
use Piwik\Plugins\Marketplace\Input\PurchaseType;

class Consumer {

    public static function build($service)
    {
        $client = Client::build($service);
        return new ActualConsumer($client);
    }

    public static function buildNoLicense()
    {
        $service = new Service();
        $service->setOnDownloadCallback(function ($action, $params) use ($service) {
            if ($action === 'info') {
                return $service->getFixtureContent('v2.0_info.json');
            } elseif ($action === 'consumer') {
                return $service->getFixtureContent('v2.0_consumer-access_token-notexistingtoken.json');
            } elseif ($action === 'consumer/validate') {
                return $service->getFixtureContent('v2.0_consumer_validate-access_token-notexistingtoken.json');
            } elseif ($action === 'plugins' && !empty($params['purchase_type']) && $params['purchase_type'] === PurchaseType::TYPE_PAID) {
                return $service->getFixtureContent('v2.0_plugins-purchase_type-paid-access_token-notexistingtoken.json');
            }
        });
        return static::build($service);
    }

    public static function buildValidLicense()
    {
        $service = new Service();
        $service->setOnDownloadCallback(function ($action, $params) use ($service) {
            if ($action === 'info') {
                return $service->getFixtureContent('v2.0_info.json');
            } elseif ($action === 'consumer') {
                return $service->getFixtureContent('v2.0_consumer-access_token-consumer2_paid1.json');
            } elseif ($action === 'consumer/validate') {
                return $service->getFixtureContent('v2.0_consumer_validate-access_token-consumer2_paid1.json');
            } elseif ($action === 'plugins' && !empty($params['purchase_type']) && $params['purchase_type'] === PurchaseType::TYPE_PAID) {
                return $service->getFixtureContent('v2.0_plugins-purchase_type-paid-access_token-consumer2_paid1.json');
            }
        });
        return static::build($service);
    }

    public static function buildExceededLicense()
    {
        $service = new Service();
        $service->setOnDownloadCallback(function ($action, $params) use ($service) {
            if ($action === 'info') {
                return $service->getFixtureContent('v2.0_info.json');
            } elseif ($action === 'consumer') {
                return $service->getFixtureContent('v2.0_consumer-num_users-201-access_token-consumer1_paid2_custom1.json');
            } elseif ($action === 'consumer/validate') {
                return $service->getFixtureContent('v2.0_consumer_validate-access_token-consumer1_paid2_custom1.json');
            } elseif ($action === 'plugins' && !empty($params['purchase_type']) && $params['purchase_type'] === PurchaseType::TYPE_PAID) {
                return $service->getFixtureContent('v2.0_plugins-purchase_type-paid-num_users-201-access_token-consumer1_paid2_custom1.json');
            }
        });

        return static::build($service);
    }

    public static function buildExpiredLicense()
    {
        $service = new Service();
        $service->setOnDownloadCallback(function ($action, $params) use ($service) {
            if ($action === 'info') {
                return $service->getFixtureContent('v2.0_info.json');
            } elseif ($action === 'consumer') {
                return $service->getFixtureContent('v2.0_consumer-access_token-consumer3_paid1_custom2.json');
            } elseif ($action === 'consumer/validate') {
                return $service->getFixtureContent('v2.0_consumer_validate-access_token-consumer3_paid1_custom2.json');
            } elseif ($action === 'plugins' && !empty($params['purchase_type']) && $params['purchase_type'] === PurchaseType::TYPE_PAID) {
                return $service->getFixtureContent('v2.0_plugins-purchase_type-paid-access_token-consumer1_paid2_custom1.json');
            }
        });
        return static::build($service);
    }

}