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

ServiceTest.php « Integration « tests « Marketplace « plugins - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4852e9ba0702ad4c10f2d8422a7db355a3358d03 (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
<?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()
    {
        parent::setUp();

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

    /**
     * @expectedException \Piwik\Plugins\Marketplace\Api\Service\Exception
     * @expectedExceptionCode 101
     * @expectedExceptionMessage Requested plugin does not exist.
     */
    public function test_fetch_throwsApiError_WhenMarketplaceReturnsAnError()
    {
        $this->service->returnFixture('v2.0_plugins_CustomPlugin1_info-access_token-notexistingtoken.json');
        $this->service->fetch('plugins/CustomPlugin1/info', array());
    }

    /**
     * @expectedException \Piwik\Plugins\Marketplace\Api\Service\Exception
     * @expectedExceptionCode 100
     * @expectedExceptionMessage There was an error reading the response from the Marketplace
     */
    public function test_fetch_throwsHttpError_WhenMarketplaceReturnsNoResultWhichMeansHttpError()
    {
        $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);
    }

}