if ($options) {
$$stateName->setOptions($options);
}
- if (property_exists($$stateName, 'urlPath') && isset($_GET[CRM_Core_Config::singleton()->userFrameworkURLVar])) {
- $$stateName->urlPath = explode('/', $_GET[CRM_Core_Config::singleton()->userFrameworkURLVar]);
+ if (property_exists($$stateName, 'urlPath')) {
+ $$stateName->urlPath = explode('/', (string) CRM_Utils_System::getUrlPath());
}
$this->addPage($$stateName);
$this->addAction($stateName, new HTML_QuickForm_Action_Direct());
* is this page request an ajax snippet?
*/
public static function isAjaxMode() {
- return in_array(CRM_Utils_Array::value('snippet', $_REQUEST), array(
+ if (in_array(CRM_Utils_Array::value('snippet', $_REQUEST), array(
CRM_Core_Smarty::PRINT_SNIPPET,
CRM_Core_Smarty::PRINT_NOFORM,
CRM_Core_Smarty::PRINT_JSON,
- ));
+ ))
+ ) {
+ return TRUE;
+ }
+ return strpos(CRM_Utils_System::getUrlPath(), 'civicrm/ajax') === 0;
}
/**
*/
protected $mapper;
+ protected $originalRequest;
+ protected $originalGet;
+
public function setUp() {
parent::setUp();
// Templates injected into regions should normally be file names, but for unit-testing it's handy to use "string:" notation
require_once 'CRM/Core/Smarty/resources/String.php';
civicrm_smarty_register_string_resource();
+
+ $this->originalRequest = $_REQUEST;
+ $this->originalGet = $_GET;
+ }
+
+ /**
+ * Restore globals so this test doesn't interfere with others.
+ */
+ public function tearDown() {
+ $_REQUEST = $this->originalRequest;
+ $_GET = $this->originalGet;
}
public function testAddScriptFile() {
);
}
+ /**
+ * @dataProvider ajaxModeData
+ */
+ public function testIsAjaxMode($query, $result) {
+ $_REQUEST = $_GET = $query;
+ $this->assertEquals($result, CRM_Core_Resources::isAjaxMode());
+ }
+
+ public function ajaxModeData() {
+ return array(
+ array(array('q' => 'civicrm/ajax/foo'), 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),
+ );
+ }
+
/**
* @param CRM_Utils_Cache_Interface $cache
* @param string $cacheKey