Merge pull request #15884 from kainuk/issue-lab-1365
[civicrm-core.git] / tests / phpunit / CRM / Extension / Container / StaticTest.php
CommitLineData
6a488035
TO
1<?php
2
aba1cd8b
EM
3/**
4 * Class CRM_Extension_Container_StaticTest
acb109b7 5 * @group headless
aba1cd8b 6 */
6a488035 7class CRM_Extension_Container_StaticTest extends CiviUnitTestCase {
39b959db 8
00be9182 9 public function setUp() {
6a488035
TO
10 parent::setUp();
11 }
12
00be9182 13 public function tearDown() {
6a488035
TO
14 parent::tearDown();
15 }
16
00be9182 17 public function testGetKeysEmpty() {
9099cab3
CW
18 $c = new CRM_Extension_Container_Static([]);
19 $this->assertEquals($c->getKeys(), []);
6a488035
TO
20 }
21
00be9182 22 public function testGetKeys() {
6a488035 23 $c = $this->_createContainer();
9099cab3 24 $this->assertEquals($c->getKeys(), ['test.foo', 'test.foo.bar']);
6a488035
TO
25 }
26
00be9182 27 public function testGetPath() {
6a488035
TO
28 $c = $this->_createContainer();
29 try {
30 $c->getPath('un.kno.wn');
0db6c3e1
TO
31 }
32 catch (CRM_Extension_Exception $e) {
6a488035
TO
33 $exc = $e;
34 }
35 $this->assertTrue(is_object($exc), 'Expected exception');
36
37 $this->assertEquals("/path/to/foo", $c->getPath('test.foo'));
38 $this->assertEquals("/path/to/bar", $c->getPath('test.foo.bar'));
39 }
40
00be9182 41 public function testGetResUrl() {
6a488035
TO
42 $c = $this->_createContainer();
43 try {
44 $c->getResUrl('un.kno.wn');
0db6c3e1
TO
45 }
46 catch (CRM_Extension_Exception $e) {
6a488035
TO
47 $exc = $e;
48 }
49 $this->assertTrue(is_object($exc), 'Expected exception');
50
51 $this->assertEquals('http://foo', $c->getResUrl('test.foo'));
52 $this->assertEquals('http://foobar', $c->getResUrl('test.foo.bar'));
53 }
54
4cbe18b8
EM
55 /**
56 * @return CRM_Extension_Container_Static
57 */
00be9182 58 public function _createContainer() {
9099cab3
CW
59 return new CRM_Extension_Container_Static([
60 'test.foo' => [
6a488035
TO
61 'path' => '/path/to/foo',
62 'resUrl' => 'http://foo',
9099cab3
CW
63 ],
64 'test.foo.bar' => [
6a488035
TO
65 'path' => '/path/to/bar',
66 'resUrl' => 'http://foobar',
9099cab3
CW
67 ],
68 ]);
6a488035 69 }
96025800 70
6a488035 71}