Added unit tests for OC_DB::insertIfNotExist()

This commit is contained in:
Thomas Tanghus 2012-10-19 13:18:57 +02:00
parent 03ff614265
commit 1c9929d44f
2 changed files with 110 additions and 0 deletions

View File

@ -135,4 +135,88 @@
</table>
<table>
<name>*dbprefix*vcategory</name>
<declaration>
<field>
<name>id</name>
<type>integer</type>
<default>0</default>
<notnull>true</notnull>
<autoincrement>1</autoincrement>
<unsigned>true</unsigned>
<length>4</length>
</field>
<field>
<name>uid</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>type</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>64</length>
</field>
<field>
<name>category</name>
<type>text</type>
<default></default>
<notnull>true</notnull>
<length>255</length>
</field>
<index>
<name>uid_index</name>
<field>
<name>uid</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<name>type_index</name>
<field>
<name>type</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<name>category_index</name>
<field>
<name>category</name>
<sorting>ascending</sorting>
</field>
</index>
<index>
<name>uid_type_category_index</name>
<unique>true</unique>
<field>
<name>uid</name>
<sorting>ascending</sorting>
</field>
<field>
<name>type</name>
<sorting>ascending</sorting>
</field>
<field>
<name>category</name>
<sorting>ascending</sorting>
</field>
</index>
</declaration>
</table>
</database>

View File

@ -24,6 +24,7 @@ class Test_DB extends UnitTestCase {
$this->test_prefix = $r;
$this->table1 = $this->test_prefix.'contacts_addressbooks';
$this->table2 = $this->test_prefix.'contacts_cards';
$this->table3 = $this->test_prefix.'vcategory';
}
public function tearDown() {
@ -67,4 +68,29 @@ class Test_DB extends UnitTestCase {
$result = $query->execute(array('uri_3'));
$this->assertTrue($result);
}
public function testinsertIfNotExist() {
$categoryentries = array(
array('user' => 'test', 'type' => 'contact', 'category' => 'Family'),
array('user' => 'test', 'type' => 'contact', 'category' => 'Friends'),
array('user' => 'test', 'type' => 'contact', 'category' => 'Coworkers'),
array('user' => 'test', 'type' => 'contact', 'category' => 'Coworkers'),
array('user' => 'test', 'type' => 'contact', 'category' => 'School'),
);
foreach($categoryentries as $entry) {
$result = OC_DB::insertIfNotExist('*PREFIX*'.$this->table3,
array(
'uid' => $entry['user'],
'type' => $entry['type'],
'category' => $entry['category'],
));
$this->assertTrue($result);
}
$query = OC_DB::prepare('SELECT * FROM *PREFIX*'.$this->table3);
$result = $query->execute();
$this->assertTrue($result);
$this->assertEqual($result->numRows(), '4');
}
}