Merge pull request #19870 from totten/master-psr0
[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
9 public function setUp() {
10 parent::setUp();
11 }
12
13 public function tearDown(): void {
14 parent::tearDown();
15 }
16
17 public function testDisabled() {
18 $browser = new CRM_Extension_Browser(FALSE, '/index.html', 'file:///itd/oesn/tmat/ter');
19 $this->assertEquals(FALSE, $browser->isEnabled());
20 $this->assertEquals([], $browser->checkRequirements());
21 $this->assertEquals([], $browser->getExtensions());
22 }
23
24 public function testCheckRequirements_BadCachedir_false() {
25 $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, FALSE);
26 $this->assertEquals(TRUE, $browser->isEnabled());
27 $reqs = $browser->checkRequirements();
28 $this->assertEquals(1, count($reqs));
29 }
30
31 public function testCheckRequirements_BadCachedir_nonexistent() {
32 $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, '/tot/all/yin/v/alid');
33 $this->assertEquals(TRUE, $browser->isEnabled());
34 $reqs = $browser->checkRequirements();
35 $this->assertEquals(1, count($reqs));
36 }
37
38 public function testGetExtensions_good() {
39 $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-'));
40 $this->assertEquals(TRUE, $browser->isEnabled());
41 $this->assertEquals([], $browser->checkRequirements());
42 $exts = $browser->getExtensions();
43 $keys = array_keys($exts);
44 sort($keys);
45 $this->assertEquals(['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 public function testGetExtension_good() {
53 $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-'));
54 $this->assertEquals(TRUE, $browser->isEnabled());
55 $this->assertEquals([], $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 public function testGetExtension_nonexistent() {
63 $browser = new CRM_Extension_Browser('file://' . dirname(__FILE__) . '/dataset/good-repository', NULL, $this->createTempDir('ext-cache-'));
64 $this->assertEquals(TRUE, $browser->isEnabled());
65 $this->assertEquals([], $browser->checkRequirements());
66
67 $info = $browser->getExtension('test.crm.extension.browsertest.nonexistent');
68 $this->assertEquals(NULL, $info);
69 }
70
71 }