mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-30 19:52:17 +01:00
Contacts: Use class fixtures in tests.
This commit is contained in:
parent
7a69ed85d3
commit
96bfa85a5e
@ -8,42 +8,47 @@
|
||||
OC_App::loadApp('contacts');
|
||||
class Test_Contacts_Backend_Datebase extends PHPUnit_Framework_TestCase {
|
||||
protected static $schema_file = 'static://test_db_scheme';
|
||||
protected $test_prefix;
|
||||
protected static $test_prefix;
|
||||
protected static $backend;
|
||||
protected static $user;
|
||||
protected static $addressBooksTableName;
|
||||
protected static $cardsTableName;
|
||||
|
||||
public function setUp() {
|
||||
public static function setUpBeforeClass() {
|
||||
$dbfile = __DIR__.'/../appinfo/database.xml';
|
||||
|
||||
$this->test_prefix = '_'.OC_Util::generate_random_bytes('4').'_';
|
||||
self::$test_prefix = '_'.OC_Util::generate_random_bytes('4').'_';
|
||||
$content = file_get_contents($dbfile);
|
||||
$content = str_replace( '*dbprefix*', '*dbprefix*'.$this->test_prefix, $content );
|
||||
$content = str_replace( '*dbprefix*', '*dbprefix*'.self::$test_prefix, $content );
|
||||
file_put_contents( self::$schema_file, $content );
|
||||
OC_DB::createDbFromStructure(self::$schema_file);
|
||||
|
||||
$this->addressBooksTableName = '*PREFIX*'.$this->test_prefix.'contacts_addressbooks';
|
||||
$this->cardsTableName = '*PREFIX*'.$this->test_prefix.'contacts_cards';
|
||||
self::$addressBooksTableName = '*PREFIX*'.self::$test_prefix.'contacts_addressbooks';
|
||||
self::$cardsTableName = '*PREFIX*'.self::$test_prefix.'contacts_cards';
|
||||
|
||||
OC_User::clearBackends();
|
||||
OC_User::useBackend('dummy');
|
||||
$this->user = uniqid('user_');
|
||||
OC_User::createUser($this->user, 'pass');
|
||||
OC_User::setUserId($this->user);
|
||||
self::$user = uniqid('user_');
|
||||
OC_User::createUser(self::$user, 'pass');
|
||||
OC_User::setUserId(self::$user);
|
||||
|
||||
self::$backend = new OCA\Contacts\Backend\Database(
|
||||
self::$user,
|
||||
self::$addressBooksTableName,
|
||||
self::$cardsTableName
|
||||
);
|
||||
}
|
||||
|
||||
public function tearDown() {
|
||||
public static function tearDownAfterClass() {
|
||||
OC_DB::removeDBStructure(self::$schema_file);
|
||||
unlink(self::$schema_file);
|
||||
}
|
||||
|
||||
public function testDatabaseBackend() {
|
||||
$this->backend = new OCA\Contacts\Backend\Database(
|
||||
$this->user,
|
||||
$this->addressBooksTableName,
|
||||
$this->cardsTableName
|
||||
);
|
||||
|
||||
$this->assertEquals(array(), $this->backend->getAddressBooksForUser());
|
||||
$this->assertEquals(array(), self::$backend->getAddressBooksForUser());
|
||||
|
||||
$aid = $this->backend->createAddressBook(
|
||||
$aid = self::$backend->createAddressBook(
|
||||
array(
|
||||
'displayname' => 'Contacts',
|
||||
'description' => 'My Contacts',
|
||||
@ -51,31 +56,43 @@ class Test_Contacts_Backend_Datebase extends PHPUnit_Framework_TestCase {
|
||||
);
|
||||
|
||||
// Test address books
|
||||
$this->assertEquals(1, count($this->backend->getAddressBooksForUser()));
|
||||
$this->assertTrue($this->backend->hasAddressBook($aid));
|
||||
$addressBook = $this->backend->getAddressBook($aid);
|
||||
$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']);
|
||||
$this->backend->updateAddressBook($aid, array('description' => 'All my contacts'));
|
||||
$addressBook = $this->backend->getAddressBook($aid);
|
||||
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(), $this->backend->getContacts($aid));
|
||||
$this->assertEquals(array(), self::$backend->getContacts($aid));
|
||||
|
||||
$carddata = file_get_contents(__DIR__ . '/data/test.vcf');
|
||||
$id = $this->backend->createContact($aid, $carddata);
|
||||
$id = self::$backend->createContact($aid, $carddata);
|
||||
$this->assertNotEquals(false, $id); // Isn't there an assertNotFalse() ?
|
||||
$this->assertEquals(1, count($this->backend->getContacts($aid)));
|
||||
$this->assertTrue($this->backend->hasContact($aid, $id));
|
||||
$contact = $this->backend->getContact($aid, $id);
|
||||
$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($this->backend->updateContact($aid, $id, $carddata));
|
||||
$contact = $this->backend->getContact($aid, $id);
|
||||
$this->assertTrue(self::$backend->updateContact($aid, $id, $carddata));
|
||||
$contact = self::$backend->getContact($aid, $id);
|
||||
$this->assertEquals('John Q. Public', $contact['displayname']);
|
||||
$this->assertTrue($this->backend->deleteContact($aid, $id));
|
||||
$this->assertTrue(self::$backend->deleteContact($aid, $id));
|
||||
|
||||
$this->assertTrue($this->backend->deleteAddressBook($aid));
|
||||
$this->assertTrue(self::$backend->deleteAddressBook($aid));
|
||||
}
|
||||
|
||||
public function testAddressBook() {
|
||||
$addressBook = new OCA\Contacts\AddressBook(
|
||||
self::$backend,
|
||||
array(
|
||||
'displayname' => 'Contacts',
|
||||
'description' => 'My Contacts',
|
||||
'permissions' => OCP\PERMISSION_ALL,
|
||||
'owner' => self::$user,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user