-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Hamza Mahjoubi <[email protected]>
- Loading branch information
Showing
6 changed files
with
253 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,229 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
|
||
namespace OCA\Mail\Tests\Integration\Db; | ||
|
||
use ChristophWurst\Nextcloud\Testing\DatabaseTransaction; | ||
use ChristophWurst\Nextcloud\Testing\TestCase; | ||
use ChristophWurst\Nextcloud\Testing\TestUser; | ||
use OCA\Mail\Db\InternalAddressMapper; | ||
use OCP\IDBConnection; | ||
use OCP\IUser; | ||
use OCP\Server; | ||
|
||
class InternalAddressMapperTest extends TestCase { | ||
use DatabaseTransaction, TestUser; | ||
|
||
/** @var IDBConnection */ | ||
private $db; | ||
|
||
/** @var IUser */ | ||
private $user; | ||
|
||
/** @var InternalAddressMapper */ | ||
private $mapper; | ||
|
||
protected function setUp(): void { | ||
parent::setUp(); | ||
|
||
/** @var IDBConnection $db */ | ||
$this->db = Server::get(IDBConnection::class); | ||
$this->user = $this->createTestUser(); | ||
|
||
$this->mapper = new InternalAddressMapper( | ||
$this->db | ||
); | ||
} | ||
|
||
public function testDoesntExist(): void { | ||
$exists = $this->mapper->exists($this->user->getUID(), "[email protected]"); | ||
|
||
$this->assertFalse($exists); | ||
} | ||
|
||
public function testIndividualExists(): void { | ||
$uid = $this->user->getUID(); | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->insert('mail_internal_address') | ||
->values([ | ||
'user_id' => $qb->createNamedParameter($uid), | ||
'address' => $qb->createNamedParameter('[email protected]'), | ||
'type' => $qb->createNamedParameter('individual') | ||
|
||
]) | ||
->executeStatement(); | ||
|
||
$exists = $this->mapper->exists($uid, "[email protected]"); | ||
|
||
$this->assertTrue($exists); | ||
} | ||
|
||
public function testDomainExists(): void { | ||
$uid = $this->user->getUID(); | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->insert('mail_internal_address') | ||
->values([ | ||
'user_id' => $qb->createNamedParameter($uid), | ||
'address' => $qb->createNamedParameter('next.cloud'), | ||
'type' => $qb->createNamedParameter('domain'), | ||
|
||
]) | ||
->executeStatement(); | ||
|
||
$exists = $this->mapper->exists($uid, "[email protected]"); | ||
|
||
$this->assertTrue($exists); | ||
} | ||
|
||
public function testCreateIndividual(): void { | ||
$uid = $this->user->getUID(); | ||
$this->mapper->create( | ||
$uid, | ||
"[email protected]", | ||
'individual' | ||
); | ||
|
||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('*') | ||
->from('mail_internal_address') | ||
->where( | ||
$qb->expr()->eq('user_id', $qb->createNamedParameter($uid)), | ||
$qb->expr()->eq('address', $qb->createNamedParameter("[email protected]")) | ||
); | ||
$result = $qb->executeQuery(); | ||
$rows = $result->fetchAll(); | ||
$result->closeCursor(); | ||
$this->assertCount(1, $rows); | ||
} | ||
|
||
public function testRemoveIndividual(): void { | ||
$uid = $this->user->getUID(); | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->insert('mail_internal_address') | ||
->values([ | ||
'user_id' => $qb->createNamedParameter($uid), | ||
'address' => $qb->createNamedParameter('[email protected]'), | ||
'type' => $qb->createNamedParameter('individual'), | ||
]) | ||
->executeStatement(); | ||
|
||
$this->mapper->remove( | ||
$uid, | ||
"[email protected]", | ||
'individual' | ||
); | ||
|
||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('*') | ||
->from('mail_internal_address') | ||
->where( | ||
$qb->expr()->eq('user_id', $qb->createNamedParameter($uid)), | ||
$qb->expr()->eq('address', $qb->createNamedParameter("[email protected]")) | ||
); | ||
$result = $qb->executeQuery(); | ||
$rows = $result->fetchAll(); | ||
$result->closeCursor(); | ||
$this->assertEmpty($rows); | ||
} | ||
|
||
public function testCreateDomain(): void { | ||
$uid = $this->user->getUID(); | ||
$this->mapper->create( | ||
$uid, | ||
"next.cloud", | ||
'domain' | ||
); | ||
|
||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('*') | ||
->from('mail_internal_address') | ||
->where( | ||
$qb->expr()->eq('user_id', $qb->createNamedParameter($uid)), | ||
$qb->expr()->eq('address', $qb->createNamedParameter("next.cloud")), | ||
$qb->expr()->eq('type', $qb->createNamedParameter('domain')) | ||
); | ||
$result = $qb->executeQuery(); | ||
$rows = $result->fetchAll(); | ||
$result->closeCursor(); | ||
$this->assertCount(1, $rows); | ||
} | ||
|
||
public function testRemoveDomain(): void { | ||
$uid = $this->user->getUID(); | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->insert('mail_internal_address') | ||
->values([ | ||
'user_id' => $qb->createNamedParameter($uid), | ||
'address' => $qb->createNamedParameter('next.cloud'), | ||
'type' => $qb->createNamedParameter('domain'), | ||
]) | ||
->executeStatement(); | ||
|
||
$this->mapper->remove( | ||
$uid, | ||
"next.cloud", | ||
'domain' | ||
); | ||
|
||
$qb = $this->db->getQueryBuilder(); | ||
$qb->select('*') | ||
->from('mail_internal_address') | ||
->where( | ||
$qb->expr()->eq('user_id', $qb->createNamedParameter($uid)), | ||
$qb->expr()->eq('address', $qb->createNamedParameter("next.cloud")), | ||
$qb->expr()->eq('type', $qb->createNamedParameter("domain")) | ||
); | ||
$result = $qb->executeQuery(); | ||
$rows = $result->fetchAll(); | ||
$result->closeCursor(); | ||
$this->assertEmpty($rows); | ||
} | ||
|
||
/* public function testFindAll(): void { | ||
$uid = $this->user->getUID(); | ||
$qb = $this->db->getQueryBuilder(); | ||
$qb->i('mail_internal_address') | ||
->values([ | ||
'user_id' => $qb->createNamedParameter($uid), | ||
'address' => $qb->createNamedParameter('[email protected]'), | ||
'type' => $qb->createNamedParameter('individual'), | ||
], | ||
)->insert('mail_internal_address') | ||
->values([ | ||
'user_id' => $qb->createNamedParameter($uid), | ||
'address' => $qb->createNamedParameter('[email protected]'), | ||
'type' => $qb->createNamedParameter('individual'), | ||
]) | ||
->executeStatement(); | ||
$result = $qb->executeQuery(); | ||
$result->closeCursor(); | ||
$rows = $this->mapper->findAll($uid); | ||
$this->assertCount(2, $rows); | ||
$resultArray = []; | ||
foreach ($rows as $row) { | ||
$resultArray[] = $row->jsonSerialize(); | ||
} | ||
$expected = [ | ||
[ | ||
'id' => 1, | ||
'user_id' => $uid, | ||
'address' => '[email protected]', | ||
'type' => 'individual', | ||
], | ||
[ | ||
'id' => 2, | ||
'user_id' => $uid, | ||
'address' => '[email protected]', | ||
'type' => 'individual', | ||
], | ||
]; | ||
$this->assertEquals($expected, $resultArray); | ||
}*/ | ||
} |