summaryrefslogtreecommitdiff
path: root/tests/units/Core/Plugin/DirectoryTest.php
blob: 302bd6f60f344ba96d22b45acd32cb5578f16fa3 (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
<?php

use Kanboard\Core\Plugin\Directory;

require_once __DIR__.'/../../Base.php';

class DirectoryTest extends Base
{
    public function testIsCompatible()
    {
        $pluginDirectory = new Directory($this->container);
        $this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '1.0.29'), '1.0.28'));
        $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), '1.0.28'));
        $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '1.0.28'), 'master.1234'));
        $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), 'master'));
        $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), '1.0.32'));
        $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>=1.0.32'), '1.0.33'));
        $this->assertTrue($pluginDirectory->isCompatible(array('compatible_version' => '>1.0.32'), '1.0.33'));
        $this->assertFalse($pluginDirectory->isCompatible(array('compatible_version' => '>1.0.32'), '1.0.32'));
    }

    public function testGetAvailablePlugins()
    {
        $plugins = array(
            array(
                'title' => 'Plugin A',
                'compatible_version' => '1.0.30',
                'remote_install' => true,
            ),
            array(
                'title' => 'Plugin B',
                'compatible_version' => '1.0.29',
                'remote_install' => false,
            ),
        );

        $this->container['httpClient']
            ->expects($this->once())
            ->method('getJson')
            ->with('api_url')
            ->will($this->returnValue($plugins));

        $pluginDirectory = new Directory($this->container);
        $availablePlugins = $pluginDirectory->getAvailablePlugins('api_url');

        $this->assertCount(1, $availablePlugins);
        $this->assertEquals('Plugin A', $availablePlugins[0]['title']);
    }
}