Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/server.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/tests/lib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib')
-rw-r--r--tests/lib/AppFramework/Db/QBMapperTest.php21
-rw-r--r--tests/lib/DB/MigratorTest.php2
-rw-r--r--tests/lib/Metadata/FileMetadataMapperTest.php83
3 files changed, 99 insertions, 7 deletions
diff --git a/tests/lib/AppFramework/Db/QBMapperTest.php b/tests/lib/AppFramework/Db/QBMapperTest.php
index b03034056d2..96d319923b3 100644
--- a/tests/lib/AppFramework/Db/QBMapperTest.php
+++ b/tests/lib/AppFramework/Db/QBMapperTest.php
@@ -47,6 +47,7 @@ class QBTestEntity extends Entity {
protected $stringProp;
protected $integerProp;
protected $booleanProp;
+ protected $jsonProp;
public function __construct() {
$this->addType('intProp', 'int');
@@ -54,11 +55,10 @@ class QBTestEntity extends Entity {
$this->addType('stringProp', 'string');
$this->addType('integerProp', 'integer');
$this->addType('booleanProp', 'boolean');
+ $this->addType('jsonProp', 'json');
}
}
-;
-
/**
* Class QBTestMapper
*
@@ -69,7 +69,7 @@ class QBTestMapper extends QBMapper {
parent::__construct($db, 'table');
}
- public function getParameterTypeForPropertyForTest(Entity $entity, string $property): int {
+ public function getParameterTypeForPropertyForTest(Entity $entity, string $property) {
return parent::getParameterTypeForProperty($entity, $property);
}
}
@@ -171,6 +171,7 @@ class QBMapperTest extends \Test\TestCase {
$entity->setStringProp('string');
$entity->setIntegerProp(456);
$entity->setBooleanProp(false);
+ $entity->setJsonProp(["hello" => "world"]);
$idParam = $this->qb->createNamedParameter('id', IQueryBuilder::PARAM_INT);
$intParam = $this->qb->createNamedParameter('int_prop', IQueryBuilder::PARAM_INT);
@@ -178,8 +179,9 @@ class QBMapperTest extends \Test\TestCase {
$stringParam = $this->qb->createNamedParameter('string_prop', IQueryBuilder::PARAM_STR);
$integerParam = $this->qb->createNamedParameter('integer_prop', IQueryBuilder::PARAM_INT);
$booleanParam = $this->qb->createNamedParameter('boolean_prop', IQueryBuilder::PARAM_BOOL);
+ $jsonParam = $this->qb->createNamedParameter('json_prop', IQueryBuilder::PARAM_JSON);
- $this->qb->expects($this->exactly(6))
+ $this->qb->expects($this->exactly(7))
->method('createNamedParameter')
->withConsecutive(
[$this->equalTo(123), $this->equalTo(IQueryBuilder::PARAM_INT)],
@@ -187,17 +189,19 @@ class QBMapperTest extends \Test\TestCase {
[$this->equalTo('string'), $this->equalTo(IQueryBuilder::PARAM_STR)],
[$this->equalTo(456), $this->equalTo(IQueryBuilder::PARAM_INT)],
[$this->equalTo(false), $this->equalTo(IQueryBuilder::PARAM_BOOL)],
- [$this->equalTo(789), $this->equalTo(IQueryBuilder::PARAM_INT)]
+ [$this->equalTo(["hello" => "world"]), $this->equalTo(IQueryBuilder::PARAM_JSON)],
+ [$this->equalTo(789), $this->equalTo(IQueryBuilder::PARAM_INT)],
);
- $this->qb->expects($this->exactly(5))
+ $this->qb->expects($this->exactly(6))
->method('set')
->withConsecutive(
[$this->equalTo('int_prop'), $this->equalTo($intParam)],
[$this->equalTo('bool_prop'), $this->equalTo($boolParam)],
[$this->equalTo('string_prop'), $this->equalTo($stringParam)],
[$this->equalTo('integer_prop'), $this->equalTo($integerParam)],
- [$this->equalTo('boolean_prop'), $this->equalTo($booleanParam)]
+ [$this->equalTo('boolean_prop'), $this->equalTo($booleanParam)],
+ [$this->equalTo('json_prop'), $this->equalTo($jsonParam)]
);
$this->expr->expects($this->once())
@@ -227,6 +231,9 @@ class QBMapperTest extends \Test\TestCase {
$stringType = $this->mapper->getParameterTypeForPropertyForTest($entity, 'stringProp');
$this->assertEquals(IQueryBuilder::PARAM_STR, $stringType, 'String type property mapping incorrect');
+ $jsonType = $this->mapper->getParameterTypeForPropertyForTest($entity, 'jsonProp');
+ $this->assertEquals(IQueryBuilder::PARAM_JSON, $jsonType, 'JSON type property mapping incorrect');
+
$unknownType = $this->mapper->getParameterTypeForPropertyForTest($entity, 'someProp');
$this->assertEquals(IQueryBuilder::PARAM_STR, $unknownType, 'Unknown type property mapping incorrect');
}
diff --git a/tests/lib/DB/MigratorTest.php b/tests/lib/DB/MigratorTest.php
index 114cf03d7be..af44159efa3 100644
--- a/tests/lib/DB/MigratorTest.php
+++ b/tests/lib/DB/MigratorTest.php
@@ -267,6 +267,8 @@ class MigratorTest extends \Test\TestCase {
[ParameterType::INTEGER, 1234, Types::INTEGER, false],
[ParameterType::INTEGER, 0, Types::INTEGER, false], // Integer 0 is not stored as Null and therefor works
+
+ [ParameterType::STRING, '{"a": 2}', Types::JSON, false],
];
}
diff --git a/tests/lib/Metadata/FileMetadataMapperTest.php b/tests/lib/Metadata/FileMetadataMapperTest.php
new file mode 100644
index 00000000000..8e385351be2
--- /dev/null
+++ b/tests/lib/Metadata/FileMetadataMapperTest.php
@@ -0,0 +1,83 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2022 Carl Schwan <carl@carlschwan.eu>
+ * @license AGPL-3.0-or-later
+ *
+ * This code is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program 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, version 3,
+ * along with this program. If not, see <http://www.gnu.org/licenses/>
+ *
+ */
+
+namespace Test\Metadata;
+
+use OC\Metadata\FileMetadataMapper;
+use OC\Metadata\FileMetadata;
+
+/**
+ * @group DB
+ * @package Test\DB\QueryBuilder
+ */
+class FileMetadataMapperTest extends \Test\TestCase {
+ /** @var IDBConnection */
+ protected $connection;
+
+ /** @var SystemConfig|\PHPUnit\Framework\MockObject\MockObject */
+ protected $config;
+
+ protected function setUp(): void {
+ parent::setUp();
+
+ $this->connection = \OC::$server->getDatabaseConnection();
+ $this->mapper = new FileMetadataMapper($this->connection);
+ }
+
+ public function testFindForGroupForFiles() {
+ $file1 = new FileMetadata();
+ $file1->setId(1);
+ $file1->setGroupName('size');
+ $file1->setMetadata([]);
+
+ $file2 = new FileMetadata();
+ $file2->setId(2);
+ $file2->setGroupName('size');
+ $file2->setMetadata(['width' => 293, 'height' => 23]);
+
+ // not added, it's the default
+ $file3 = new FileMetadata();
+ $file3->setId(3);
+ $file3->setGroupName('size');
+ $file3->setMetadata([]);
+
+ $file4 = new FileMetadata();
+ $file4->setId(4);
+ $file4->setGroupName('size');
+ $file4->setMetadata(['complex' => ["yes", "maybe" => 34.0]]);
+
+ $this->mapper->insert($file1);
+ $this->mapper->insert($file2);
+ $this->mapper->insert($file4);
+
+ $files = $this->mapper->findForGroupForFiles([1, 2, 3, 4], 'size');
+
+ $this->assertEquals($files[1]->getMetadata(), $file1->getMetadata());
+ $this->assertEquals($files[2]->getMetadata(), $file2->getMetadata());
+ $this->assertEquals($files[3]->getMetadata(), $file3->getMetadata());
+ $this->assertEquals($files[4]->getMetadata(), $file4->getMetadata());
+
+ $this->mapper->clear(1);
+ $this->mapper->clear(2);
+ $this->mapper->clear(4);
+ }
+}