* $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;
return $this->allCaseTypes;
}
+ /**
+ * @return array<string> 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<string> 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.
}
+ 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']),
)
);
array('CaseTypeWithSingleRole', 'CaseTypeWithSingleActivityType'),
array(
'CaseTypeWithSingleRole' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleRole']),
- /* noise: */
+ /* healthful noise: */
'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']),
)
);
array(
'CaseTypeWithTwoRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithTwoRoles']),
'CaseTypeWithThreeRoles' => new SimpleXMLElement($this->fixtures['CaseTypeWithThreeRoles']),
- /* noise: */
+ /* healthful noise: */
'CaseTypeWithSingleActivityType' => new SimpleXMLElement($this->fixtures['CaseTypeWithSingleActivityType']),
)
);