diff options
author | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-03-20 14:41:31 +0100 |
---|---|---|
committer | Bernhard Posselt <dev@bernhard-posselt.com> | 2015-03-21 13:36:50 +0100 |
commit | 953b030e2678ce45d2f182c181ef2190f39d161d (patch) | |
tree | 0337988efca9bf3b714ca9af5e95e188d6ddb260 /tests/unit/db | |
parent | 03ce3af3a51f51852cd0a3f06872fc36d7f62dfb (diff) |
generate an index
Diffstat (limited to 'tests/unit/db')
-rw-r--r-- | tests/unit/db/ItemTest.php | 12 | ||||
-rw-r--r-- | tests/unit/db/mappertestutility.php | 73 |
2 files changed, 58 insertions, 27 deletions
diff --git a/tests/unit/db/ItemTest.php b/tests/unit/db/ItemTest.php index c937053d1..719e8d5da 100644 --- a/tests/unit/db/ItemTest.php +++ b/tests/unit/db/ItemTest.php @@ -186,6 +186,18 @@ class ItemTest extends \PHPUnit_Framework_TestCase { } + public function testSearchIndex() { + $item = new Item(); + $item->setBody('<a>somEthing</a>'); + $item->setUrl('http://link'); + $item->setAuthor('author'); + $item->setTitle('<a>title</a>'); + $item->generateSearchIndex(); + $expected = 'somethingauthortitlehttp://link'; + $this->assertEquals($expected, $item->getSearchIndex()); + } + + public function testFromImport() { $item = $this->createImportItem(false); diff --git a/tests/unit/db/mappertestutility.php b/tests/unit/db/mappertestutility.php index cba2aadd6..de07f136c 100644 --- a/tests/unit/db/mappertestutility.php +++ b/tests/unit/db/mappertestutility.php @@ -45,7 +45,7 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { parent::setUp(); $this->db = $this->getMockBuilder( - '\OCP\IDb') + '\OCP\IDBConnection') ->disableOriginalConstructor() ->getMock(); @@ -56,6 +56,30 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { $this->fetchAt = 0; } + /** + * Checks if an array is associative + * @param array $array + * @return bool true if associative + */ + private function isAssocArray(array $array) { + return array_values($array) !== $array; + } + + /** + * Returns the correct PDO constant based on the value type + * @param $value + * @return PDO constant + */ + private function getPDOType($value) { + switch (gettype($value)) { + case 'integer': + return \PDO::PARAM_INT; + case 'boolean': + return \PDO::PARAM_BOOL; + default: + return \PDO::PARAM_STR; + } + } /** * Create mocks and set expected results for database queries @@ -116,32 +140,28 @@ abstract class MapperTestUtility extends \PHPUnit_Framework_TestCase { } )); - $index = 1; - foreach($arguments as $argument) { - switch (gettype($argument)) { - case 'integer': - $pdoConstant = \PDO::PARAM_INT; - break; - - case 'NULL': - $pdoConstant = \PDO::PARAM_NULL; - break; - - case 'boolean': - $pdoConstant = \PDO::PARAM_BOOL; - break; - - default: - $pdoConstant = \PDO::PARAM_STR; - break; + if ($this->isAssocArray($arguments)) { + foreach($arguments as $key => $argument) { + $pdoConstant = $this->getPDOType($argument); + $this->query->expects($this->at($this->queryAt)) + ->method('bindValue') + ->with($this->equalTo($key), + $this->equalTo($argument), + $this->equalTo($pdoConstant)); + $this->queryAt++; + } + } else { + $index = 1; + foreach($arguments as $argument) { + $pdoConstant = $this->getPDOType($argument); + $this->query->expects($this->at($this->queryAt)) + ->method('bindValue') + ->with($this->equalTo($index), + $this->equalTo($argument), + $this->equalTo($pdoConstant)); + $index++; + $this->queryAt++; } - $this->query->expects($this->at($this->queryAt)) - ->method('bindValue') - ->with($this->equalTo($index), - $this->equalTo($argument), - $this->equalTo($pdoConstant)); - $index++; - $this->queryAt++; } $this->query->expects($this->at($this->queryAt)) @@ -186,4 +206,3 @@ class ArgumentIterator { } } } - |