3 require_once 'CiviTest/CiviUnitTestCase.php';
6 * Class CRM_Extension_MapperTest
8 class CRM_Extension_MapperTest
extends CiviUnitTestCase
{
11 list ($this->basedir
, $this->container
) = $this->_createContainer();
12 $this->mapper
= new CRM_Extension_Mapper($this->container
);
14 list ($this->basedir2
, $this->containerWithSlash
) = $this->_createContainer(NULL, NULL, '/');
15 $this->mapperWithSlash
= new CRM_Extension_Mapper($this->containerWithSlash
);
22 function testClassToKey() {
23 $this->assertEquals("test.foo.bar", $this->mapper
->classToKey('test_foo_bar'));
26 function testClassToPath() {
27 $this->assertEquals("{$this->basedir}/weird/foobar/oddball.php", $this->mapper
->classToPath('test_foo_bar'));
30 function testIsExtensionClass() {
31 $this->assertTrue($this->mapper
->isExtensionClass('test_foo_bar'));
32 $this->assertFalse($this->mapper
->isExtensionClass('test.foo.bar'));
33 $this->assertFalse($this->mapper
->isExtensionClass('CRM_Core_DAO'));
36 function testIsExtensionKey() {
37 $this->assertFalse($this->mapper
->isExtensionKey('test_foo_bar'));
38 $this->assertTrue($this->mapper
->isExtensionKey('test.foo.bar'));
39 $this->assertFalse($this->mapper
->isExtensionKey('CRM_Core_DAO'));
42 function testGetTemplateName() {
43 $this->assertEquals("oddball.tpl", $this->mapper
->getTemplateName('test_foo_bar'));
46 function testGetTemplatePath() {
47 $this->assertEquals("{$this->basedir}/weird/foobar/templates", $this->mapper
->getTemplatePath('test_foo_bar'));
50 function testKeyToClass() {
51 $this->assertEquals("test_foo_bar", $this->mapper
->keyToClass('test.foo.bar'));
54 function testKeyToPath() {
55 $this->assertEquals("{$this->basedir}/weird/foobar/oddball.php", $this->mapper
->classToPath('test.foo.bar'));
56 $this->assertEquals("{$this->basedir2}/weird/foobar/oddball.php", $this->mapperWithSlash
->classToPath('test.foo.bar'));
59 function testKeyToBasePath() {
60 $this->assertEquals("{$this->basedir}/weird/foobar", $this->mapper
->keyToBasePath('test.foo.bar'));
61 $this->assertEquals("{$this->basedir2}/weird/foobar", $this->mapperWithSlash
->keyToBasePath('test.foo.bar'));
64 $this->assertEquals(rtrim($civicrm_root, '/'), $this->mapper
->keyToBasePath('civicrm'));
67 function testKeyToUrl() {
68 $this->assertEquals("http://example/basedir/weird/foobar", $this->mapper
->keyToUrl('test.foo.bar'));
69 $this->assertEquals("http://example/basedir/weird/foobar", $this->mapperWithSlash
->keyToUrl('test.foo.bar'));
71 $config = CRM_Core_Config
::singleton();
72 $this->assertEquals(rtrim($config->resourceBase
, '/'), $this->mapper
->keyToUrl('civicrm'));
73 $this->assertEquals(rtrim($config->resourceBase
, '/'), $this->mapperWithSlash
->keyToUrl('civicrm'));
77 * @param CRM_Utils_Cache_Interface $cache
78 * @param null $cacheKey
79 * @param string $appendPathGarbage
83 function _createContainer(CRM_Utils_Cache_Interface
$cache = NULL, $cacheKey = NULL, $appendPathGarbage = '') {
85 $container = new CRM_Extension_Container_Static(array(
86 'test.foo.bar' => array(
87 'path' => '/path/to/test.foo.bar',
88 'resUrl' => 'http://resources/test.foo.bar',
92 $basedir = rtrim($this->createTempDir('ext-'), '/');
93 mkdir("$basedir/weird");
94 mkdir("$basedir/weird/foobar");
95 file_put_contents("$basedir/weird/foobar/info.xml", "<extension key='test.foo.bar' type='report'><file>oddball</file></extension>");
96 // not needed for now // file_put_contents("$basedir/weird/bar/oddball.php", "<?php\n");
97 $c = new CRM_Extension_Container_Basic($basedir . $appendPathGarbage, 'http://example/basedir' . $appendPathGarbage, $cache, $cacheKey);
98 return array($basedir, $c);