diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/db/ItemTest.php | 12 | ||||
-rw-r--r-- | tests/unit/db/mappertestutility.php | 73 | ||||
-rw-r--r-- | tests/unit/fetcher/FeedFetcherTest.php | 1 |
3 files changed, 59 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 { } } } - diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php index b0320de4b..e1a3997ac 100644 --- a/tests/unit/fetcher/FeedFetcherTest.php +++ b/tests/unit/fetcher/FeedFetcherTest.php @@ -217,6 +217,7 @@ class FeedFetcherTest extends \PHPUnit_Framework_TestCase { $item->setGuidHash($this->guid); $item->setBody($this->body); $item->setLastModified($this->time); + $item->generateSearchIndex(); $this->expectItem('getAuthor', $this->author); $item->setAuthor(html_entity_decode($this->author)); |