blob: 6fea2f109ba57e9b0ad1867c46d409b636f1b8f6 (
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
|
<?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\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\Plugins\Marketplace\tests\Framework\Mock\Service as TestService;
/**
* @group Plugins
* @group Marketplace
* @group Service
* @group ServiceTest
*/
class ServiceTest extends IntegrationTestCase
{
/**
* @var TestService
*/
private $service;
public function setUp(): void
{
parent::setUp();
$this->service = new TestService();
}
public function test_fetch_throwsApiError_WhenMarketplaceReturnsAnError()
{
$this->expectException(\Piwik\Plugins\Marketplace\Api\Service\Exception::class);
$this->expectExceptionCode(101);
$this->expectExceptionMessage('Requested plugin does not exist.');
$this->service->returnFixture('v2.0_plugins_CustomPlugin1_info-access_token-notexistingtoken.json');
$this->service->fetch('plugins/CustomPlugin1/info', array());
}
public function test_fetch_throwsHttpError_WhenMarketplaceReturnsNoResultWhichMeansHttpError()
{
$this->expectException(\Piwik\Plugins\Marketplace\Api\Service\Exception::class);
$this->expectExceptionCode(100);
$this->expectExceptionMessage('There was an error reading the response from the Marketplace');
$this->service->setOnDownloadCallback(function () {
return null;
});
$this->service->fetch('plugins/CustomPlugin1/info', array());
}
public function test_fetch_jsonDecodesTheHttpResponse()
{
$this->service->returnFixture('v2.0_consumer-access_token-consumer1_paid2_custom1.json');
$consumer = $this->service->fetch('consumer', array());
$this->assertTrue(is_array($consumer));
$this->assertNotEmpty($consumer);
}
}
|