3 +--------------------------------------------------------------------+
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2019 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
29 * Class CRM_Extension_Container_CollectionTest
32 class CRM_Extension_Container_CollectionTest
extends CiviUnitTestCase
{
34 public function setUp() {
38 public function tearDown() {
42 public function testGetKeysEmpty() {
43 $c = new CRM_Extension_Container_Collection([]);
44 $this->assertEquals($c->getKeys(), []);
47 public function testGetKeys() {
48 $c = $this->_createContainer();
58 public function testGetPath() {
59 $c = $this->_createContainer();
61 $c->getPath('un.kno.wn');
63 catch (CRM_Extension_Exception
$e) {
66 $this->assertTrue(is_object($exc), 'Expected exception');
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'));
75 public function testGetResUrl() {
76 $c = $this->_createContainer();
78 $c->getResUrl('un.kno.wn');
80 catch (CRM_Extension_Exception
$e) {
83 $this->assertTrue(is_object($exc), 'Expected exception');
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'));
92 public function testCaching() {
93 $cache = new CRM_Utils_Cache_Arraycache([]);
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')));
99 $cacheData = $cache->get('ext-collection');
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']);
107 * @param CRM_Utils_Cache_Interface $cache
108 * @param null $cacheKey
110 * @return CRM_Extension_Container_Collection
112 public function _createContainer(CRM_Utils_Cache_Interface
$cache = NULL, $cacheKey = NULL) {
114 $containers['a'] = new CRM_Extension_Container_Static([
116 'path' => '/path/to/foo',
117 'resUrl' => 'http://foo',
120 'path' => '/path/to/bar',
121 'resUrl' => 'http://foobar',
124 $containers['b'] = new CRM_Extension_Container_Static([
126 'path' => '/path/to/whiz',
127 'resUrl' => 'http://whiz',
130 'path' => '/path/to/whizbang',
131 'resUrl' => 'http://whizbang',
134 'path' => '/path/to/conflict-b',
135 'resUrl' => 'http://conflict-b',
138 $containers['c'] = new CRM_Extension_Container_Static([
140 'path' => '/path/to/conflict-c',
141 'resUrl' => 'http://conflict-c',
144 $c = new CRM_Extension_Container_Collection($containers, $cache, $cacheKey);