+--------------------------------------------------------------------+
| CiviCRM version 4.6 |
+--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014 |
+ | Copyright CiviCRM LLC (c) 2004-2015 |
+--------------------------------------------------------------------+
| This file is a part of CiviCRM. |
| |
| GNU Affero General Public License or the licensing of CiviCRM, |
| see the CiviCRM license FAQ at http://civicrm.org/licensing |
+--------------------------------------------------------------------+
-*/
+ */
require_once 'CiviTest/CiviUnitTestCase.php';
public function testAddScriptFile() {
$this->res
->addScriptFile('com.example.ext', 'foo%20bar.js', 0, 'testAddScriptFile')
- ->addScriptFile('com.example.ext', 'foo%20bar.js', 0, 'testAddScriptFile') // extra
+ ->addScriptFile('com.example.ext', 'foo%20bar.js', 0, 'testAddScriptFile')// extra
->addScriptFile('civicrm', 'foo%20bar.js', 0, 'testAddScriptFile');
$smarty = CRM_Core_Smarty::singleton();
*
* FIXME: This can't work because the tests run in English and CRM_Core_Resources optimizes
* away the English data from $settings['strings']
- public function testAddScriptFile_strings() {
- file_put_contents($this->mapper->keyToBasePath('com.example.ext') . '/hello.js', 'alert(ts("Hello world"));');
- $this->res->addScriptFile('com.example.ext', 'hello.js', 0, 'testAddScriptFile_strings');
- $settings = $this->res->getSettings();
- $expected = array('Hello world');
- $this->assertEquals($expected, $settings['strings']);
- }
+ * public function testAddScriptFile_strings() {
+ * file_put_contents($this->mapper->keyToBasePath('com.example.ext') . '/hello.js', 'alert(ts("Hello world"));');
+ * $this->res->addScriptFile('com.example.ext', 'hello.js', 0, 'testAddScriptFile_strings');
+ * $settings = $this->res->getSettings();
+ * $expected = array('Hello world');
+ * $this->assertEquals($expected, $settings['strings']);
+ * }
*/
+ /**
+ * Ensure that adding a script URL creates expected markup.
+ */
public function testAddScriptURL() {
$this->res
->addScriptUrl('/whiz/foo%20bar.js', 0, 'testAddScriptURL')
- ->addScriptUrl('/whiz/foo%20bar.js', 0, 'testAddScriptURL') // extra
+ ->addScriptUrl('/whiz/foo%20bar.js', 0, 'testAddScriptURL')// extra
->addScriptUrl('/whizbang/foo%20bar.js', 0, 'testAddScriptURL');
$smarty = CRM_Core_Smarty::singleton();
->addVars('food', array('fruit' => array('mine' => 'apple', 'ours' => 'banana')))
->addVars('food', array('fruit' => array('mine' => 'new apple', 'yours' => 'orange')));
$this->assertTreeEquals(
- array('vars' => array('food' => array('fruit' => array('yours' => 'orange', 'mine' => 'new apple', 'ours' => 'banana')))),
+ array(
+ 'vars' => array(
+ 'food' => array(
+ 'fruit' => array(
+ 'yours' => 'orange',
+ 'mine' => 'new apple',
+ 'ours' => 'banana',
+ ),
+ ),
+ ),
+ ),
$this->res->getSettings()
);
}
}
public function testAddSettingFactory() {
- $this->res->addSettingsFactory(function() {
+ $this->res->addSettingsFactory(function () {
return array('fruit' => array('yours' => 'orange'));
});
- $this->res->addSettingsFactory(function() {
+ $this->res->addSettingsFactory(function () {
return array('fruit' => array('mine' => 'apple'));
});
$this->res->addSetting(array('fruit' => array('mine' => 'apple')));
$muckableValue = array('fruit' => array('yours' => 'orange', 'theirs' => 'apricot'));
- $this->res->addSettingsFactory(function() use (&$muckableValue) {
+ $this->res->addSettingsFactory(function () use (&$muckableValue) {
return $muckableValue;
});
$actual = $this->res->getSettings();
public function testAddStyleFile() {
$this->res
->addStyleFile('com.example.ext', 'foo%20bar.css', 0, 'testAddStyleFile')
- ->addStyleFile('com.example.ext', 'foo%20bar.css', 0, 'testAddStyleFile') // extra
+ ->addStyleFile('com.example.ext', 'foo%20bar.css', 0, 'testAddStyleFile')// extra
->addStyleFile('civicrm', 'foo%20bar.css', 0, 'testAddStyleFile');
$smarty = CRM_Core_Smarty::singleton();
public function testAddStyleURL() {
$this->res
->addStyleUrl('/whiz/foo%20bar.css', 0, 'testAddStyleURL')
- ->addStyleUrl('/whiz/foo%20bar.css', 0, 'testAddStyleURL') // extra
+ ->addStyleUrl('/whiz/foo%20bar.css', 0, 'testAddStyleURL')// extra
->addStyleUrl('/whizbang/foo%20bar.css', 0, 'testAddStyleURL');
$smarty = CRM_Core_Smarty::singleton();
$this->assertEquals('http://ext-dir/com.example.ext/', $actual);
}
+ public function testGlob() {
+ $this->assertEquals(
+ array('info.xml'),
+ $this->res->glob('com.example.ext', 'info.xml')
+ );
+ $this->assertEquals(
+ array('js/example.js'),
+ $this->res->glob('com.example.ext', 'js/*.js')
+ );
+ $this->assertEquals(
+ array('js/example.js'),
+ $this->res->glob('com.example.ext', array('js/*.js'))
+ );
+ }
+
/**
* @param CRM_Utils_Cache_Interface $cache
- * @param null $cacheKey
+ * @param string $cacheKey
*
- * @internal param string $appendPathGarbage
- * @return array(string $basedir, CRM_Extension_Container_Interface, CRM_Extension_Mapper)
+ * @return array
+ * [string $basedir, CRM_Extension_Container_Interface, CRM_Extension_Mapper]
*/
public function _createMapper(CRM_Utils_Cache_Interface $cache = NULL, $cacheKey = NULL) {
$basedir = rtrim($this->createTempDir('ext-'), '/');
mkdir("$basedir/com.example.ext");
+ mkdir("$basedir/com.example.ext/js");
file_put_contents("$basedir/com.example.ext/info.xml", "<extension key='com.example.ext' type='report'><file>oddball</file></extension>");
+ file_put_contents("$basedir/com.example.ext/js/example.js", "alert('Boo!');");
// not needed for now // file_put_contents("$basedir/weird/bar/oddball.php", "<?php\n");
$c = new CRM_Extension_Container_Basic($basedir, 'http://ext-dir', $cache, $cacheKey);
$mapper = new CRM_Extension_Mapper($c, NULL, NULL, '/pathto/civicrm', 'http://core-app');