diff options
author | Anna Larch <anna@nextcloud.com> | 2021-12-13 14:49:07 +0300 |
---|---|---|
committer | Anna Larch <anna@nextcloud.com> | 2021-12-13 16:25:27 +0300 |
commit | 25f5cbc5fe8801b44c9a5b11e918ea4decceb7fc (patch) | |
tree | 5254337454abfb8cebd32f6d47df7c52853b90b1 /tests | |
parent | 6cc996b1b8244dd21f324f166c9b6a07dfcfc6b1 (diff) |
Add repair step to fix reply tos that have <> as their content
Signed-off-by: Anna Larch <anna@nextcloud.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/Integration/Db/MessageMapperTest.php | 114 | ||||
-rw-r--r-- | tests/psalm-baseline.xml | 11 |
2 files changed, 125 insertions, 0 deletions
diff --git a/tests/Integration/Db/MessageMapperTest.php b/tests/Integration/Db/MessageMapperTest.php new file mode 100644 index 000000000..88be939de --- /dev/null +++ b/tests/Integration/Db/MessageMapperTest.php @@ -0,0 +1,114 @@ +<?php + +declare(strict_types=1); + +/** + * @copyright 2021 Anna Larch <anna.larch@nextcloud.com> + * + * @author 2021 Anna Larch <anna.larch@nextcloud.com> + * + * @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\Mail\Tests\Integration\Db; + +use ChristophWurst\Nextcloud\Testing\DatabaseTransaction; +use ChristophWurst\Nextcloud\Testing\TestCase; +use OCA\Mail\Account; +use OCA\Mail\Db\MessageMapper; +use OCA\Mail\Db\TagMapper; +use OCA\Mail\Support\PerformanceLogger; +use OCP\AppFramework\Utility\ITimeFactory; +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IDBConnection; + +class MessageMapperTest extends TestCase { + use DatabaseTransaction; + + /** @var IDBConnection */ + private $db; + + /** @var MessageMapper */ + private $mapper; + + protected function setUp(): void { + parent::setUp(); + + $this->db = \OC::$server->getDatabaseConnection(); + $timeFactory = $this->createMock(ITimeFactory::class); + $tagMapper = $this->createMock(TagMapper::class); + $performanceLogger = $this->createMock(PerformanceLogger::class); + $this->mapper = new MessageMapper( + $this->db, + $timeFactory, + $tagMapper, + $performanceLogger + ); + + $qb = $this->db->getQueryBuilder(); + + $delete = $qb->delete($this->mapper->getTableName()); + $delete->execute(); + } + + public function testResetInReplyTo() : void { + $account = $this->createMock(Account::class); + $account->method('getId')->willReturn(13); + array_map(function ($i) { + $qb = $this->db->getQueryBuilder(); + $insert = $qb->insert($this->mapper->getTableName()) + ->values([ + 'uid' => $qb->createNamedParameter($i, IQueryBuilder::PARAM_INT), + 'message_id' => $qb->createNamedParameter('<abc' . $i . '@123.com>'), + 'mailbox_id' => $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT), + 'subject' => $qb->createNamedParameter('TEST'), + 'sent_at' => $qb->createNamedParameter(time(), IQueryBuilder::PARAM_INT), + 'in_reply_to' => $qb->createNamedParameter('<>') + ]); + $insert->execute(); + }, range(1, 10)); + + array_map(function ($i) { + $qb = $this->db->getQueryBuilder(); + $insert = $qb->insert($this->mapper->getTableName()) + ->values([ + 'uid' => $qb->createNamedParameter($i, IQueryBuilder::PARAM_INT), + 'message_id' => $qb->createNamedParameter('<abc' . $i . '@123.com>'), + 'mailbox_id' => $qb->createNamedParameter(1, IQueryBuilder::PARAM_INT), + 'subject' => $qb->createNamedParameter('TEST'), + 'sent_at' => $qb->createNamedParameter(time(), IQueryBuilder::PARAM_INT), + 'in_reply_to' => $qb->createNamedParameter('<abc@dgf.com>') + ]); + $insert->execute(); + }, range(11, 20)); + + $result = $this->mapper->resetInReplyTo(); + + $this->assertEquals(10, $result); + + $qb2 = $this->db->getQueryBuilder(); + $select = $qb2->select('*') + ->from($this->mapper->getTableName()) + ->where( + $qb2->expr()->like('in_reply_to', $qb2->createNamedParameter("<>", IQueryBuilder::PARAM_STR), IQueryBuilder::PARAM_STR) + ); + + $result = $select->execute(); + $rows = $result->fetchAll(); + + $this->assertEmpty($rows); + } +} diff --git a/tests/psalm-baseline.xml b/tests/psalm-baseline.xml index 66cc2bf0e..16f0951d4 100644 --- a/tests/psalm-baseline.xml +++ b/tests/psalm-baseline.xml @@ -66,6 +66,11 @@ <code>Command</code> </UndefinedClass> </file> + <file src="lib/Command/RepairMailTheads.php"> + <UndefinedClass occurrences="1"> + <code>Command</code> + </UndefinedClass> + </file> <file src="lib/Command/SyncAccount.php"> <UndefinedClass occurrences="1"> <code>Command</code> @@ -124,6 +129,12 @@ <code>$select->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)</code> <code>$select->createNamedParameter($chunk, IQueryBuilder::PARAM_INT_ARRAY)</code> </ImplicitToStringCast> + <InvalidReturnStatement occurrences="1"> + <code>$update->execute()</code> + </InvalidReturnStatement> + <InvalidReturnType occurrences="1"> + <code>int</code> + </InvalidReturnType> </file> <file src="lib/Db/StatisticsDao.php"> <ImplicitToStringCast occurrences="7"> |