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