blob: 777ce4393b15d20c935e121dea2f01855e2478ae (
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
|
<?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(): void
{
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);
}
public function test_getPluginInfo_shouldThrowException_IfNotAllowedToRequestPlugin()
{
$this->expectException(\Piwik\Plugins\Marketplace\Api\Exception::class);
$this->expectExceptionMessage('Requested plugin does not exist.');
$this->service->returnFixture('v2.0_plugins_CustomPlugin1_info-access_token-notexistingtoken.json');
$this->client->getPluginInfo('CustomPlugin1');
}
private function buildClient()
{
return ClientBuilder::build($this->service);
}
}
|