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

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

namespace Piwik\Plugins\Marketplace\tests\Integration\Api;

use Piwik\Filesystem;
use Piwik\Plugins\Marketplace\Api\Client;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Plugins\Marketplace\tests\Framework\Mock\Service as TestService;
use Piwik\Plugins\Marketplace\tests\Framework\Mock\Client as ClientBuilder;

/**
 * @group Plugins
 * @group Marketplace
 * @group ClientTest
 * @group Client
 */
class ClientTest extends IntegrationTestCase
{
    /**
     * @var Client
     */
    private $client;

    /**
     * @var TestService
     */
    private $service;

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

        $this->service = new TestService();
        $this->client = $this->buildClient();
    }

    public function test_download()
    {
        $this->service->returnFixture('v2.0_plugins_TreemapVisualization_info.json');

        $file = $this->client->download('AnyPluginName');

        $this->assertFileExists($file);
        $this->assertStringEqualsFile($file, 'http://plugins.piwik.org/api/2.0/plugins/TreemapVisualization/download/1.0.1?coreVersion=2.16.3');
        Filesystem::deleteFileIfExists($file);

        $this->assertStringStartsWith(PIWIK_INCLUDE_PATH . '/tmp/latest/plugins/', $file);
        $this->assertStringEndsWith('.zip', $file);
    }

    /**
     * @expectedException \Piwik\Plugins\Marketplace\Api\Exception
     * @expectedExceptionMessage Requested plugin does not exist.
     */
    public function test_getPluginInfo_shouldThrowException_IfNotAllowedToRequestPlugin()
    {
        $this->service->returnFixture('v2.0_plugins_CustomPlugin1_info-access_token-notexistingtoken.json');
        $this->client->getPluginInfo('CustomPlugin1');
    }

    private function buildClient()
    {
        return ClientBuilder::build($this->service);
    }

}