Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
b6708aeb | 2 | /* |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | +--------------------------------------------------------------------+ | |
26 | */ | |
6a488035 TO |
27 | require_once 'CiviTest/CiviUnitTestCase.php'; |
28 | ||
29 | class CRM_Extension_Container_CollectionTest extends CiviUnitTestCase { | |
30 | function setUp() { | |
31 | parent::setUp(); | |
32 | } | |
33 | ||
34 | function tearDown() { | |
35 | parent::tearDown(); | |
36 | } | |
37 | ||
38 | function testGetKeysEmpty() { | |
39 | $c = new CRM_Extension_Container_Collection(array()); | |
40 | $this->assertEquals($c->getKeys(), array()); | |
41 | } | |
42 | ||
43 | function testGetKeys() { | |
44 | $c = $this->_createContainer(); | |
b6708aeb | 45 | $this->assertEquals(array('test.conflict', 'test.whiz', 'test.whizbang', 'test.foo', 'test.foo.bar'), $c->getKeys()); |
6a488035 TO |
46 | } |
47 | ||
48 | function testGetPath() { | |
49 | $c = $this->_createContainer(); | |
50 | try { | |
51 | $c->getPath('un.kno.wn'); | |
52 | } catch (CRM_Extension_Exception $e) { | |
53 | $exc = $e; | |
54 | } | |
55 | $this->assertTrue(is_object($exc), 'Expected exception'); | |
56 | ||
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')); | |
62 | } | |
63 | ||
64 | function testGetResUrl() { | |
65 | $c = $this->_createContainer(); | |
66 | try { | |
67 | $c->getResUrl('un.kno.wn'); | |
68 | } catch (CRM_Extension_Exception $e) { | |
69 | $exc = $e; | |
70 | } | |
71 | $this->assertTrue(is_object($exc), 'Expected exception'); | |
72 | ||
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')); | |
78 | } | |
79 | ||
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'))); | |
86 | ||
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 | |
90 | } | |
91 | ||
92 | function _createContainer(CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) { | |
93 | $containers = array(); | |
94 | $containers['a'] = new CRM_Extension_Container_Static(array( | |
95 | 'test.foo' => array( | |
96 | 'path' => '/path/to/foo', | |
97 | 'resUrl' => 'http://foo', | |
98 | ), | |
99 | 'test.foo.bar' => array( | |
100 | 'path' => '/path/to/bar', | |
101 | 'resUrl' => 'http://foobar', | |
102 | ), | |
103 | )); | |
104 | $containers['b'] = new CRM_Extension_Container_Static(array( | |
105 | 'test.whiz' => array( | |
106 | 'path' => '/path/to/whiz', | |
107 | 'resUrl' => 'http://whiz', | |
108 | ), | |
109 | 'test.whizbang' => array( | |
110 | 'path' => '/path/to/whizbang', | |
111 | 'resUrl' => 'http://whizbang', | |
112 | ), | |
113 | 'test.conflict' => array( | |
114 | 'path' => '/path/to/conflict-b', | |
115 | 'resUrl' => 'http://conflict-b', | |
116 | ), | |
117 | )); | |
118 | $containers['c'] = new CRM_Extension_Container_Static(array( | |
119 | 'test.conflict' => array( | |
120 | 'path' => '/path/to/conflict-c', | |
121 | 'resUrl' => 'http://conflict-c', | |
122 | ), | |
123 | )); | |
124 | $c = new CRM_Extension_Container_Collection($containers, $cache, $cacheKey); | |
125 | return $c; | |
126 | } | |
127 | } |