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

ReleaseChannelsTest.php « Plugin « Integration « PHPUnit « tests - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 3d2eae212bd83443550c670e1dc666b6b6e22023 (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
92
93
94
95
96
97
98
99
100
101
102
103
<?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\Tests\Integration\Plugin;

use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\Db;
use Piwik\Plugin;
use Piwik\Settings\Storage;
use Piwik\Cache as PiwikCache;
use Piwik\Tests\Framework\Fixture;
use Piwik\Tests\Framework\TestCase\IntegrationTestCase;
use Piwik\UpdateCheck\ReleaseChannel;

/**
 * @group Plugin
 * @group ReleaseChannels
 * @group ReleaseChannelsTest
 */
class ReleaseChannelsTest extends IntegrationTestCase
{
    /**
     * @var Plugin\ReleaseChannels
     */
    private $channels;

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

        if (!Fixture::siteCreated(1)) {
            Fixture::createWebsite('2015-01-01 00:00:00');
        }

        $this->channels = new Plugin\ReleaseChannels(StaticContainer::get('Piwik\Plugin\Manager'));
    }

    public function test_getAllReleaseChannels_shouldFindAllAvailableRelaseChannels()
    {
        $channels = $this->channels->getAllReleaseChannels();

        $this->assertCount(4, $channels);

        foreach ($channels as $channel) {
            $this->assertTrue($channel instanceof ReleaseChannel);
        }
    }

    public function test_getAllReleaseChannels_shouldOrderChannelsByOrderId()
    {
        $channels = $this->channels->getAllReleaseChannels();

        $lowest = 0;
        foreach ($channels as $channel) {
            $this->assertGreaterThanOrEqual($lowest, $channel->getOrder());
            $lowest = $channel->getOrder();
        }

        // to make sure we actually went into the for loop...
        $this->assertGreaterThan(0, $lowest);
    }

    /**
     * @dataProvider getTestValidReleaseChannelIds
     */
    public function test_isValidReleaseChannelId_shouldDetectIfReleaseChannelIsCorrectOrNot($expectedExists, $id)
    {
        $this->assertSame($expectedExists, $this->channels->isValidReleaseChannelId($id));
    }

    public function getTestValidReleaseChannelIds()
    {
        return array(
            array($exists = true, $id = 'latest_stable'),
            array($exists = true, $id = 'latest_beta'),
            array($exists = true, $id = 'latest_3x_stable'),
            array($exists = true, $id = 'laTest_stable'), // we do not check for exact match
            array($exists = false, $id = ''),
            array($exists = false, $id = 'latest'),
            array($exists = false, $id = 'stable'),
            array($exists = false, $id = 'lateststable'),
        );
    }

    public function getTestActiveReleaseChannel()
    {
        return array(
            array('latest_stable', 'latest_stable'),
            array('latest_3x_stable', 'latest_3x_stable'),
            array('latest_beta', 'latest_beta'),
            array('latest_beta', 'latEst_betA'),
            array('latest_stable', ''), // if nothing configured should return default (the one with lowest order)
            array('latest_stable', 'latest'), // if invalid id configured should return default (the one with lowest order)
        );
    }

}