aboutsummaryrefslogtreecommitdiffstats
path: root/tests/lib/AppFramework/Db/EntityTest.php
diff options
context:
space:
mode:
Diffstat (limited to 'tests/lib/AppFramework/Db/EntityTest.php')
-rw-r--r--tests/lib/AppFramework/Db/EntityTest.php44
1 files changed, 36 insertions, 8 deletions
diff --git a/tests/lib/AppFramework/Db/EntityTest.php b/tests/lib/AppFramework/Db/EntityTest.php
index 8e6e6dcd645..5b953a25c1a 100644
--- a/tests/lib/AppFramework/Db/EntityTest.php
+++ b/tests/lib/AppFramework/Db/EntityTest.php
@@ -9,6 +9,7 @@
namespace Test\AppFramework\Db;
use OCP\AppFramework\Db\Entity;
+use OCP\DB\Types;
use PHPUnit\Framework\Constraint\IsType;
/**
@@ -29,6 +30,10 @@ use PHPUnit\Framework\Constraint\IsType;
* @method bool isAnotherBool()
* @method string getLongText()
* @method void setLongText(string $longText)
+ * @method \DateTime getTime()
+ * @method void setTime(\DateTime $time)
+ * @method \DateTimeImmutable getDatetime()
+ * @method void setDatetime(\DateTimeImmutable $datetime)
*/
class TestEntity extends Entity {
protected $name;
@@ -38,12 +43,16 @@ class TestEntity extends Entity {
protected $trueOrFalse;
protected $anotherBool;
protected $longText;
+ protected $time;
+ protected $datetime;
public function __construct($name = null) {
- $this->addType('testId', 'integer');
+ $this->addType('testId', Types::INTEGER);
$this->addType('trueOrFalse', 'bool');
- $this->addType('anotherBool', 'boolean');
- $this->addType('longText', 'blob');
+ $this->addType('anotherBool', Types::BOOLEAN);
+ $this->addType('longText', Types::BLOB);
+ $this->addType('time', Types::TIME);
+ $this->addType('datetime', Types::DATETIME_IMMUTABLE);
$this->name = $name;
}
@@ -216,15 +225,34 @@ class EntityTest extends \Test\TestCase {
$this->assertSame($string, $entity->getLongText());
}
+ public function testSetterConvertsDatetime() {
+ $entity = new TestEntity();
+ $entity->setDatetime('2024-08-19 15:26:00');
+ $this->assertEquals(new \DateTimeImmutable('2024-08-19 15:26:00'), $entity->getDatetime());
+ }
+
+ public function testSetterDoesNotConvertNullOnDatetime() {
+ $entity = new TestEntity();
+ $entity->setDatetime(null);
+ $this->assertNull($entity->getDatetime());
+ }
+
+ public function testSetterConvertsTime() {
+ $entity = new TestEntity();
+ $entity->setTime('15:26:00');
+ $this->assertEquals(new \DateTime('15:26:00'), $entity->getTime());
+ }
public function testGetFieldTypes(): void {
$entity = new TestEntity();
$this->assertEquals([
- 'id' => 'integer',
- 'testId' => 'integer',
+ 'id' => Types::INTEGER,
+ 'testId' => Types::INTEGER,
'trueOrFalse' => 'bool',
- 'anotherBool' => 'boolean',
- 'longText' => 'blob',
+ 'anotherBool' => Types::BOOLEAN,
+ 'longText' => Types::BLOB,
+ 'time' => Types::TIME,
+ 'datetime' => Types::DATETIME_IMMUTABLE,
], $entity->getFieldTypes());
}
@@ -232,7 +260,7 @@ class EntityTest extends \Test\TestCase {
public function testGetItInt(): void {
$entity = new TestEntity();
$entity->setId(3);
- $this->assertEquals('integer', gettype($entity->getId()));
+ $this->assertEquals(Types::INTEGER, gettype($entity->getId()));
}