Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
aba1cd8b EM |
3 | /** |
4 | * Class CRM_Extension_BrowserTest | |
acb109b7 | 5 | * @group headless |
aba1cd8b | 6 | */ |
6a488035 | 7 | class CRM_Extension_BrowserTest extends CiviUnitTestCase { |
00be9182 | 8 | public function setUp() { |
6a488035 TO |
9 | parent::setUp(); |
10 | } | |
11 | ||
00be9182 | 12 | public function tearDown() { |
6a488035 TO |
13 | parent::tearDown(); |
14 | } | |
15 | ||
00be9182 | 16 | public function testDisabled() { |
72b14f38 | 17 | $browser = new CRM_Extension_Browser(FALSE, '/index.html', 'file:///itd/oesn/tmat/ter'); |
6a488035 TO |
18 | $this->assertEquals(FALSE, $browser->isEnabled()); |
19 | $this->assertEquals(array(), $browser->checkRequirements()); | |
20 | $this->assertEquals(array(), $browser->getExtensions()); | |
21 | } | |
22 | ||
00be9182 | 23 | public function testCheckRequirements_BadCachedir_false() { |
929dd368 | 24 | $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, FALSE); |
6a488035 TO |
25 | $this->assertEquals(TRUE, $browser->isEnabled()); |
26 | $reqs = $browser->checkRequirements(); | |
27 | $this->assertEquals(1, count($reqs)); | |
28 | } | |
29 | ||
00be9182 | 30 | public function testCheckRequirements_BadCachedir_nonexistent() { |
929dd368 | 31 | $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, '/tot/all/yin/v/alid'); |
6a488035 TO |
32 | $this->assertEquals(TRUE, $browser->isEnabled()); |
33 | $reqs = $browser->checkRequirements(); | |
34 | $this->assertEquals(1, count($reqs)); | |
35 | } | |
36 | ||
00be9182 | 37 | public function testGetExtensions_good() { |
929dd368 | 38 | $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-')); |
6a488035 TO |
39 | $this->assertEquals(TRUE, $browser->isEnabled()); |
40 | $this->assertEquals(array(), $browser->checkRequirements()); | |
41 | $exts = $browser->getExtensions(); | |
42 | $keys = array_keys($exts); | |
43 | sort($keys); | |
44 | $this->assertEquals(array('test.crm.extension.browsertest.a', 'test.crm.extension.browsertest.b'), $keys); | |
45 | $this->assertEquals('report', $exts['test.crm.extension.browsertest.a']->type); | |
46 | $this->assertEquals('module', $exts['test.crm.extension.browsertest.b']->type); | |
47 | $this->assertEquals('http://example.com/test.crm.extension.browsertest.a-0.1.zip', $exts['test.crm.extension.browsertest.a']->downloadUrl); | |
48 | $this->assertEquals('http://example.com/test.crm.extension.browsertest.b-1.2.zip', $exts['test.crm.extension.browsertest.b']->downloadUrl); | |
49 | } | |
50 | ||
00be9182 | 51 | public function testGetExtension_good() { |
929dd368 | 52 | $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-')); |
6a488035 TO |
53 | $this->assertEquals(TRUE, $browser->isEnabled()); |
54 | $this->assertEquals(array(), $browser->checkRequirements()); | |
55 | ||
56 | $info = $browser->getExtension('test.crm.extension.browsertest.b'); | |
57 | $this->assertEquals('module', $info->type); | |
58 | $this->assertEquals('http://example.com/test.crm.extension.browsertest.b-1.2.zip', $info->downloadUrl); | |
59 | } | |
60 | ||
00be9182 | 61 | public function testGetExtension_nonexistent() { |
929dd368 | 62 | $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-')); |
6a488035 TO |
63 | $this->assertEquals(TRUE, $browser->isEnabled()); |
64 | $this->assertEquals(array(), $browser->checkRequirements()); | |
65 | ||
66 | $info = $browser->getExtension('test.crm.extension.browsertest.nonexistent'); | |
67 | $this->assertEquals(NULL, $info); | |
68 | } | |
96025800 | 69 | |
6a488035 | 70 | } |