/** * check getTopicCategoryNice */ function testgetTopicCategoryNice() { $topic = new MDTopicCategory(); $topic->Value = 'biota'; //check initial value $this->assertEquals($topic->Value, 'biota', 'initial data'); // make it nice $topicName = $topic->getTopicCategoryNice(); $this->assertEquals($topicName, 'Biota', 'on initial data'); // checking empty value $topic->Value = ''; $topicName = $topic->getTopicCategoryNice(); $this->assertEquals($topicName, '', 'on empty value'); //null-Value should return the default for null $topic->Value = null; $topicName = $topic->getTopicCategoryNice(); $this->assertEquals($topicName, '', 'on null value'); //checking an invalid value $topic->Value = 'INVALID_TOPIC'; $topicName = $topic->getTopicCategoryNice(); $this->assertEquals($topicName, '', 'on invalid value'); }
/** * This method loads a provided array into the data structure. * It also creates dependencies, such as contact data objects * and populate the values into those objects. * * @param $data array of db-values. */ public function loadData($data) { if ($data == null) { return; } if (!is_array($data)) { return; } foreach ($data as $k => $v) { // store data into this object (no ':" in the string) if (strpos($k, ':') === false) { $this->{$k} = Convert::xml2raw($v); } else { // A ':' is used as a namespace marker. It is used to // create the related data objects, such as MDContacts. $relations = explode(':', $k); $fieldName = array_pop($relations); $relObj = $this; // iterate through the relationships. At the moment, this // loading process just works for 1 level hierarchies. foreach ($relations as $relation) { if ($relation == 'PointOfContacts') { // load the sub-array into the MDContact object $item = new MDContact(); $item->loadData($v); // add the new MDContect to the collection class of this // object. $relObj->PointOfContacts()->add($item); } if ($relation == 'MDContacts') { // load the sub-array into the MDContact object $item = new MDContact(); $item->loadData($v); // add the new MDContect to the collection class of this // object. $relObj->MDContacts()->add($item); } if ($relation == 'MDResourceConstraints') { // load the sub-array into the MDResourceConstraints object if (is_array($v)) { foreach ($v as $vitem) { $item = new MDResourceConstraint(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDResourceConstraints()->add($item); } } } if ($relation == 'MDResourceFormats') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDResourceFormat(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDResourceFormats()->add($item); } } } if ($relation == 'MDTopicCategory') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDTopicCategory(); $item->loadData($vitem); // add the new MDTopicCategory to the collection class of this // object. $relObj->MDTopicCategory()->add($item); } } } if ($relation == 'MDCitationDates') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDResourceFormats object $item = new MDCitationDate(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->MDCitationDates()->add($item); } } } if ($relation == 'MCPMDCreativeCommons') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDContact object $item = new MCPMDCreativeCommons(); $item->loadData($vitem); // add the new MCPMDCreativeCommons to the collection class of this // object. $relObj->MCPMDCreativeCommons()->add($item); } } } if ($relation == 'CIOnlineResources') { if (is_array($v)) { foreach ($v as $vitem) { // load the sub-array into the MDContact object $item = new CIOnlineResource(); $item->loadData($vitem); // add the new MDContect to the collection class of this // object. $relObj->CIOnlineResources()->add($item); } } } if ($relation == 'MDHierarchyLevel') { if (is_array($v)) { foreach ($v as $vitem) { $codes = MDCodeTypes::get_scope_codes(); if (isset($codes[$vitem['Value']])) { $item = new MDHierarchyLevel(); $item->loadData($vitem); $relObj->MDHierarchyLevel()->add($item); } } } } if ($relation == 'MDHierarchyLevelName') { if (is_array($v)) { foreach ($v as $vitem) { $item = new MDHierarchyLevelName(); $item->loadData($vitem); $relObj->MDHierarchyLevelName()->add($item); } } } } } } }