summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-05-13 00:10:36 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-05-13 00:10:36 +0200
commit6bceeea837f7412589317c1d08848238ba677862 (patch)
tree60169e80b21dc540ddf64be6cec06a9e56b2efe4 /tests
parent08647e4a791e48cdcac18535a6d9dccb2cc7063d (diff)
remove tests of built into oc7 classes
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/db/EntityTest.php194
-rw-r--r--tests/unit/db/MapperTest.php255
2 files changed, 0 insertions, 449 deletions
diff --git a/tests/unit/db/EntityTest.php b/tests/unit/db/EntityTest.php
deleted file mode 100644
index 9d41d6e82..000000000
--- a/tests/unit/db/EntityTest.php
+++ /dev/null
@@ -1,194 +0,0 @@
-<?php
-/**
- * ownCloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
- */
-
-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(){
- $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/MapperTest.php b/tests/unit/db/MapperTest.php
deleted file mode 100644
index 52c8f205d..000000000
--- a/tests/unit/db/MapperTest.php
+++ /dev/null
@@ -1,255 +0,0 @@
-<?php
-/**
- * ownCloud - News
- *
- * This file is licensed under the Affero General Public License version 3 or
- * later. See the COPYING file.
- *
- * @author Alessandro Cosentino <cosenal@gmail.com>
- * @author Bernhard Posselt <dev@bernhard-posselt.com>
- * @copyright Alessandro Cosentino 2012
- * @copyright Bernhard Posselt 2012, 2014
- */
-
-
-namespace OCA\News\Db;
-
-use OCA\News\Core\Db;
-use OCA\News\Utility\MapperTestUtility;
-
-
-require_once(__DIR__ . "/../../classloader.php");
-
-
-class Example extends Entity {
- public $preName;
- public $email;
-};
-
-
-class ExampleMapper extends Mapper {
- public function __construct(Db $db){ parent::__construct($db, '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->db = $this->getMockBuilder(
- '\OCA\News\Core\Db')
- ->disableOriginalConstructor()
- ->getMock();
- $this->mapper = new ExampleMapper($this->db);
- }
-
-
- public function testMapperShouldSetTableName(){
- $this->assertEquals('*PREFIX*table', $this->mapper->getTableName());
- }
-
-
- public function testFindQuery(){
- $sql = 'hi';
- $params = array('jo');
- $rows = array(
- array('hi')
- );
- $this->setMapperResult($sql, $params, $rows);
- $this->mapper->find($sql, $params);
- }
-
- public function testFindEntity(){
- $sql = 'hi';
- $params = array('jo');
- $rows = array(
- array('pre_name' => 'hi')
- );
- $this->setMapperResult($sql, $params, $rows);
- $this->mapper->findOneEntity($sql, $params);
- }
-
- public function testFindNotFound(){
- $sql = 'hi';
- $params = array('jo');
- $rows = array();
- $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();
- $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')
- );
- $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')
- );
- $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->db->expects($this->once())
- ->method('getInsertId')
- ->with($this->equalTo('*PREFIX*table'))
- ->will($this->returnValue(3));
- $this->mapper = new ExampleMapper($this->db);
-
- $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->db->expects($this->once())
- ->method('getInsertId')
- ->with($this->equalTo('*PREFIX*table'))
- ->will($this->returnValue(3));
- $this->mapper = new ExampleMapper($this->db);
-
- $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(){
- $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();
- $this->setMapperResult($sql, array(), $rows);
- $result = $this->mapper->findAllEntities($sql);
- $this->assertEquals(array($entity), $result);
- }
-
- public function testFindEntitiesNotFound(){
- $sql = 'hi';
- $rows = array();
- $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();
- $this->setMapperResult($sql, array(), $rows);
- $result = $this->mapper->findAllEntities($sql);
- $this->assertEquals(array($entity1, $entity2), $result);
- }
-} \ No newline at end of file