4 * Class CRM_Extension_MapperTest
7 class CRM_Extension_MapperTest
extends CiviUnitTestCase
{
8 public function setUp() {
10 list ($this->basedir
, $this->container
) = $this->_createContainer();
11 $this->mapper
= new CRM_Extension_Mapper($this->container
);
13 list ($this->basedir2
, $this->containerWithSlash
) = $this->_createContainer(NULL, NULL, '/');
14 $this->mapperWithSlash
= new CRM_Extension_Mapper($this->containerWithSlash
);
17 public function tearDown() {
21 public function testClassToKey() {
22 $this->assertEquals("test.foo.bar", $this->mapper
->classToKey('test_foo_bar'));
25 public function testClassToPath() {
26 $this->assertEquals("{$this->basedir}/weird/foobar/oddball.php", $this->mapper
->classToPath('test_foo_bar'));
29 public function testIsExtensionClass() {
30 $this->assertTrue($this->mapper
->isExtensionClass('test_foo_bar'));
31 $this->assertFalse($this->mapper
->isExtensionClass('test.foo.bar'));
32 $this->assertFalse($this->mapper
->isExtensionClass('CRM_Core_DAO'));
35 public function testIsExtensionKey() {
36 $this->assertFalse($this->mapper
->isExtensionKey('test_foo_bar'));
37 $this->assertTrue($this->mapper
->isExtensionKey('test.foo.bar'));
38 $this->assertFalse($this->mapper
->isExtensionKey('CRM_Core_DAO'));
41 public function testGetTemplateName() {
42 $this->assertEquals("oddball.tpl", $this->mapper
->getTemplateName('test_foo_bar'));
45 public function testGetTemplatePath() {
46 $this->assertEquals("{$this->basedir}/weird/foobar/templates", $this->mapper
->getTemplatePath('test_foo_bar'));
49 public function testKeyToClass() {
50 $this->assertEquals("test_foo_bar", $this->mapper
->keyToClass('test.foo.bar'));
53 public function testKeyToPath() {
54 $this->assertEquals("{$this->basedir}/weird/foobar/oddball.php", $this->mapper
->classToPath('test.foo.bar'));
55 $this->assertEquals("{$this->basedir2}/weird/foobar/oddball.php", $this->mapperWithSlash
->classToPath('test.foo.bar'));
58 public function testKeyToBasePath() {
59 $this->assertEquals("{$this->basedir}/weird/foobar", $this->mapper
->keyToBasePath('test.foo.bar'));
60 $this->assertEquals("{$this->basedir2}/weird/foobar", $this->mapperWithSlash
->keyToBasePath('test.foo.bar'));
63 $this->assertEquals(rtrim($civicrm_root, '/'), $this->mapper
->keyToBasePath('civicrm'));
66 public function testKeyToUrl() {
67 $this->assertEquals("http://example/basedir/weird/foobar", $this->mapper
->keyToUrl('test.foo.bar'));
68 $this->assertEquals("http://example/basedir/weird/foobar", $this->mapperWithSlash
->keyToUrl('test.foo.bar'));
70 $config = CRM_Core_Config
::singleton();
71 $this->assertEquals(rtrim($config->resourceBase
, '/'), $this->mapper
->keyToUrl('civicrm'));
72 $this->assertEquals(rtrim($config->resourceBase
, '/'), $this->mapperWithSlash
->keyToUrl('civicrm'));
76 * @param CRM_Utils_Cache_Interface $cache
77 * @param null $cacheKey
78 * @param string $appendPathGarbage
82 public function _createContainer(CRM_Utils_Cache_Interface
$cache = NULL, $cacheKey = NULL, $appendPathGarbage = '') {
84 $container = new CRM_Extension_Container_Static(array(
85 'test.foo.bar' => array(
86 'path' => '/path/to/test.foo.bar',
87 'resUrl' => 'http://resources/test.foo.bar',
91 $basedir = rtrim($this->createTempDir('ext-'), '/');
92 mkdir("$basedir/weird");
93 mkdir("$basedir/weird/foobar");
94 file_put_contents("$basedir/weird/foobar/info.xml", "<extension key='test.foo.bar' type='report'><file>oddball</file></extension>");
95 // not needed for now // file_put_contents("$basedir/weird/bar/oddball.php", "<?php\n");
96 $c = new CRM_Extension_Container_Basic($basedir . $appendPathGarbage, 'http://example/basedir' . $appendPathGarbage, $cache, $cacheKey);
97 return array($basedir, $c);