From: Tim Otten Date: Sat, 24 May 2014 00:08:25 +0000 (-0700) Subject: CRM_Case_XMLRepository -- Add getAllDeclaredActivityTypes() & getAllDeclaredRelations... X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=7458ddd3011ca96f996ab79a030bb844d4ad3bcc;p=civicrm-core.git CRM_Case_XMLRepository -- Add getAllDeclaredActivityTypes() & getAllDeclaredRelationshipTypes() --- diff --git a/CRM/Case/XMLRepository.php b/CRM/Case/XMLRepository.php index 0214254bef..698393eb56 100644 --- a/CRM/Case/XMLRepository.php +++ b/CRM/Case/XMLRepository.php @@ -32,6 +32,8 @@ * $Id$ * * The XMLRepository is responsible for loading XML for case-types. + * It includes any bulk operations that apply across the list of all XML + * documents of all case-types. */ class CRM_Case_XMLRepository { private static $singleton; @@ -165,6 +167,40 @@ class CRM_Case_XMLRepository { return $this->allCaseTypes; } + /** + * @return array symbolic-names of activity-types + */ + public function getAllDeclaredActivityTypes() { + $result = array(); + + $p = new CRM_Case_XMLProcessor_Process(); + foreach ($this->getAllCaseTypes() as $caseTypeName) { + $caseTypeXML = $this->retrieve($caseTypeName); + $result = array_merge($result, $p->getDeclaredActivityTypes($caseTypeXML)); + } + + $result = array_unique($result); + sort($result); + return $result; + } + + /** + * @return array symbolic-names of relationship-types + */ + public function getAllDeclaredRelationshipTypes() { + $result = array(); + + $p = new CRM_Case_XMLProcessor_Process(); + foreach ($this->getAllCaseTypes() as $caseTypeName) { + $caseTypeXML = $this->retrieve($caseTypeName); + $result = array_merge($result, $p->getDeclaredRelationshipTypes($caseTypeXML)); + } + + $result = array_unique($result); + sort($result); + return $result; + } + /** * Determine the number of times a particular activity-type is * referenced in CiviCase XML. diff --git a/tests/phpunit/CRM/Case/XMLRepositoryTest.php b/tests/phpunit/CRM/Case/XMLRepositoryTest.php index be2a6d9d66..cde2164f4b 100644 --- a/tests/phpunit/CRM/Case/XMLRepositoryTest.php +++ b/tests/phpunit/CRM/Case/XMLRepositoryTest.php @@ -97,12 +97,45 @@ class CRM_Case_XMLRepositoryTest extends CiviUnitTestCase { } + function testGetAllDeclaredActivityTypes() { + $repo = new CRM_Case_XMLRepository( + array('CaseTypeWithTwoActivityTypes', 'CaseTypeWithThreeActivityTypes'), + array( + 'CaseTypeWithTwoActivityTypes' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoActivityTypes']), + 'CaseTypeWithThreeActivityTypes' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeActivityTypes']), + /* healthful noise: */ + 'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']), + ) + ); + + // omitted: 'Single Activity Type' + $expected = array('First Activity Type', 'Second Activity Type', 'Third Activity Type'); + $actual = $repo->getAllDeclaredActivityTypes(); + $this->assertEquals($expected, $actual); + } + + function testGetAllDeclaredRelationshipTypes() { + $repo = new CRM_Case_XMLRepository( + array('CaseTypeWithTwoRoles', 'CaseTypeWithThreeRoles', 'CaseTypeWithSingleActivityType'), + array( + 'CaseTypeWithTwoRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoRoles']), + 'CaseTypeWithThreeRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeRoles']), + /* healthful noise: */ + 'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']), + ) + ); + // omitted: 'Single Role' + $expected = array('First Role', 'Second Role', 'Third Role'); + $actual = $repo->getAllDeclaredRelationshipTypes(); + $this->assertEquals($expected, $actual); + } + function testGetActivityReferenceCount_1() { $repo = new CRM_Case_XMLRepository( array('CaseTypeWithSingleActivityType'), array( 'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']), - /* noise: */ + /* healthful noise: */ 'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']), ) ); @@ -135,7 +168,7 @@ class CRM_Case_XMLRepositoryTest extends CiviUnitTestCase { array('CaseTypeWithSingleRole', 'CaseTypeWithSingleActivityType'), array( 'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']), - /* noise: */ + /* healthful noise: */ 'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']), ) ); @@ -152,7 +185,7 @@ class CRM_Case_XMLRepositoryTest extends CiviUnitTestCase { array( 'CaseTypeWithTwoRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoRoles']), 'CaseTypeWithThreeRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeRoles']), - /* noise: */ + /* healthful noise: */ 'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']), ) );