assertEquals(array(), self::$backend->getAddressBooksForUser()); $aid = self::$backend->createAddressBook( array( 'displayname' => 'Contacts', 'description' => 'My Contacts', ) ); // Test address books $this->assertEquals(1, count(self::$backend->getAddressBooksForUser())); $this->assertTrue(self::$backend->hasAddressBook($aid)); $addressBook = self::$backend->getAddressBook($aid); $this->assertEquals('Contacts', $addressBook['displayname']); $this->assertEquals('My Contacts', $addressBook['description']); self::$backend->updateAddressBook($aid, array('description' => 'All my contacts')); $addressBook = self::$backend->getAddressBook($aid); $this->assertEquals('All my contacts', $addressBook['description']); // Test contacts $this->assertEquals(array(), self::$backend->getContacts($aid)); $carddata = file_get_contents(__DIR__ . '/data/test1.vcf'); $id = self::$backend->createContact($aid, $carddata); $this->assertNotEquals(false, $id); // Isn't there an assertNotFalse() ? $this->assertEquals(1, count(self::$backend->getContacts($aid))); $this->assertTrue(self::$backend->hasContact($aid, $id)); $contact = self::$backend->getContact($aid, $id); $this->assertEquals('Max Mustermann', $contact['displayname']); $carddata = file_get_contents(__DIR__ . '/data/test2.vcf'); $this->assertTrue(self::$backend->updateContact($aid, $id, $carddata)); $contact = self::$backend->getContact($aid, $id); $this->assertEquals('John Q. Public', $contact['displayname']); $this->assertTrue(self::$backend->deleteContact($aid, $id)); $this->assertTrue(self::$backend->deleteAddressBook($aid)); } public function testAddressBook() { $addressBook = new OCA\Contacts\AddressBook( self::$backend, array( 'displayname' => 'Contacts', 'description' => 'My Contacts', ) ); $this->assertEquals(0, count($addressBook)); $id = $addressBook->addChild( array( 'displayname' => 'John Q. Public' ) ); $this->assertNotEquals(false, $id); $this->assertEquals(1, count($addressBook)); $contact = $addressBook->getChild($id); $this->assertEquals('John Q. Public', (string)$contact->FN); $contact->FN = 'Max Mustermann'; $contact->save(); $contact = $addressBook[$id]; $metadata = $contact->getMetaData(); $this->assertEquals('Max Mustermann', $metadata['displayname']); $this->assertEquals($contact->getPermissions(), $addressBook->getPermissions()); // Array access $this->assertEquals($contact, $addressBook[$id]); $this->assertTrue(isset($addressBook[$id])); // Magic accessors //$this->assertEquals($contact, $addressBook->{$id}); $this->assertTrue($addressBook->deleteChild($id)); $this->assertEquals(0, count($addressBook)); $this->assertEquals(0, 1); } }