Esempio n. 1
0
 public function contactAdd(Contact $contact)
 {
     #print __CLASS__.'->'.__FUNCTION__.''."\n";
     $ocontact = $this->contactGetByNodeId($contact->getNodeId());
     if (!$ocontact) {
         $this->contactsId++;
         $contact->setId($this->contactsId);
         $this->contacts[$contact->getId()] = $contact;
         $this->contactsByNodeId[$contact->getNodeId()] = $contact;
         $this->setDataChanged(true);
     }
 }
Esempio n. 2
0
 public function testContactRemove()
 {
     $book = new Addressbook();
     $contact = new Contact();
     $contact->setId(1);
     $contact->setNodeId('cafed00d-2131-4159-8e11-0b4dbadb1738');
     $contact->setUserNickname('nick1');
     $contact->setTimeCreated(24);
     $book->contactAdd($contact);
     $contact = new Contact();
     $contact->setId(2);
     $contact->setNodeId('cafed00d-2131-4159-8e11-0b4dbadb1739');
     $contact->setUserNickname('nick2');
     $contact->setTimeCreated(25);
     $book->contactAdd($contact);
     $contact = new Contact();
     $contact->setId(3);
     $contact->setNodeId('cafed00d-2131-4159-8e11-0b4dbadb1740');
     $contact->setUserNickname('nick3');
     $contact->setTimeCreated(26);
     $book->contactAdd($contact);
     $this->assertEquals(3, count($book->getContacts()));
     $this->assertTrue($book->contactRemove(2));
     $contacts = $book->getContacts();
     $this->assertEquals(2, count($contacts));
     $this->assertEquals(1, $contacts[1]->getId());
     $this->assertEquals(3, $contacts[3]->getId());
     $this->assertFalse($book->contactRemove(4));
     $contacts = $book->getContacts();
     $this->assertEquals(2, count($contacts));
     $this->assertEquals(1, $contacts[1]->getId());
     $this->assertEquals(3, $contacts[3]->getId());
 }