From: Tim Otten Date: Tue, 27 May 2014 03:45:41 +0000 (-0700) Subject: CiviCaseTestCase - Allow specifying the XML file. Allow hook-XML to override core... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=bb68492cc740f6da0b3f7fe31aac3bc0abb6afa0;p=civicrm-core.git CiviCaseTestCase - Allow specifying the XML file. Allow hook-XML to override core-XML. --- diff --git a/CRM/Case/XMLRepository.php b/CRM/Case/XMLRepository.php index d23ffcd994..b5c29eee15 100644 --- a/CRM/Case/XMLRepository.php +++ b/CRM/Case/XMLRepository.php @@ -82,53 +82,54 @@ class CRM_Case_XMLRepository { if (!CRM_Utils_Array::value($caseType, $this->xml)) { // first check custom templates directory $fileName = NULL; - $config = CRM_Core_Config::singleton(); - if (isset($config->customTemplateDir) && - $config->customTemplateDir - ) { - // check if the file exists in the custom templates directory - $fileName = implode(DIRECTORY_SEPARATOR, - array( - $config->customTemplateDir, - 'CRM', - 'Case', - 'xml', - 'configuration', - "$caseType.xml", - ) - ); + + if (!$fileName || !file_exists($fileName)) { + $caseTypesViaHook = $this->getCaseTypesViaHook(); + if (isset($caseTypesViaHook[$caseType], $caseTypesViaHook[$caseType]['file'])) { + $fileName = $caseTypesViaHook[$caseType]['file']; + } } - if (!$fileName || - !file_exists($fileName) - ) { - // check if file exists locally - $fileName = implode(DIRECTORY_SEPARATOR, - array( - dirname(__FILE__), - 'xml', - 'configuration', - "$caseType.xml", - ) - ); + if (!$fileName || !file_exists($fileName)) { + $config = CRM_Core_Config::singleton(); + if (isset($config->customTemplateDir) && $config->customTemplateDir) { + // check if the file exists in the custom templates directory + $fileName = implode(DIRECTORY_SEPARATOR, + array( + $config->customTemplateDir, + 'CRM', + 'Case', + 'xml', + 'configuration', + "$caseType.xml", + ) + ); + } + } + if (!$fileName || !file_exists($fileName)) { if (!file_exists($fileName)) { // check if file exists locally $fileName = implode(DIRECTORY_SEPARATOR, array( dirname(__FILE__), 'xml', - 'configuration.sample', + 'configuration', "$caseType.xml", ) ); } if (!file_exists($fileName)) { - $caseTypesViaHook = $this->getCaseTypesViaHook(); - if (isset($caseTypesViaHook[$caseType], $caseTypesViaHook[$caseType]['file'])) { - $fileName = $caseTypesViaHook[$caseType]['file']; - } + // check if file exists locally + $fileName = implode(DIRECTORY_SEPARATOR, + array( + dirname(__FILE__), + 'xml', + 'configuration.sample', + "$caseType.xml", + ) + ); } if (!file_exists($fileName)) { @@ -158,7 +159,7 @@ class CRM_Case_XMLRepository { } /** - * @return array symbolic names of case-types + * @return array symbolic names of case-types */ public function getAllCaseTypes() { if ($this->allCaseTypes === NULL) { diff --git a/tests/phpunit/CiviTest/CiviCaseTestCase.php b/tests/phpunit/CiviTest/CiviCaseTestCase.php index 5f009ebec1..8f80ebc335 100644 --- a/tests/phpunit/CiviTest/CiviCaseTestCase.php +++ b/tests/phpunit/CiviTest/CiviCaseTestCase.php @@ -32,13 +32,27 @@ require_once 'CiviTest/CiviUnitTestCase.php'; */ class CiviCaseTestCase extends CiviUnitTestCase { + /** + * @var string symbolic-name + */ + protected $caseType; + protected $caseTypeId; + protected $caseStatusGroup; + protected $optionValues; + protected $_loggedInUser; public function setUp() { parent::setUp(); + + /** @var $hooks \CRM_Utils_Hook_UnitTests */ + $hooks = \CRM_Utils_Hook::singleton(); + $hooks->setHook('civicrm_caseTypes', array($this, 'hook_caseTypes')); + \CRM_Case_XMLRepository::singleton(TRUE); + // CRM-9404 - set-up is a bit cumbersome but had to put something in place to set up activity types & case types //. Using XML was causing breakage as id numbers were changing over time // & was really hard to troubleshoot as involved truncating option_value table to mitigate this & not leaving DB in a @@ -66,6 +80,9 @@ class CiviCaseTestCase extends CiviUnitTestCase { // store for cleanup $this->optionValues[] = $activityTypes['id']; } + + // TODO Our data seems inconsistent on whether name is "HousingSupport" or "housing_support" + $this->caseType = 'HousingSupport'; $this->caseTypeId = 1; $this->tablesToTruncate = array( 'civicrm_activity', @@ -111,5 +128,15 @@ class CiviCaseTestCase extends CiviUnitTestCase { function tearDown() { $this->quickCleanup($this->tablesToTruncate, TRUE); $this->customDirectories(array('template_path' => FALSE)); + CRM_Case_XMLRepository::singleton(TRUE); + } + + /** + * Subclasses may override this if they want to be explicit about the case-type definition. + * + * @param $caseTypes + * @see CRM_Utils_Hook::caseTypes + */ + function hook_caseTypes(&$caseTypes) { } } \ No newline at end of file