summaryrefslogtreecommitdiffstats
path: root/tests/lib/appframework
diff options
context:
space:
mode:
authorBernhard Posselt <dev@bernhard-posselt.com>2014-04-23 13:43:17 +0200
committerBernhard Posselt <dev@bernhard-posselt.com>2014-04-23 13:43:17 +0200
commit5199e4508ac0c1d3902434a9cd05987d053d40f0 (patch)
treed91739aeac078e7c9a1c50d01afd1bd37221c142 /tests/lib/appframework
parent309aa3bcd253d5584ff4b514874ef51a6623a621 (diff)
downloadnextcloud-server-5199e4508ac0c1d3902434a9cd05987d053d40f0.tar.gz
nextcloud-server-5199e4508ac0c1d3902434a9cd05987d053d40f0.zip
dont update entity and dont run an update query if an entity wasnt changed at all
Diffstat (limited to 'tests/lib/appframework')
-rw-r--r--tests/lib/appframework/db/EntityTest.php11
-rw-r--r--tests/lib/appframework/db/MapperTest.php14
2 files changed, 24 insertions, 1 deletions
diff --git a/tests/lib/appframework/db/EntityTest.php b/tests/lib/appframework/db/EntityTest.php
index f674f435e09..9de44b9b3ba 100644
--- a/tests/lib/appframework/db/EntityTest.php
+++ b/tests/lib/appframework/db/EntityTest.php
@@ -42,8 +42,9 @@ class TestEntity extends Entity {
public $testId;
public $preName;
- public function __construct(){
+ public function __construct($name=null){
$this->addType('testId', 'integer');
+ $this->name = $name;
}
};
@@ -211,4 +212,12 @@ class EntityTest extends \PHPUnit_Framework_TestCase {
$this->assertEquals('integer', gettype($entity->getId()));
}
+
+ public function testFieldsNotMarkedUpdatedIfNothingChanges() {
+ $entity = new TestEntity('hey');
+ $entity->setName('hey');
+ $this->assertEquals(0, count($entity->getUpdatedFields()));
+ }
+
+
} \ No newline at end of file
diff --git a/tests/lib/appframework/db/MapperTest.php b/tests/lib/appframework/db/MapperTest.php
index e21edbd05cf..4ddc4ef0422 100644
--- a/tests/lib/appframework/db/MapperTest.php
+++ b/tests/lib/appframework/db/MapperTest.php
@@ -217,6 +217,20 @@ class MapperTest extends MapperTestUtility {
}
+ public function testUpdateNothingChangedNoQuery(){
+ $params = array('john', 'my@email');
+ $entity = new Example();
+ $entity->setId(3);
+ $entity->setEmail($params[1]);
+ $entity->resetUpdatedFields();
+
+ $this->db->expects($this->never())
+ ->method('prepareQuery');
+
+ $this->mapper->update($entity);
+ }
+
+
public function testMapRowToEntity(){
$entity1 = $this->mapper->mapRow(array('pre_name' => 'test1', 'email' => 'test2'));
$entity2 = new Example();