/** * Create Person From XML * * @param SimpleXMLElement $xmlElement * @return Batchblue_Service_BatchBook_Person */ private function _populatePersonFromXmlElement(SimpleXMLElement $xmlElement, Batchblue_Service_BatchBook_Person $person = null) { if (null === $person) { $person = new Batchblue_Service_BatchBook_Person(); } $person->setId($xmlElement->id)->setFirstName($xmlElement->first_name)->setLastName($xmlElement->last_name)->setTitle($xmlElement->title)->setCompany($xmlElement->company)->setNotes($xmlElement->notes); $locations = array(); $tags = array(); foreach ($xmlElement->tags->tag as $xmlTag) { if ($xmlTag->supertag) { $tag = new Batchblue_Service_BatchBook_SuperTag(); $tag->setName($xmlTag->name); $tag->setFields($xmlTag->fields); } else { $tag = new Batchblue_Service_BatchBook_Tag(); $tag->setName($xmlTag->name); } array_push($tags, $tag); } foreach ($xmlElement->locations->location as $xmlLocation) { $location = new Batchblue_Service_BatchBook_Location(); $location->setId($xmlLocation->id)->setLabel($xmlLocation->label)->setEmail($xmlLocation->email)->setWebsite($xmlLocation->website)->setPhone($xmlLocation->phone)->setCell($xmlLocation->cell)->setFax($xmlLocation->fax)->setStreet1($xmlLocation->street_1)->setStreet2($xmlLocation->street_2)->setCity($xmlLocation->city)->setState($xmlLocation->state)->setPostalCode($xmlLocation->postal_code)->setCountry($xmlLocation->country); array_push($locations, $location); } $person->setLocations($locations); $person->setTags($tags); return $person; }
/** * @depends testPutPerson * @param Batchblue_Service_BatchBook_Person $person * @return void */ public function testAddTag(Batchblue_Service_BatchBook_Person $person) { $tagA = new Batchblue_Service_BatchBook_Tag(); $tagA->setName('my_test_tag_a' . md5(uniqid(rand(), true))); $tagB = new Batchblue_Service_BatchBook_Tag(); $tagB->setName('my_test_tag_b' . md5(uniqid(rand(), true))); $this->_personService->addTag($person, $tagA); $this->_personService->addTag($person, $tagB); $getPerson = $this->_personService->getPerson($person->getId()); $tags = $getPerson->getTags(); $this->assertGreaterThanOrEqual(2, count($tags)); $foundTagA = false; $foundTagB = false; foreach ($tags as $currentTag) { if ($currentTag->getName() == $tagA->getName()) { $foundTagA = true; } if ($currentTag->getName() == $tagB->getName()) { $foundTagB = true; } } $this->assertTrue($foundTagA, "Looking for tagA: " . $tagA->getName()); $this->assertTrue($foundTagB, "Looking for tagB: " . $tagB->getName()); }