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 { |
39b959db | 8 | |
00be9182 | 9 | public function testDisabled() { |
72b14f38 | 10 | $browser = new CRM_Extension_Browser(FALSE, '/index.html', 'file:///itd/oesn/tmat/ter'); |
6a488035 | 11 | $this->assertEquals(FALSE, $browser->isEnabled()); |
9099cab3 CW |
12 | $this->assertEquals([], $browser->checkRequirements()); |
13 | $this->assertEquals([], $browser->getExtensions()); | |
6a488035 TO |
14 | } |
15 | ||
00be9182 | 16 | public function testCheckRequirements_BadCachedir_false() { |
929dd368 | 17 | $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, FALSE); |
6a488035 TO |
18 | $this->assertEquals(TRUE, $browser->isEnabled()); |
19 | $reqs = $browser->checkRequirements(); | |
20 | $this->assertEquals(1, count($reqs)); | |
21 | } | |
22 | ||
00be9182 | 23 | public function testCheckRequirements_BadCachedir_nonexistent() { |
929dd368 | 24 | $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, '/tot/all/yin/v/alid'); |
6a488035 TO |
25 | $this->assertEquals(TRUE, $browser->isEnabled()); |
26 | $reqs = $browser->checkRequirements(); | |
27 | $this->assertEquals(1, count($reqs)); | |
28 | } | |
29 | ||
00be9182 | 30 | public function testGetExtensions_good() { |
929dd368 | 31 | $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-')); |
6a488035 | 32 | $this->assertEquals(TRUE, $browser->isEnabled()); |
9099cab3 | 33 | $this->assertEquals([], $browser->checkRequirements()); |
6a488035 TO |
34 | $exts = $browser->getExtensions(); |
35 | $keys = array_keys($exts); | |
36 | sort($keys); | |
9099cab3 | 37 | $this->assertEquals(['test.crm.extension.browsertest.a', 'test.crm.extension.browsertest.b'], $keys); |
6a488035 TO |
38 | $this->assertEquals('report', $exts['test.crm.extension.browsertest.a']->type); |
39 | $this->assertEquals('module', $exts['test.crm.extension.browsertest.b']->type); | |
40 | $this->assertEquals('http://example.com/test.crm.extension.browsertest.a-0.1.zip', $exts['test.crm.extension.browsertest.a']->downloadUrl); | |
41 | $this->assertEquals('http://example.com/test.crm.extension.browsertest.b-1.2.zip', $exts['test.crm.extension.browsertest.b']->downloadUrl); | |
42 | } | |
43 | ||
00be9182 | 44 | public function testGetExtension_good() { |
929dd368 | 45 | $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-')); |
6a488035 | 46 | $this->assertEquals(TRUE, $browser->isEnabled()); |
9099cab3 | 47 | $this->assertEquals([], $browser->checkRequirements()); |
6a488035 TO |
48 | |
49 | $info = $browser->getExtension('test.crm.extension.browsertest.b'); | |
50 | $this->assertEquals('module', $info->type); | |
51 | $this->assertEquals('http://example.com/test.crm.extension.browsertest.b-1.2.zip', $info->downloadUrl); | |
52 | } | |
53 | ||
00be9182 | 54 | public function testGetExtension_nonexistent() { |
929dd368 | 55 | $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-')); |
6a488035 | 56 | $this->assertEquals(TRUE, $browser->isEnabled()); |
9099cab3 | 57 | $this->assertEquals([], $browser->checkRequirements()); |
6a488035 TO |
58 | |
59 | $info = $browser->getExtension('test.crm.extension.browsertest.nonexistent'); | |
60 | $this->assertEquals(NULL, $info); | |
61 | } | |
96025800 | 62 | |
6a488035 | 63 | } |