3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 +--------------------------------------------------------------------+
27 require_once 'CiviTest/CiviUnitTestCase.php';
29 class CRM_Extension_Container_CollectionTest
extends CiviUnitTestCase
{
38 function testGetKeysEmpty() {
39 $c = new CRM_Extension_Container_Collection(array());
40 $this->assertEquals($c->getKeys(), array());
43 function testGetKeys() {
44 $c = $this->_createContainer();
45 $this->assertEquals(array('test.conflict', 'test.whiz', 'test.whizbang', 'test.foo', 'test.foo.bar'), $c->getKeys());
48 function testGetPath() {
49 $c = $this->_createContainer();
51 $c->getPath('un.kno.wn');
52 } catch (CRM_Extension_Exception
$e) {
55 $this->assertTrue(is_object($exc), 'Expected exception');
57 $this->assertEquals("/path/to/foo", $c->getPath('test.foo'));
58 $this->assertEquals("/path/to/bar", $c->getPath('test.foo.bar'));
59 $this->assertEquals("/path/to/whiz", $c->getPath('test.whiz'));
60 $this->assertEquals("/path/to/whizbang", $c->getPath('test.whizbang'));
61 $this->assertEquals("/path/to/conflict-b", $c->getPath('test.conflict'));
64 function testGetResUrl() {
65 $c = $this->_createContainer();
67 $c->getResUrl('un.kno.wn');
68 } catch (CRM_Extension_Exception
$e) {
71 $this->assertTrue(is_object($exc), 'Expected exception');
73 $this->assertEquals('http://foo', $c->getResUrl('test.foo'));
74 $this->assertEquals('http://foobar', $c->getResUrl('test.foo.bar'));
75 $this->assertEquals('http://whiz', $c->getResUrl('test.whiz'));
76 $this->assertEquals('http://whizbang', $c->getResUrl('test.whizbang'));
77 $this->assertEquals('http://conflict-b', $c->getResUrl('test.conflict'));
80 function testCaching() {
81 $cache = new CRM_Utils_Cache_Arraycache(array());
82 $this->assertTrue(!is_array($cache->get('ext-collection')));
83 $c = $this->_createContainer($cache, 'ext-collection');
84 $this->assertEquals('http://foo', $c->getResUrl('test.foo'));
85 $this->assertTrue(is_array($cache->get('ext-collection')));
87 $cacheData = $cache->get('ext-collection');
88 $this->assertEquals('a', $cacheData['test.foo']); // 'test.foo' was defined in the 'a' container
89 $this->assertEquals('b', $cacheData['test.whiz']); // 'test.whiz' was defined in the 'b' container
92 function _createContainer(CRM_Utils_Cache_Interface
$cache = NULL, $cacheKey = NULL) {
93 $containers = array();
94 $containers['a'] = new CRM_Extension_Container_Static(array(
96 'path' => '/path/to/foo',
97 'resUrl' => 'http://foo',
99 'test.foo.bar' => array(
100 'path' => '/path/to/bar',
101 'resUrl' => 'http://foobar',
104 $containers['b'] = new CRM_Extension_Container_Static(array(
105 'test.whiz' => array(
106 'path' => '/path/to/whiz',
107 'resUrl' => 'http://whiz',
109 'test.whizbang' => array(
110 'path' => '/path/to/whizbang',
111 'resUrl' => 'http://whizbang',
113 'test.conflict' => array(
114 'path' => '/path/to/conflict-b',
115 'resUrl' => 'http://conflict-b',
118 $containers['c'] = new CRM_Extension_Container_Static(array(
119 'test.conflict' => array(
120 'path' => '/path/to/conflict-c',
121 'resUrl' => 'http://conflict-c',
124 $c = new CRM_Extension_Container_Collection($containers, $cache, $cacheKey);