Merge pull request #7764 from pradpnayak/CRM-16617-master
[civicrm-core.git] / tests / phpunit / CRM / Extension / BrowserTest.php
1 <?php
2
3 /**
4 * Class CRM_Extension_BrowserTest
5 * @group headless
6 */
7 class CRM_Extension_BrowserTest extends CiviUnitTestCase {
8 public function setUp() {
9 parent::setUp();
10 }
11
12 public function tearDown() {
13 parent::tearDown();
14 }
15
16 public function testDisabled() {
17 $browser = new CRM_Extension_Browser(FALSE, '/index.html', 'file:///itd/oesn/tmat/ter');
18 $this->assertEquals(FALSE, $browser->isEnabled());
19 $this->assertEquals(array(), $browser->checkRequirements());
20 $this->assertEquals(array(), $browser->getExtensions());
21 }
22
23 public function testCheckRequirements_BadCachedir_false() {
24 $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, FALSE);
25 $this->assertEquals(TRUE, $browser->isEnabled());
26 $reqs = $browser->checkRequirements();
27 $this->assertEquals(1, count($reqs));
28 }
29
30 public function testCheckRequirements_BadCachedir_nonexistent() {
31 $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, '/tot/all/yin/v/alid');
32 $this->assertEquals(TRUE, $browser->isEnabled());
33 $reqs = $browser->checkRequirements();
34 $this->assertEquals(1, count($reqs));
35 }
36
37 public function testGetExtensions_good() {
38 $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-'));
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
51 public function testGetExtension_good() {
52 $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-'));
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
61 public function testGetExtension_nonexistent() {
62 $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-'));
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 }
69
70 }