Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
2fe49090 | 4 | | CiviCRM version 5 | |
b6708aeb | 5 | +--------------------------------------------------------------------+ |
6b83d5bd | 6 | | Copyright CiviCRM LLC (c) 2004-2019 | |
b6708aeb | 7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
e70a7fc0 | 26 | */ |
6a488035 | 27 | |
e9479dcf EM |
28 | /** |
29 | * Class CRM_Extension_Container_CollectionTest | |
acb109b7 | 30 | * @group headless |
e9479dcf | 31 | */ |
6a488035 | 32 | class CRM_Extension_Container_CollectionTest extends CiviUnitTestCase { |
92915c55 | 33 | |
00be9182 | 34 | public function setUp() { |
6a488035 TO |
35 | parent::setUp(); |
36 | } | |
37 | ||
00be9182 | 38 | public function tearDown() { |
6a488035 TO |
39 | parent::tearDown(); |
40 | } | |
41 | ||
00be9182 | 42 | public function testGetKeysEmpty() { |
9099cab3 CW |
43 | $c = new CRM_Extension_Container_Collection([]); |
44 | $this->assertEquals($c->getKeys(), []); | |
6a488035 TO |
45 | } |
46 | ||
00be9182 | 47 | public function testGetKeys() { |
6a488035 | 48 | $c = $this->_createContainer(); |
9099cab3 | 49 | $this->assertEquals([ |
39b959db SL |
50 | 'test.conflict', |
51 | 'test.whiz', | |
52 | 'test.whizbang', | |
53 | 'test.foo', | |
54 | 'test.foo.bar', | |
9099cab3 | 55 | ], $c->getKeys()); |
6a488035 TO |
56 | } |
57 | ||
00be9182 | 58 | public function testGetPath() { |
6a488035 TO |
59 | $c = $this->_createContainer(); |
60 | try { | |
61 | $c->getPath('un.kno.wn'); | |
0db6c3e1 TO |
62 | } |
63 | catch (CRM_Extension_Exception $e) { | |
6a488035 TO |
64 | $exc = $e; |
65 | } | |
66 | $this->assertTrue(is_object($exc), 'Expected exception'); | |
67 | ||
68 | $this->assertEquals("/path/to/foo", $c->getPath('test.foo')); | |
69 | $this->assertEquals("/path/to/bar", $c->getPath('test.foo.bar')); | |
70 | $this->assertEquals("/path/to/whiz", $c->getPath('test.whiz')); | |
71 | $this->assertEquals("/path/to/whizbang", $c->getPath('test.whizbang')); | |
72 | $this->assertEquals("/path/to/conflict-b", $c->getPath('test.conflict')); | |
73 | } | |
74 | ||
00be9182 | 75 | public function testGetResUrl() { |
6a488035 TO |
76 | $c = $this->_createContainer(); |
77 | try { | |
78 | $c->getResUrl('un.kno.wn'); | |
0db6c3e1 TO |
79 | } |
80 | catch (CRM_Extension_Exception $e) { | |
6a488035 TO |
81 | $exc = $e; |
82 | } | |
83 | $this->assertTrue(is_object($exc), 'Expected exception'); | |
84 | ||
85 | $this->assertEquals('http://foo', $c->getResUrl('test.foo')); | |
86 | $this->assertEquals('http://foobar', $c->getResUrl('test.foo.bar')); | |
87 | $this->assertEquals('http://whiz', $c->getResUrl('test.whiz')); | |
88 | $this->assertEquals('http://whizbang', $c->getResUrl('test.whizbang')); | |
89 | $this->assertEquals('http://conflict-b', $c->getResUrl('test.conflict')); | |
90 | } | |
91 | ||
00be9182 | 92 | public function testCaching() { |
9099cab3 | 93 | $cache = new CRM_Utils_Cache_Arraycache([]); |
6a488035 TO |
94 | $this->assertTrue(!is_array($cache->get('ext-collection'))); |
95 | $c = $this->_createContainer($cache, 'ext-collection'); | |
96 | $this->assertEquals('http://foo', $c->getResUrl('test.foo')); | |
97 | $this->assertTrue(is_array($cache->get('ext-collection'))); | |
98 | ||
99 | $cacheData = $cache->get('ext-collection'); | |
39b959db SL |
100 | // 'test.foo' was defined in the 'a' container |
101 | $this->assertEquals('a', $cacheData['test.foo']); | |
102 | // 'test.whiz' was defined in the 'b' container | |
103 | $this->assertEquals('b', $cacheData['test.whiz']); | |
6a488035 TO |
104 | } |
105 | ||
4cbe18b8 EM |
106 | /** |
107 | * @param CRM_Utils_Cache_Interface $cache | |
108 | * @param null $cacheKey | |
109 | * | |
110 | * @return CRM_Extension_Container_Collection | |
111 | */ | |
00be9182 | 112 | public function _createContainer(CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) { |
9099cab3 CW |
113 | $containers = []; |
114 | $containers['a'] = new CRM_Extension_Container_Static([ | |
115 | 'test.foo' => [ | |
6a488035 TO |
116 | 'path' => '/path/to/foo', |
117 | 'resUrl' => 'http://foo', | |
9099cab3 CW |
118 | ], |
119 | 'test.foo.bar' => [ | |
6a488035 TO |
120 | 'path' => '/path/to/bar', |
121 | 'resUrl' => 'http://foobar', | |
9099cab3 CW |
122 | ], |
123 | ]); | |
124 | $containers['b'] = new CRM_Extension_Container_Static([ | |
125 | 'test.whiz' => [ | |
6a488035 TO |
126 | 'path' => '/path/to/whiz', |
127 | 'resUrl' => 'http://whiz', | |
9099cab3 CW |
128 | ], |
129 | 'test.whizbang' => [ | |
6a488035 TO |
130 | 'path' => '/path/to/whizbang', |
131 | 'resUrl' => 'http://whizbang', | |
9099cab3 CW |
132 | ], |
133 | 'test.conflict' => [ | |
6a488035 TO |
134 | 'path' => '/path/to/conflict-b', |
135 | 'resUrl' => 'http://conflict-b', | |
9099cab3 CW |
136 | ], |
137 | ]); | |
138 | $containers['c'] = new CRM_Extension_Container_Static([ | |
139 | 'test.conflict' => [ | |
6a488035 TO |
140 | 'path' => '/path/to/conflict-c', |
141 | 'resUrl' => 'http://conflict-c', | |
9099cab3 CW |
142 | ], |
143 | ]); | |
92915c55 | 144 | $c = new CRM_Extension_Container_Collection($containers, $cache, $cacheKey); |
6a488035 TO |
145 | return $c; |
146 | } | |
96025800 | 147 | |
6a488035 | 148 | } |