Loading lib/Db/Booking.php +2 −2 Original line number Diff line number Diff line Loading @@ -45,9 +45,9 @@ use Safe\DateTimeImmutable; * @method void setDescription(?string $description) * @method string getEmail() * @method void setEmail(string $email) * @method int|null getStart() * @method int getStart() * @method void setStart(int $start) * @method int|null getEnd() * @method int getEnd() * @method void setEnd(int $end) * @method string getTimezone() * @method void setTimezone(string $timezone) Loading lib/Db/BookingMapper.php +1 −2 Original line number Diff line number Diff line Loading @@ -65,8 +65,7 @@ class BookingMapper extends QBMapper { public function deleteOutdated(int $validFor = 0) : int { $limit = $this->time->getTime() - ($validFor); $qb = $this->db->getQueryBuilder(); $qb->delete('*') ->from($this->getTableName()) $qb->delete($this->getTableName()) ->where($qb->expr()->lt('created_at', $qb->createNamedParameter($limit, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT)); return $qb->executeStatement(); Loading tests/php/integration/Db/AppointmentMapperTest.php→tests/php/integration/Db/AppointmentConfigMapperTest.php +46 −5 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ use OCA\Calendar\Db\AppointmentConfigMapper; use OCP\AppFramework\Db\DoesNotExistException; use OCP\IDBConnection; class AppointmentMapperTest extends TestCase { class AppointmentConfigMapperTest extends TestCase { use DatabaseTransaction; /** @var IDBConnection */ Loading @@ -59,7 +59,7 @@ class AppointmentMapperTest extends TestCase { public function testFindByIdNoData() { $this->expectException(DoesNotExistException::class); $this->mapper->findByIdForUser(1); $this->mapper->findByIdForUser(1, 'test'); } /** Loading @@ -67,6 +67,7 @@ class AppointmentMapperTest extends TestCase { */ public function testFindById() { $appointment = new AppointmentConfig(); $appointment->setToken('okens'); $appointment->setName('Test 2'); $appointment->setDescription('Test Description'); $appointment->setIncrement(15); Loading @@ -79,6 +80,8 @@ class AppointmentMapperTest extends TestCase { $id = $appointment->getId(); $appointment = $this->mapper->findById($id); $this->assertObjectHasAttribute('token', $appointment); $this->assertEquals('okens', $appointment->getToken()); $this->assertObjectHasAttribute('name', $appointment); $this->assertEquals('Test 2', $appointment->getName()); $this->assertObjectHasAttribute('description', $appointment); Loading @@ -87,16 +90,20 @@ class AppointmentMapperTest extends TestCase { $this->assertEquals(15, $appointment->getIncrement()); $this->assertObjectHasAttribute('length', $appointment); $this->assertEquals(60, $appointment->getLength()); $this->assertObjectHasAttribute('calendarUri', $appointment); $this->assertEquals('testuri', $appointment->getCalendarUri()); $this->assertObjectHasAttribute('targetCalendarUri', $appointment); $this->assertEquals('testuri', $appointment->getTargetCalendarUri()); $this->assertObjectHasAttribute('visibility', $appointment); $this->assertEquals(AppointmentConfig::VISIBILITY_PUBLIC, $appointment->getVisibility()); $this->assertObjectHasAttribute('userId', $appointment); $this->assertEquals('testuser', $appointment->getUserId()); } public function testFindAllForUser():void { /** * @depends testFindByIdNoData */ public function testFindByToken() { $appointment = new AppointmentConfig(); $appointment->setToken('okensdsadsas'); $appointment->setName('Test 2'); $appointment->setDescription('Test Description'); $appointment->setIncrement(15); Loading @@ -105,6 +112,39 @@ class AppointmentMapperTest extends TestCase { $appointment->setVisibility(AppointmentConfig::VISIBILITY_PUBLIC); $appointment->setUserId('testuser'); $appointment = $this->mapper->insert($appointment); $token = $appointment->getToken(); $appointment = $this->mapper->findByToken($token); $this->assertObjectHasAttribute('token', $appointment); $this->assertEquals('okensdsadsas', $appointment->getToken()); $this->assertObjectHasAttribute('name', $appointment); $this->assertEquals('Test 2', $appointment->getName()); $this->assertObjectHasAttribute('description', $appointment); $this->assertEquals('Test Description', $appointment->getDescription()); $this->assertObjectHasAttribute('increment', $appointment); $this->assertEquals(15, $appointment->getIncrement()); $this->assertObjectHasAttribute('length', $appointment); $this->assertEquals(60, $appointment->getLength()); $this->assertObjectHasAttribute('targetCalendarUri', $appointment); $this->assertEquals('testuri', $appointment->getTargetCalendarUri()); $this->assertObjectHasAttribute('visibility', $appointment); $this->assertEquals(AppointmentConfig::VISIBILITY_PUBLIC, $appointment->getVisibility()); $this->assertObjectHasAttribute('userId', $appointment); $this->assertEquals('testuser', $appointment->getUserId()); } public function testFindAllForUser():void { $appointment = new AppointmentConfig(); $appointment->setToken('frokns'); $appointment->setName('Test 3'); $appointment->setDescription('Test Description'); $appointment->setIncrement(15); $appointment->setLength(60); $appointment->setTargetCalendarUri('testuri'); $appointment->setVisibility(AppointmentConfig::VISIBILITY_PUBLIC); $appointment->setUserId('testuser'); $this->mapper->insert($appointment); $appointments = $this->mapper->findAllForUser('testuser'); Loading @@ -118,6 +158,7 @@ class AppointmentMapperTest extends TestCase { public function testDeleteById():void { $appointment = new AppointmentConfig(); $appointment->setToken('frokns'); $appointment->setName('Test 2'); $appointment->setDescription('Test Description'); $appointment->setIncrement(15); Loading tests/php/integration/Db/BookingMapperTest.php 0 → 100644 +129 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); /** * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> * * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * 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 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ namespace OCA\Calendar\Tests\Integration\Db; use BadFunctionCallException; use ChristophWurst\Nextcloud\Testing\DatabaseTransaction; use ChristophWurst\Nextcloud\Testing\TestCase; use InvalidArgumentException; use OCA\Calendar\Db\AppointmentConfig; use OCA\Calendar\Db\AppointmentConfigMapper; use OCA\Calendar\Db\Booking; use OCA\Calendar\Db\BookingMapper; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IDBConnection; class BookingMapperTest extends TestCase { use DatabaseTransaction; /** @var IDBConnection */ private $db; /** @var BookingMapper */ private $mapper; protected function setUp(): void { parent::setUp(); $this->db = \OC::$server->getDatabaseConnection(); $this->time = $this->createConfiguredMock(ITimeFactory::class, [ 'getTime' => 1635721200 ]); $this->mapper = new BookingMapper( $this->db, $this->time ); $qb = $this->db->getQueryBuilder(); $delete = $qb->delete($this->mapper->getTableName()); $delete->execute(); } public function testFindByIdNoData() { $this->expectException(DoesNotExistException::class); $this->mapper->findByToken('token'); } /** * @depends testFindByIdNoData */ public function testFindByToken() { $booking = new Booking(); $booking->setApptConfigId(1); $booking->setCreatedAt($this->time->getTime()); $booking->setToken('oken'); $booking->setDisplayName('Test'); $booking->setStart(123); $booking->setEnd(123); $booking->setEmail('test@test.com'); $booking->setTimezone('Europe/Berlin'); $booking = $this->mapper->insert($booking); $token = $booking->getToken(); $booking = $this->mapper->findByToken($token); $this->assertObjectHasAttribute('apptConfigId', $booking); $this->assertEquals('1', $booking->getApptConfigId()); $this->assertObjectHasAttribute('createdAt', $booking); $this->assertEquals($this->time->getTime(), $booking->getCreatedAt()); $this->assertObjectHasAttribute('token', $booking); $this->assertEquals('oken', $booking->getToken()); $this->assertObjectHasAttribute('displayName', $booking); $this->assertEquals('Test', $booking->getDisplayName()); $this->assertObjectHasAttribute('start', $booking); $this->assertEquals(123, $booking->getStart()); $this->assertObjectHasAttribute('end', $booking); $this->assertEquals(123, $booking->getEnd()); $this->assertObjectHasAttribute('email', $booking); $this->assertEquals('test@test.com', $booking->getEmail()); $this->assertObjectHasAttribute('timezone', $booking); $this->assertEquals('Europe/Berlin', $booking->getTimezone()); } public function testDeleteOutdated():void { $booking = new Booking(); $booking->setApptConfigId(1); $booking->setCreatedAt(891485); $booking->setToken('okfdfssdsdfen'); $booking->setDisplayName('Test'); $booking->setStart(123); $booking->setEnd(123); $booking->setEmail('test@test.com'); $booking->setTimezone('Europe/Berlin'); $booking = $this->mapper->insert($booking); $token = $booking->getToken(); $booking = $this->mapper->findByToken($token); $row = $this->mapper->deleteOutdated(86400); $this->assertEquals(1, $row); $this->expectException(DoesNotExistException::class); $this->mapper->findByToken($token); } } Loading
lib/Db/Booking.php +2 −2 Original line number Diff line number Diff line Loading @@ -45,9 +45,9 @@ use Safe\DateTimeImmutable; * @method void setDescription(?string $description) * @method string getEmail() * @method void setEmail(string $email) * @method int|null getStart() * @method int getStart() * @method void setStart(int $start) * @method int|null getEnd() * @method int getEnd() * @method void setEnd(int $end) * @method string getTimezone() * @method void setTimezone(string $timezone) Loading
lib/Db/BookingMapper.php +1 −2 Original line number Diff line number Diff line Loading @@ -65,8 +65,7 @@ class BookingMapper extends QBMapper { public function deleteOutdated(int $validFor = 0) : int { $limit = $this->time->getTime() - ($validFor); $qb = $this->db->getQueryBuilder(); $qb->delete('*') ->from($this->getTableName()) $qb->delete($this->getTableName()) ->where($qb->expr()->lt('created_at', $qb->createNamedParameter($limit, IQueryBuilder::PARAM_INT), IQueryBuilder::PARAM_INT)); return $qb->executeStatement(); Loading
tests/php/integration/Db/AppointmentMapperTest.php→tests/php/integration/Db/AppointmentConfigMapperTest.php +46 −5 Original line number Diff line number Diff line Loading @@ -34,7 +34,7 @@ use OCA\Calendar\Db\AppointmentConfigMapper; use OCP\AppFramework\Db\DoesNotExistException; use OCP\IDBConnection; class AppointmentMapperTest extends TestCase { class AppointmentConfigMapperTest extends TestCase { use DatabaseTransaction; /** @var IDBConnection */ Loading @@ -59,7 +59,7 @@ class AppointmentMapperTest extends TestCase { public function testFindByIdNoData() { $this->expectException(DoesNotExistException::class); $this->mapper->findByIdForUser(1); $this->mapper->findByIdForUser(1, 'test'); } /** Loading @@ -67,6 +67,7 @@ class AppointmentMapperTest extends TestCase { */ public function testFindById() { $appointment = new AppointmentConfig(); $appointment->setToken('okens'); $appointment->setName('Test 2'); $appointment->setDescription('Test Description'); $appointment->setIncrement(15); Loading @@ -79,6 +80,8 @@ class AppointmentMapperTest extends TestCase { $id = $appointment->getId(); $appointment = $this->mapper->findById($id); $this->assertObjectHasAttribute('token', $appointment); $this->assertEquals('okens', $appointment->getToken()); $this->assertObjectHasAttribute('name', $appointment); $this->assertEquals('Test 2', $appointment->getName()); $this->assertObjectHasAttribute('description', $appointment); Loading @@ -87,16 +90,20 @@ class AppointmentMapperTest extends TestCase { $this->assertEquals(15, $appointment->getIncrement()); $this->assertObjectHasAttribute('length', $appointment); $this->assertEquals(60, $appointment->getLength()); $this->assertObjectHasAttribute('calendarUri', $appointment); $this->assertEquals('testuri', $appointment->getCalendarUri()); $this->assertObjectHasAttribute('targetCalendarUri', $appointment); $this->assertEquals('testuri', $appointment->getTargetCalendarUri()); $this->assertObjectHasAttribute('visibility', $appointment); $this->assertEquals(AppointmentConfig::VISIBILITY_PUBLIC, $appointment->getVisibility()); $this->assertObjectHasAttribute('userId', $appointment); $this->assertEquals('testuser', $appointment->getUserId()); } public function testFindAllForUser():void { /** * @depends testFindByIdNoData */ public function testFindByToken() { $appointment = new AppointmentConfig(); $appointment->setToken('okensdsadsas'); $appointment->setName('Test 2'); $appointment->setDescription('Test Description'); $appointment->setIncrement(15); Loading @@ -105,6 +112,39 @@ class AppointmentMapperTest extends TestCase { $appointment->setVisibility(AppointmentConfig::VISIBILITY_PUBLIC); $appointment->setUserId('testuser'); $appointment = $this->mapper->insert($appointment); $token = $appointment->getToken(); $appointment = $this->mapper->findByToken($token); $this->assertObjectHasAttribute('token', $appointment); $this->assertEquals('okensdsadsas', $appointment->getToken()); $this->assertObjectHasAttribute('name', $appointment); $this->assertEquals('Test 2', $appointment->getName()); $this->assertObjectHasAttribute('description', $appointment); $this->assertEquals('Test Description', $appointment->getDescription()); $this->assertObjectHasAttribute('increment', $appointment); $this->assertEquals(15, $appointment->getIncrement()); $this->assertObjectHasAttribute('length', $appointment); $this->assertEquals(60, $appointment->getLength()); $this->assertObjectHasAttribute('targetCalendarUri', $appointment); $this->assertEquals('testuri', $appointment->getTargetCalendarUri()); $this->assertObjectHasAttribute('visibility', $appointment); $this->assertEquals(AppointmentConfig::VISIBILITY_PUBLIC, $appointment->getVisibility()); $this->assertObjectHasAttribute('userId', $appointment); $this->assertEquals('testuser', $appointment->getUserId()); } public function testFindAllForUser():void { $appointment = new AppointmentConfig(); $appointment->setToken('frokns'); $appointment->setName('Test 3'); $appointment->setDescription('Test Description'); $appointment->setIncrement(15); $appointment->setLength(60); $appointment->setTargetCalendarUri('testuri'); $appointment->setVisibility(AppointmentConfig::VISIBILITY_PUBLIC); $appointment->setUserId('testuser'); $this->mapper->insert($appointment); $appointments = $this->mapper->findAllForUser('testuser'); Loading @@ -118,6 +158,7 @@ class AppointmentMapperTest extends TestCase { public function testDeleteById():void { $appointment = new AppointmentConfig(); $appointment->setToken('frokns'); $appointment->setName('Test 2'); $appointment->setDescription('Test Description'); $appointment->setIncrement(15); Loading
tests/php/integration/Db/BookingMapperTest.php 0 → 100644 +129 −0 Original line number Diff line number Diff line <?php declare(strict_types=1); /** * @copyright 2019 Christoph Wurst <christoph@winzerhof-wurst.at> * * @author 2019 Christoph Wurst <christoph@winzerhof-wurst.at> * * @license GNU AGPL version 3 or any later version * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as * published by the Free Software Foundation, either version 3 of the * License, or (at your option) any later version. * * 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 * along with this program. If not, see <http://www.gnu.org/licenses/>. */ namespace OCA\Calendar\Tests\Integration\Db; use BadFunctionCallException; use ChristophWurst\Nextcloud\Testing\DatabaseTransaction; use ChristophWurst\Nextcloud\Testing\TestCase; use InvalidArgumentException; use OCA\Calendar\Db\AppointmentConfig; use OCA\Calendar\Db\AppointmentConfigMapper; use OCA\Calendar\Db\Booking; use OCA\Calendar\Db\BookingMapper; use OCP\AppFramework\Db\DoesNotExistException; use OCP\AppFramework\Utility\ITimeFactory; use OCP\IDBConnection; class BookingMapperTest extends TestCase { use DatabaseTransaction; /** @var IDBConnection */ private $db; /** @var BookingMapper */ private $mapper; protected function setUp(): void { parent::setUp(); $this->db = \OC::$server->getDatabaseConnection(); $this->time = $this->createConfiguredMock(ITimeFactory::class, [ 'getTime' => 1635721200 ]); $this->mapper = new BookingMapper( $this->db, $this->time ); $qb = $this->db->getQueryBuilder(); $delete = $qb->delete($this->mapper->getTableName()); $delete->execute(); } public function testFindByIdNoData() { $this->expectException(DoesNotExistException::class); $this->mapper->findByToken('token'); } /** * @depends testFindByIdNoData */ public function testFindByToken() { $booking = new Booking(); $booking->setApptConfigId(1); $booking->setCreatedAt($this->time->getTime()); $booking->setToken('oken'); $booking->setDisplayName('Test'); $booking->setStart(123); $booking->setEnd(123); $booking->setEmail('test@test.com'); $booking->setTimezone('Europe/Berlin'); $booking = $this->mapper->insert($booking); $token = $booking->getToken(); $booking = $this->mapper->findByToken($token); $this->assertObjectHasAttribute('apptConfigId', $booking); $this->assertEquals('1', $booking->getApptConfigId()); $this->assertObjectHasAttribute('createdAt', $booking); $this->assertEquals($this->time->getTime(), $booking->getCreatedAt()); $this->assertObjectHasAttribute('token', $booking); $this->assertEquals('oken', $booking->getToken()); $this->assertObjectHasAttribute('displayName', $booking); $this->assertEquals('Test', $booking->getDisplayName()); $this->assertObjectHasAttribute('start', $booking); $this->assertEquals(123, $booking->getStart()); $this->assertObjectHasAttribute('end', $booking); $this->assertEquals(123, $booking->getEnd()); $this->assertObjectHasAttribute('email', $booking); $this->assertEquals('test@test.com', $booking->getEmail()); $this->assertObjectHasAttribute('timezone', $booking); $this->assertEquals('Europe/Berlin', $booking->getTimezone()); } public function testDeleteOutdated():void { $booking = new Booking(); $booking->setApptConfigId(1); $booking->setCreatedAt(891485); $booking->setToken('okfdfssdsdfen'); $booking->setDisplayName('Test'); $booking->setStart(123); $booking->setEnd(123); $booking->setEmail('test@test.com'); $booking->setTimezone('Europe/Berlin'); $booking = $this->mapper->insert($booking); $token = $booking->getToken(); $booking = $this->mapper->findByToken($token); $row = $this->mapper->deleteOutdated(86400); $this->assertEquals(1, $row); $this->expectException(DoesNotExistException::class); $this->mapper->findByToken($token); } }