summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-04-08 18:50:10 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-04-08 18:50:10 +0200
commit31ae116fe4ab5cac3d2a85069adae2d211ecc846 (patch)
tree10c02f09fb0086b7553091fb73c299d9b294385d /tests
parent83e8691308971680977b6e29d7c1fbd790e4eb16 (diff)
migrated database, utility, bootstrap from appframework
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/articleenhancer/XPathArticleEnhancerTest.php2
-rw-r--r--tests/unit/businesslayer/BusinessLayerTest.php4
-rw-r--r--tests/unit/businesslayer/FeedBusinessLayerTest.php5
-rw-r--r--tests/unit/businesslayer/FolderBusinessLayerTest.php2
-rw-r--r--tests/unit/businesslayer/ItemBusinessLayerTest.php5
-rw-r--r--tests/unit/controller/ExportControllerTest.php2
-rw-r--r--tests/unit/controller/PageControllerTest.php2
-rw-r--r--tests/unit/controller/UserSettingsControllerTest.php2
-rw-r--r--tests/unit/db/EntityTest.php207
-rw-r--r--tests/unit/db/FeedMapperTest.php8
-rw-r--r--tests/unit/db/FolderMapperTest.php4
-rw-r--r--tests/unit/db/ItemMapperTest.php2
-rw-r--r--tests/unit/db/MapperFactoryTest.php2
-rw-r--r--tests/unit/db/MapperTest.php267
-rw-r--r--tests/unit/fetcher/FeedFetcherTest.php6
-rw-r--r--tests/unit/utility/FaviconFetcherTest.php194
16 files changed, 687 insertions, 27 deletions
diff --git a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php
index 60b8e0a90..65e16fb4b 100644
--- a/tests/unit/articleenhancer/XPathArticleEnhancerTest.php
+++ b/tests/unit/articleenhancer/XPathArticleEnhancerTest.php
@@ -38,7 +38,7 @@ class XPathArticleEnhancerTest extends \OCA\AppFramework\Utility\TestUtility {
protected function setUp() {
$timeout = 30;
- $this->fileFactory = $this->getMockBuilder('\OCA\News\Utility\SimplePieFileFactory')
+ $this->fileFactory = $this->getMockBuilder('\OCA\News\Utility\SimplePieAPIFactory')
->disableOriginalConstructor()
->getMock();
diff --git a/tests/unit/businesslayer/BusinessLayerTest.php b/tests/unit/businesslayer/BusinessLayerTest.php
index 9326da67c..2208e34f8 100644
--- a/tests/unit/businesslayer/BusinessLayerTest.php
+++ b/tests/unit/businesslayer/BusinessLayerTest.php
@@ -28,8 +28,8 @@ namespace OCA\News\BusinessLayer;
require_once(__DIR__ . "/../../classloader.php");
-use \OCA\AppFramework\Db\DoesNotExistException;
-use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
+use \OCA\News\Db\DoesNotExistException;
+use \OCA\News\Db\MultipleObjectsReturnedException;
use \OCA\News\Db\Folder;
diff --git a/tests/unit/businesslayer/FeedBusinessLayerTest.php b/tests/unit/businesslayer/FeedBusinessLayerTest.php
index 40b1fa883..99ecee9f2 100644
--- a/tests/unit/businesslayer/FeedBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FeedBusinessLayerTest.php
@@ -28,8 +28,7 @@ namespace OCA\News\BusinessLayer;
require_once(__DIR__ . "/../../classloader.php");
-use \OCA\AppFramework\Db\DoesNotExistException;
-
+use \OCA\News\Db\DoesNotExistException;
use \OCA\News\Db\Feed;
use \OCA\News\Db\Item;
use \OCA\News\Fetcher\Fetcher;
@@ -55,7 +54,7 @@ class FeedBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->time = 222;
$this->autoPurgeMinimumInterval = 10;
$timeFactory = $this->getMockBuilder(
- '\OCA\AppFramework\Utility\TimeFactory')
+ '\OCA\News\Utility\TimeFactory')
->disableOriginalConstructor()
->getMock();
$timeFactory->expects($this->any())
diff --git a/tests/unit/businesslayer/FolderBusinessLayerTest.php b/tests/unit/businesslayer/FolderBusinessLayerTest.php
index b473e5dea..398365739 100644
--- a/tests/unit/businesslayer/FolderBusinessLayerTest.php
+++ b/tests/unit/businesslayer/FolderBusinessLayerTest.php
@@ -43,7 +43,7 @@ class FolderBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
$this->api = $this->getAPIMock();
$this->time = 222;
$timeFactory = $this->getMockBuilder(
- '\OCA\AppFramework\Utility\TimeFactory')
+ '\OCA\News\Utility\TimeFactory')
->disableOriginalConstructor()
->getMock();
$timeFactory->expects($this->any())
diff --git a/tests/unit/businesslayer/ItemBusinessLayerTest.php b/tests/unit/businesslayer/ItemBusinessLayerTest.php
index c120b753d..2909dae28 100644
--- a/tests/unit/businesslayer/ItemBusinessLayerTest.php
+++ b/tests/unit/businesslayer/ItemBusinessLayerTest.php
@@ -27,8 +27,7 @@ namespace OCA\News\BusinessLayer;
require_once(__DIR__ . "/../../classloader.php");
-use \OCA\AppFramework\Db\DoesNotExistException;
-
+use \OCA\News\Db\DoesNotExistException;
use \OCA\News\Db\Item;
use \OCA\News\Db\StatusFlag;
use \OCA\News\Db\FeedType;
@@ -49,7 +48,7 @@ class ItemBusinessLayerTest extends \OCA\AppFramework\Utility\TestUtility {
protected function setUp(){
$this->time = 222;
$timeFactory = $this->getMockBuilder(
- '\OCA\AppFramework\Utility\TimeFactory')
+ '\OCA\News\Utility\TimeFactory')
->disableOriginalConstructor()
->getMock();
$timeFactory->expects($this->any())
diff --git a/tests/unit/controller/ExportControllerTest.php b/tests/unit/controller/ExportControllerTest.php
index 2b9d41dde..542053edf 100644
--- a/tests/unit/controller/ExportControllerTest.php
+++ b/tests/unit/controller/ExportControllerTest.php
@@ -29,8 +29,6 @@ use \OCA\AppFramework\Http\Request;
use \OCA\AppFramework\Http\TextDownloadResponse;
use \OCA\AppFramework\Http\JSONResponse;
use \OCA\AppFramework\Utility\ControllerTestUtility;
-use \OCA\AppFramework\Db\DoesNotExistException;
-use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
use \OCA\News\Utility\OPMLExporter;
use \OCA\News\Db\Item;
diff --git a/tests/unit/controller/PageControllerTest.php b/tests/unit/controller/PageControllerTest.php
index 852b891a8..ddb9f9c88 100644
--- a/tests/unit/controller/PageControllerTest.php
+++ b/tests/unit/controller/PageControllerTest.php
@@ -28,8 +28,6 @@ namespace OCA\News\Controller;
use \OCA\AppFramework\Http\Request;
use \OCA\AppFramework\Http\TemplateResponse;
use \OCA\AppFramework\Utility\ControllerTestUtility;
-use \OCA\AppFramework\Db\DoesNotExistException;
-use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
require_once(__DIR__ . "/../../classloader.php");
diff --git a/tests/unit/controller/UserSettingsControllerTest.php b/tests/unit/controller/UserSettingsControllerTest.php
index 0f2be1bc0..d6c76ddb9 100644
--- a/tests/unit/controller/UserSettingsControllerTest.php
+++ b/tests/unit/controller/UserSettingsControllerTest.php
@@ -28,8 +28,6 @@ namespace OCA\News\Controller;
use \OCA\AppFramework\Http\Request;
use \OCA\AppFramework\Http\JSONResponse;
use \OCA\AppFramework\Utility\ControllerTestUtility;
-use \OCA\AppFramework\Db\DoesNotExistException;
-use \OCA\AppFramework\Db\MultipleObjectsReturnedException;
require_once(__DIR__ . "/../../classloader.php");
diff --git a/tests/unit/db/EntityTest.php b/tests/unit/db/EntityTest.php
new file mode 100644
index 000000000..c57d9997e
--- /dev/null
+++ b/tests/unit/db/EntityTest.php
@@ -0,0 +1,207 @@
+<?php
+
+/**
+* ownCloud - News
+*
+* @author Alessandro Copyright
+* @author Bernhard Posselt
+* @copyright 2012 Alessandro Cosentino cosenal@gmail.com
+* @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
+*
+* This library is free software; you can redistribute it and/or
+* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+* License as published by the Free Software Foundation; either
+* version 3 of the License, or any later version.
+*
+* This library is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+*
+* You should have received a copy of the GNU Affero General Public
+* License along with this library. If not, see <http://www.gnu.org/licenses/>.
+*
+*/
+
+namespace OCA\News\Db;
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class TestEntity extends Entity {
+ public $name;
+ public $email;
+ public $testId;
+ public $preName;
+
+ public function __construct(){
+ $this->addType('testId', 'integer');
+ }
+};
+
+
+class EntityTest extends \PHPUnit_Framework_TestCase {
+
+ private $entity;
+
+ protected function setUp(){
+ $this->entity = new TestEntity();
+ }
+
+
+ public function testResetUpdatedFields(){
+ $entity = new TestEntity();
+ $entity->setId(3);
+ $entity->resetUpdatedFields();
+
+ $this->assertEquals(array(), $entity->getUpdatedFields());
+ }
+
+
+ public function testFromRow(){
+ $row = array(
+ 'pre_name' => 'john',
+ 'email' => 'john@something.com'
+ );
+ $this->entity = TestEntity::fromRow($row);
+
+ $this->assertEquals($row['pre_name'], $this->entity->getPreName());
+ $this->assertEquals($row['email'], $this->entity->getEmail());
+ }
+
+
+ public function testGetSetId(){
+ $id = 3;
+ $this->entity->setId(3);
+
+ $this->assertEquals($id, $this->entity->getId());
+ }
+
+
+ public function testColumnToPropertyNoReplacement(){
+ $column = 'my';
+ $this->assertEquals('my',
+ $this->entity->columnToProperty($column));
+ }
+
+
+ public function testColumnToProperty(){
+ $column = 'my_attribute';
+ $this->assertEquals('myAttribute',
+ $this->entity->columnToProperty($column));
+ }
+
+
+ public function testPropertyToColumnNoReplacement(){
+ $property = 'my';
+ $this->assertEquals('my',
+ $this->entity->propertyToColumn($property));
+ }
+
+
+ public function testSetterMarksFieldUpdated(){
+ $id = 3;
+ $this->entity->setId(3);
+
+ $this->assertContains('id', $this->entity->getUpdatedFields());
+ }
+
+
+ public function testCallShouldOnlyWorkForGetterSetter(){
+ $this->setExpectedException('\BadFunctionCallException');
+
+ $this->entity->something();
+ }
+
+
+ public function testGetterShouldFailIfAttributeNotDefined(){
+ $this->setExpectedException('\BadFunctionCallException');
+
+ $this->entity->getTest();
+ }
+
+
+ public function testSetterShouldFailIfAttributeNotDefined(){
+ $this->setExpectedException('\BadFunctionCallException');
+
+ $this->entity->setTest();
+ }
+
+
+ public function testFromRowShouldNotAssignEmptyArray(){
+ $row = array();
+ $entity2 = new TestEntity();
+
+ $this->entity = TestEntity::fromRow($row);
+ $this->assertEquals($entity2, $this->entity);
+ }
+
+
+ public function testIdGetsConvertedToInt(){
+ $row = array('id' => '4');
+
+ $this->entity = TestEntity::fromRow($row);
+ $this->assertSame(4, $this->entity->getId());
+ }
+
+
+ public function testSetType(){
+ $row = array('testId' => '4');
+
+ $this->entity = TestEntity::fromRow($row);
+ $this->assertSame(4, $this->entity->getTestId());
+ }
+
+
+ public function testFromParams(){
+ $params = array(
+ 'testId' => 4,
+ 'email' => 'john@doe'
+ );
+
+ $entity = TestEntity::fromParams($params);
+
+ $this->assertEquals($params['testId'], $entity->getTestId());
+ $this->assertEquals($params['email'], $entity->getEmail());
+ $this->assertTrue($entity instanceof TestEntity);
+ }
+
+ public function testSlugify(){
+ $entity = new TestEntity();
+ $entity->setName('Slugify this!');
+ $this->assertEquals('slugify-this', $entity->slugify('name'));
+ $entity->setName('°!"§$%&/()=?`´ß\}][{³²#\'+~*-_.:,;<>|äöüÄÖÜSlugify this!');
+ $this->assertEquals('slugify-this', $entity->slugify('name'));
+ }
+
+
+ public function testSetterCasts() {
+ $entity = new TestEntity();
+ $entity->setId('3');
+ $this->assertSame(3, $entity->getId());
+ }
+
+
+ public function testSetterDoesNotCastOnNull() {
+ $entity = new TestEntity();
+ $entity->setId(null);
+ $this->assertSame(null, $entity->getId());
+ }
+
+
+ public function testGetFieldTypes() {
+ $entity = new TestEntity();
+ $this->assertEquals(array(
+ 'id' => 'integer',
+ 'testId' => 'integer'
+ ), $entity->getFieldTypes());
+ }
+
+
+ public function testGetItInt() {
+ $entity = new TestEntity();
+ $entity->setId(3);
+ $this->assertEquals('integer', gettype($entity->getId()));
+ }
+
+} \ No newline at end of file
diff --git a/tests/unit/db/FeedMapperTest.php b/tests/unit/db/FeedMapperTest.php
index f347e9732..d38d4c230 100644
--- a/tests/unit/db/FeedMapperTest.php
+++ b/tests/unit/db/FeedMapperTest.php
@@ -95,7 +95,7 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$params = array($id, $userId);
$this->setMapperResult($sql, $params);
- $this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException');
+ $this->setExpectedException('\OCA\News\Db\DoesNotExistException');
$result = $this->mapper->find($id, $userId);
}
@@ -122,7 +122,7 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$params = array($id, $userId);
$this->setMapperResult($sql, $params, $rows);
- $this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException');
+ $this->setExpectedException('\OCA\News\Db\MultipleObjectsReturnedException');
$result = $this->mapper->find($id, $userId);
}
@@ -238,7 +238,7 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$this->setMapperResult($sql,
array($urlHash, $this->user));
- $this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException');
+ $this->setExpectedException('\OCA\News\Db\DoesNotExistException');
$result = $this->mapper->findByUrlHash($urlHash, $this->user);
}
@@ -264,7 +264,7 @@ class FeedMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$this->setMapperResult($sql,
array($urlHash, $this->user), $rows);
- $this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException');
+ $this->setExpectedException('\OCA\News\Db\MultipleObjectsReturnedException');
$result = $this->mapper->findByUrlHash($urlHash, $this->user);
}
diff --git a/tests/unit/db/FolderMapperTest.php b/tests/unit/db/FolderMapperTest.php
index 6579e05a6..e4d1e5542 100644
--- a/tests/unit/db/FolderMapperTest.php
+++ b/tests/unit/db/FolderMapperTest.php
@@ -78,7 +78,7 @@ class FolderMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$this->setMapperResult($sql, array($id, $userId));
- $this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException');
+ $this->setExpectedException('\OCA\News\Db\DoesNotExistException');
$result = $this->folderMapper->find($id, $userId);
}
@@ -96,7 +96,7 @@ class FolderMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$this->setMapperResult($sql, array($id, $userId), $rows);
- $this->setExpectedException('\OCA\AppFramework\Db\MultipleObjectsReturnedException');
+ $this->setExpectedException('\OCA\News\Db\MultipleObjectsReturnedException');
$result = $this->folderMapper->find($id, $userId);
}
diff --git a/tests/unit/db/ItemMapperTest.php b/tests/unit/db/ItemMapperTest.php
index 0d5289786..cfef4c929 100644
--- a/tests/unit/db/ItemMapperTest.php
+++ b/tests/unit/db/ItemMapperTest.php
@@ -399,7 +399,7 @@ class ItemMapperTest extends \OCA\AppFramework\Utility\MapperTestUtility {
$rows = array();
$this->setMapperResult($sql, $params, $rows);
- $this->setExpectedException('\OCA\AppFramework\Db\DoesNotExistException');
+ $this->setExpectedException('\OCA\News\Db\DoesNotExistException');
$result = $this->mapper->getNewestItemId($this->user);
}
diff --git a/tests/unit/db/MapperFactoryTest.php b/tests/unit/db/MapperFactoryTest.php
index c1be2095b..c553b2aff 100644
--- a/tests/unit/db/MapperFactoryTest.php
+++ b/tests/unit/db/MapperFactoryTest.php
@@ -29,7 +29,7 @@ require_once(__DIR__ . "/../../classloader.php");
-class MapperTest extends \PHPUnit_Framework_TestCase {
+class MapperFactoryTest extends \PHPUnit_Framework_TestCase {
public function setUp() {
diff --git a/tests/unit/db/MapperTest.php b/tests/unit/db/MapperTest.php
new file mode 100644
index 000000000..b41348194
--- /dev/null
+++ b/tests/unit/db/MapperTest.php
@@ -0,0 +1,267 @@
+<?php
+
+/**
+ * ownCloud - News
+ *
+ * @author Bernhard Posselt
+ * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\News\Db;
+
+use OCA\AppFramework\Core\API;
+use OCA\AppFramework\Utility\MapperTestUtility;
+
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class Example extends Entity {
+ public $preName;
+ public $email;
+};
+
+
+class ExampleMapper extends Mapper {
+ public function __construct(API $api){ parent::__construct($api, 'table'); }
+ public function find($table, $id){ return $this->findOneQuery($table, $id); }
+ public function findOneEntity($table, $id){ return $this->findEntity($table, $id); }
+ public function findAll($table){ return $this->findAllQuery($table); }
+ public function findAllEntities($table){ return $this->findEntities($table); }
+ public function mapRow($row){ return $this->mapRowToEntity($row); }
+ public function pDeleteQuery($table, $id){ $this->deleteQuery($table, $id); }
+}
+
+
+class MapperTest extends MapperTestUtility {
+
+ private $mapper;
+
+ public function setUp(){
+ $this->beforeEach();
+ $this->mapper = new ExampleMapper($this->api);
+ }
+
+
+ public function testMapperShouldSetTableName(){
+ $this->assertEquals('*PREFIX*table', $this->mapper->getTableName());
+ }
+
+
+ public function testFindQuery(){
+ $sql = 'hi';
+ $params = array('jo');
+ $rows = array(
+ array('hi')
+ );
+ $row = $this->setMapperResult($sql, $params, $rows);
+ $this->mapper->find($sql, $params);
+ }
+
+ public function testFindEntity(){
+ $sql = 'hi';
+ $params = array('jo');
+ $rows = array(
+ array('pre_name' => 'hi')
+ );
+ $row = $this->setMapperResult($sql, $params, $rows);
+ $this->mapper->findOneEntity($sql, $params);
+ }
+
+ public function testFindNotFound(){
+ $sql = 'hi';
+ $params = array('jo');
+ $rows = array();
+ $row = $this->setMapperResult($sql, $params, $rows);
+ $this->setExpectedException(
+ '\OCA\News\Db\DoesNotExistException');
+ $this->mapper->find($sql, $params);
+ }
+
+ public function testFindEntityNotFound(){
+ $sql = 'hi';
+ $params = array('jo');
+ $rows = array();
+ $row = $this->setMapperResult($sql, $params, $rows);
+ $this->setExpectedException(
+ '\OCA\News\Db\DoesNotExistException');
+ $this->mapper->findOneEntity($sql, $params);
+ }
+
+ public function testFindMultiple(){
+ $sql = 'hi';
+ $params = array('jo');
+ $rows = array(
+ array('jo'), array('ho')
+ );
+ $row = $this->setMapperResult($sql, $params, $rows);
+ $this->setExpectedException(
+ '\OCA\News\Db\MultipleObjectsReturnedException');
+ $this->mapper->find($sql, $params);
+ }
+
+ public function testFindEntityMultiple(){
+ $sql = 'hi';
+ $params = array('jo');
+ $rows = array(
+ array('jo'), array('ho')
+ );
+ $row = $this->setMapperResult($sql, $params, $rows);
+ $this->setExpectedException(
+ '\OCA\News\Db\MultipleObjectsReturnedException');
+ $this->mapper->findOneEntity($sql, $params);
+ }
+
+
+ public function testDelete(){
+ $sql = 'DELETE FROM `*PREFIX*table` WHERE `id` = ?';
+ $params = array(2);
+
+ $this->setMapperResult($sql, $params);
+ $entity = new Example();
+ $entity->setId($params[0]);
+
+ $this->mapper->delete($entity);
+ }
+
+
+ public function testCreate(){
+ $this->api->expects($this->once())
+ ->method('getInsertId')
+ ->with($this->equalTo('*PREFIX*table'))
+ ->will($this->returnValue(3));
+ $this->mapper = new ExampleMapper($this->api);
+
+ $sql = 'INSERT INTO `*PREFIX*table`(`pre_name`,`email`) ' .
+ 'VALUES(?,?)';
+ $params = array('john', 'my@email');
+ $entity = new Example();
+ $entity->setPreName($params[0]);
+ $entity->setEmail($params[1]);
+
+ $this->setMapperResult($sql, $params);
+
+ $this->mapper->insert($entity);
+ }
+
+
+ public function testCreateShouldReturnItemWithCorrectInsertId(){
+ $this->api->expects($this->once())
+ ->method('getInsertId')
+ ->with($this->equalTo('*PREFIX*table'))
+ ->will($this->returnValue(3));
+ $this->mapper = new ExampleMapper($this->api);
+
+ $sql = 'INSERT INTO `*PREFIX*table`(`pre_name`,`email`) ' .
+ 'VALUES(?,?)';
+ $params = array('john', 'my@email');
+ $entity = new Example();
+ $entity->setPreName($params[0]);
+ $entity->setEmail($params[1]);
+
+ $this->setMapperResult($sql, $params);
+
+ $result = $this->mapper->insert($entity);
+
+ $this->assertEquals(3, $result->getId());
+ }
+
+
+ public function testUpdate(){
+ $sql = 'UPDATE `*PREFIX*table` ' .
+ 'SET ' .
+ '`pre_name` = ?,'.
+ '`email` = ? ' .
+ 'WHERE `id` = ?';
+
+ $params = array('john', 'my@email', 1);
+ $entity = new Example();
+ $entity->setPreName($params[0]);
+ $entity->setEmail($params[1]);
+ $entity->setId($params[2]);
+
+ $this->setMapperResult($sql, $params);
+
+ $this->mapper->update($entity);
+ }
+
+
+ public function testUpdateNoId(){
+ $sql = 'UPDATE `*PREFIX*table` ' .
+ 'SET ' .
+ '`pre_name` = ?,'.
+ '`email` = ? ' .
+ 'WHERE `id` = ?';
+
+ $params = array('john', 'my@email');
+ $entity = new Example();
+ $entity->setPreName($params[0]);
+ $entity->setEmail($params[1]);
+
+ $this->setExpectedException('InvalidArgumentException');
+
+ $this->mapper->update($entity);
+ }
+
+
+ public function testMapRowToEntity(){
+ $entity1 = $this->mapper->mapRow(array('pre_name' => 'test1', 'email' => 'test2'));
+ $entity2 = new Example();
+ $entity2->setPreName('test1');
+ $entity2->setEmail('test2');
+ $entity2->resetUpdatedFields();
+ $this->assertEquals($entity2, $entity1);
+ }
+
+ public function testFindEntities(){
+ $sql = 'hi';
+ $rows = array(
+ array('pre_name' => 'hi')
+ );
+ $entity = new Example();
+ $entity->setPreName('hi');
+ $entity->resetUpdatedFields();
+ $row = $this->setMapperResult($sql, array(), $rows);
+ $result = $this->mapper->findAllEntities($sql);
+ $this->assertEquals(array($entity), $result);
+ }
+
+ public function testFindEntitiesNotFound(){
+ $sql = 'hi';
+ $rows = array();
+ $row = $this->setMapperResult($sql, array(), $rows);
+ $result = $this->mapper->findAllEntities($sql);
+ $this->assertEquals(array(), $result);
+ }
+
+ public function testFindEntitiesMultiple(){
+ $sql = 'hi';
+ $rows = array(
+ array('pre_name' => 'jo'), array('email' => 'ho')
+ );
+ $entity1 = new Example();
+ $entity1->setPreName('jo');
+ $entity1->resetUpdatedFields();
+ $entity2 = new Example();
+ $entity2->setEmail('ho');
+ $entity2->resetUpdatedFields();
+ $row = $this->setMapperResult($sql, array(), $rows);
+ $result = $this->mapper->findAllEntities($sql);
+ $this->assertEquals(array($entity1, $entity2), $result);
+ }
+} \ No newline at end of file
diff --git a/tests/unit/fetcher/FeedFetcherTest.php b/tests/unit/fetcher/FeedFetcherTest.php
index b4ec42e60..fa978568e 100644
--- a/tests/unit/fetcher/FeedFetcherTest.php
+++ b/tests/unit/fetcher/FeedFetcherTest.php
@@ -67,7 +67,7 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
->disableOriginalConstructor()
->getMock();
$this->coreFactory = $this->getMockBuilder(
- '\OCA\AppFramework\Utility\SimplePieAPIFactory')
+ '\OCA\News\Utility\SimplePieAPIFactory')
->disableOriginalConstructor()
->getMock();
$this->coreFactory->expects($this->any())
@@ -78,12 +78,12 @@ class FeedFetcherTest extends \OCA\AppFramework\Utility\TestUtility {
->disableOriginalConstructor()
->getMock();
$this->faviconFetcher = $this->getMockBuilder(
- '\OCA\AppFramework\Utility\FaviconFetcher')
+ '\OCA\News\Utility\FaviconFetcher')
->disableOriginalConstructor()
->getMock();
$this->time = 2323;
$timeFactory = $this->getMockBuilder(
- '\OCA\AppFramework\Utility\TimeFactory')
+ '\OCA\News\Utility\TimeFactory')
->disableOriginalConstructor()
->getMock();
$timeFactory->expects($this->any())
diff --git a/tests/unit/utility/FaviconFetcherTest.php b/tests/unit/utility/FaviconFetcherTest.php
new file mode 100644
index 000000000..4f11c49e1
--- /dev/null
+++ b/tests/unit/utility/FaviconFetcherTest.php
@@ -0,0 +1,194 @@
+<?php
+
+/**
+ * ownCloud - News
+ *
+ * @author Bernhard Posselt
+ * @copyright 2012 Bernhard Posselt dev@bernhard-posselt.com
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+
+namespace OCA\News\Utility;
+
+
+require_once(__DIR__ . "/../../classloader.php");
+
+
+class FaviconFetcherTest extends \PHPUnit_Framework_TestCase {
+
+ private $fetcher;
+ private $fileFactory;
+ private $png;
+
+ protected function setUp(){
+ $this->png = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A";
+ $this->fileFactory = $this->getMockBuilder(
+ '\OCA\News\Utility\SimplePieAPIFactory')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->fetcher = new FaviconFetcher($this->fileFactory);
+ }
+
+
+ protected function getFileMock($body='') {
+ $mock = $this->getMockBuilder('\SimplePie_File')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $mock->body = $body;
+ return $mock;
+ }
+
+
+ protected function getFileMockCallback($onEqual, $returnMock) {
+ $defaultMock = $this->getFileMock();
+
+ return function($url) use ($onEqual, $returnMock, $defaultMock) {
+ if($url === $onEqual){
+ return $returnMock;
+ } else {
+ return $defaultMock;
+ }
+ };
+ }
+
+
+ public function testFetchNoResponseReturnsNull() {
+ $mock = $this->getFileMock();
+
+ $this->fileFactory->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnValue($mock));
+
+ $favicon = $this->fetcher->fetch('dfdf');
+ $this->assertNull($favicon);
+ }
+
+
+ public function testFetchFaviconFaviconDotIcoHttp(){
+ $url = ' sub.google.com ';
+ $mock = $this->getFileMock($this->png);
+
+ $callback = $this->getFileMockCallback(
+ 'http://sub.google.com/favicon.ico', $mock);
+
+ $this->fileFactory->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnCallback($callback));
+
+ $favicon = $this->fetcher->fetch($url);
+
+ $this->assertEquals('http://sub.google.com/favicon.ico', $favicon);
+ }
+
+
+ public function testFetchFaviconFaviconDotIcoHttpBaseUrl(){
+ $url = 'https://google.com/sometetst/dfladsf';
+ $mock = $this->getFileMock($this->png);
+
+ $callback = $this->getFileMockCallback(
+ 'https://google.com/favicon.ico', $mock);
+
+ $this->fileFactory->expects($this->any())
+ ->method('getFile')
+ ->will($this->returnCallback($callback));
+
+ $favicon = $this->fetcher->fetch($url);
+
+ $this->assertEquals('https://google.com/favicon.ico', $favicon);
+ }
+
+
+ private function getFaviconHTML($faviconPath) {
+ return "<html>
+ <head>
+ <link rel=\"shortcut icon\" href=\"$faviconPath\" />
+ </head>
+ <body></body>
+ </html>";
+ }
+
+
+ public function testIconAbspathHTTP() {
+ $faviconPath = "/owncloud/core/img/favicon.png";
+ $html = $this->getFaviconHTML($faviconPath);
+
+ $url = 'http://google.com';
+ $pageMock = $this->getFileMock($html);
+ $pngMock = $this->getFileMock($this->png);
+
+ $this->fileFactory->expects($this-