<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 5 |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2019 |
- +--------------------------------------------------------------------+
- | This file is a part of CiviCRM. |
- | |
- | CiviCRM is free software; you can copy, modify, and distribute it |
- | under the terms of the GNU Affero General Public License |
- | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
+ | Copyright CiviCRM LLC. All rights reserved. |
| |
- | CiviCRM is distributed in the hope that it will be useful, but |
- | WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
- | See the GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public |
- | License and the CiviCRM Licensing Exception along |
- | with this program; if not, contact CiviCRM LLC |
- | at info[AT]civicrm[DOT]org. If you have questions about the |
- | GNU Affero General Public License or the licensing of CiviCRM, |
- | see the CiviCRM license FAQ at http://civicrm.org/licensing |
+ | This work is published under the GNU AGPLv3 license with some |
+ | permitted exceptions and without any warranty. For full license |
+ | and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
protected $mapper;
/**
- * @var string for testing cache buster generation
+ * @var string
+ * For testing cache buster generation
*/
protected $cacheBusterString = 'xBkdk3';
parent::setUp();
list ($this->basedir, $this->container, $this->mapper) = $this->_createMapper();
- $cache = new CRM_Utils_Cache_Arraycache(array());
+ $cache = new CRM_Utils_Cache_Arraycache([]);
$this->res = new CRM_Core_Resources($this->mapper, $cache, NULL);
$this->res->setCacheCode('resTest');
CRM_Core_Resources::singleton($this->res);
public function testAddVars() {
$this->res
- ->addVars('food', array('fruit' => array('mine' => 'apple', 'ours' => 'banana')))
- ->addVars('food', array('fruit' => array('mine' => 'new apple', 'yours' => 'orange')));
+ ->addVars('food', ['fruit' => ['mine' => 'apple', 'ours' => 'banana']])
+ ->addVars('food', ['fruit' => ['mine' => 'new apple', 'yours' => 'orange']]);
$this->assertTreeEquals(
- array(
- 'vars' => array(
- 'food' => array(
- 'fruit' => array(
+ [
+ 'vars' => [
+ 'food' => [
+ 'fruit' => [
'yours' => 'orange',
'mine' => 'new apple',
'ours' => 'banana',
- ),
- ),
- ),
- ),
+ ],
+ ],
+ ],
+ ],
$this->res->getSettings()
);
}
public function testAddSetting() {
$this->res
- ->addSetting(array('fruit' => array('mine' => 'apple')))
- ->addSetting(array('fruit' => array('yours' => 'orange')));
+ ->addSetting(['fruit' => ['mine' => 'apple']])
+ ->addSetting(['fruit' => ['yours' => 'orange']]);
$this->assertTreeEquals(
- array('fruit' => array('yours' => 'orange', 'mine' => 'apple')),
+ ['fruit' => ['yours' => 'orange', 'mine' => 'apple']],
$this->res->getSettings()
);
$actual = $this->res->renderSetting();
- $expected = json_encode(array('fruit' => array('yours' => 'orange', 'mine' => 'apple')));
+ $expected = json_encode(['fruit' => ['yours' => 'orange', 'mine' => 'apple']]);
$this->assertTrue(strpos($actual, $expected) !== FALSE);
}
$test->assertEquals('apple', $event->data['fruit']['mine']);
$event->data['fruit']['mine'] = 'banana';
});
- $this->res->addSetting(array('fruit' => array('mine' => 'apple')));
+ $this->res->addSetting(['fruit' => ['mine' => 'apple']]);
$settings = $this->res->getSettings();
- $this->assertTreeEquals(array('fruit' => array('mine' => 'banana')), $settings);
+ $this->assertTreeEquals(['fruit' => ['mine' => 'banana']], $settings);
}
public function testAddSettingFactory() {
$this->res->addSettingsFactory(function () {
- return array('fruit' => array('yours' => 'orange'));
+ return ['fruit' => ['yours' => 'orange']];
});
$this->res->addSettingsFactory(function () {
- return array('fruit' => array('mine' => 'apple'));
+ return ['fruit' => ['mine' => 'apple']];
});
$actual = $this->res->getSettings();
- $expected = array('fruit' => array('yours' => 'orange', 'mine' => 'apple'));
+ $expected = ['fruit' => ['yours' => 'orange', 'mine' => 'apple']];
$this->assertTreeEquals($expected, $actual);
}
public function testAddSettingAndSettingFactory() {
- $this->res->addSetting(array('fruit' => array('mine' => 'apple')));
+ $this->res->addSetting(['fruit' => ['mine' => 'apple']]);
- $muckableValue = array('fruit' => array('yours' => 'orange', 'theirs' => 'apricot'));
+ $muckableValue = ['fruit' => ['yours' => 'orange', 'theirs' => 'apricot']];
$this->res->addSettingsFactory(function () use (&$muckableValue) {
return $muckableValue;
});
$actual = $this->res->getSettings();
- $expected = array('fruit' => array('mine' => 'apple', 'yours' => 'orange', 'theirs' => 'apricot'));
+ $expected = ['fruit' => ['mine' => 'apple', 'yours' => 'orange', 'theirs' => 'apricot']];
$this->assertTreeEquals($expected, $actual);
// note: the setting is not fixed based on what the factory returns when registered; it's based
// on what the factory returns when getSettings is called
- $muckableValue = array('fruit' => array('yours' => 'banana'));
+ $muckableValue = ['fruit' => ['yours' => 'banana']];
$actual = $this->res->getSettings();
- $expected = array('fruit' => array('mine' => 'apple', 'yours' => 'banana'));
+ $expected = ['fruit' => ['mine' => 'apple', 'yours' => 'banana']];
$this->assertTreeEquals($expected, $actual);
}
$actual = $smarty->fetch('string:{crmResURL ext=com.example.ext}');
$this->assertEquals('http://ext-dir/com.example.ext/', $actual);
+
+ $actual = $smarty->fetch('string:{crmResURL expr="[civicrm.root]/foo"}');
+ $this->assertEquals(Civi::paths()->getUrl('[civicrm.root]/foo'), $actual);
}
public function testGlob() {
$this->assertEquals(
- array('info.xml'),
+ ['info.xml'],
$this->res->glob('com.example.ext', 'info.xml')
);
$this->assertEquals(
- array('js/example.js'),
+ ['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'))
+ ['js/example.js'],
+ $this->res->glob('com.example.ext', ['js/*.js'])
);
}
}
public function ajaxModeData() {
- return array(
- array(array('q' => 'civicrm/ajax/foo'), TRUE),
- array(array('q' => 'civicrm/angularprofiles/template'), TRUE),
- array(array('q' => 'civicrm/test/page'), FALSE),
- array(array('q' => 'civicrm/test/page', 'snippet' => 'json'), TRUE),
- array(array('q' => 'civicrm/test/page', 'snippet' => 'foo'), FALSE),
- );
+ return [
+ [['q' => 'civicrm/ajax/foo'], TRUE],
+ [['q' => 'civicrm/angularprofiles/template'], TRUE],
+ [['q' => 'civicrm/asset/builder'], TRUE],
+ [['q' => 'civicrm/test/page'], FALSE],
+ [['q' => 'civicrm/test/page', 'snippet' => 'json'], TRUE],
+ [['q' => 'civicrm/test/page', 'snippet' => 'foo'], FALSE],
+ ];
}
/**
// 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');
- return array($basedir, $c, $mapper);
+ return [$basedir, $c, $mapper];
}
/**
* @return array
*/
public function urlForCacheCodeProvider() {
- return array(
- array(
+ return [
+ [
'http://www.civicrm.org',
'http://www.civicrm.org?r=' . $this->cacheBusterString,
- ),
- array(
+ ],
+ [
'www.civicrm.org/custom.css?foo=bar',
'www.civicrm.org/custom.css?foo=bar&r=' . $this->cacheBusterString,
- ),
- array(
+ ],
+ [
'civicrm.org/custom.css?car=blue&foo=bar',
'civicrm.org/custom.css?car=blue&foo=bar&r=' . $this->cacheBusterString,
- ),
- );
+ ],
+ ];
}
/**
$this->assertEquals($expected, CRM_Core_Resources::isFullyFormedUrl($url));
}
+ /**
+ * Test for hook_civicrm_entityRefFilters().
+ *
+ */
+ public function testEntityRefFiltersHook() {
+ CRM_Utils_Hook_UnitTests::singleton()->setHook('civicrm_entityRefFilters', [$this, 'entityRefFilters']);
+ $data = CRM_Core_Resources::getEntityRefMetadata();
+ $this->assertEquals(count($data['links']['Contact']), 4);
+ $this->assertEquals(!empty($data['links']['Contact']['new_staff']), TRUE);
+ }
+
+ /**
+ * @param array $filters
+ * @param array $links
+ */
+ public function entityRefFilters(&$filters, &$links) {
+ $links['Contact']['new_staff'] = [
+ 'label' => ts('New Staff'),
+ 'url' => '/civicrm/profile/create&reset=1&context=dialog&gid=5',
+ 'type' => 'Individual',
+ 'icon' => 'fa-user',
+ ];
+ }
+
}