Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Backends/RoundcubeTest.php
Show All 26 Lines | public function tearDown(): void | ||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test creating a Roundcube user record (and related data) | * Test creating a Roundcube user record (and related data) | ||||
* | * | ||||
* @group roundcube | * @group roundcube | ||||
*/ | */ | ||||
public function testUserCreation(): void | public function testUserCreationAndDeletion(): void | ||||
{ | { | ||||
$user = $this->getTestUser('roundcube@' . \config('app.domain')); | $user = $this->getTestUser('roundcube@' . \config('app.domain')); | ||||
$user->setSetting('first_name', 'First'); | $user->setSetting('first_name', 'First'); | ||||
$user->setSetting('last_name', 'Last'); | $user->setSetting('last_name', 'Last'); | ||||
$db = Roundcube::dbh(); | $db = Roundcube::dbh(); | ||||
// delete the user record if exists | // delete the user record if exists | ||||
if ($userid = Roundcube::userId($user->email, false)) { | if ($userid = Roundcube::userId($user->email, false)) { | ||||
$db->table('users')->delete(); | $db->table('users')->delete(); | ||||
} | } | ||||
// Create the user | // Create the user | ||||
$userid = Roundcube::userId($user->email); | $userid = Roundcube::userId($user->email); | ||||
$rcuser = $db->table('users')->where('username', $user->email)->first(); | $rcuser = $db->table('users')->where('username', $user->email)->first(); | ||||
$this->assertTrue(!empty($rcuser)); | $this->assertTrue(!empty($rcuser)); | ||||
$rcidentity = $db->table('identities')->where('user_id', $rcuser->user_id)->first(); | $rcidentity = $db->table('identities')->where('user_id', $rcuser->user_id)->first(); | ||||
$this->assertSame($user->email, $rcidentity->email); | $this->assertSame($user->email, $rcidentity->email); | ||||
$this->assertSame('First Last', $rcidentity->name); | $this->assertSame('First Last', $rcidentity->name); | ||||
$this->assertSame(1, $rcidentity->standard); | $this->assertSame(1, $rcidentity->standard); | ||||
// Delete the user | |||||
Roundcube::deleteUser($user->email); | |||||
$this->assertNull($db->table('users')->where('username', $user->email)->first()); | |||||
$this->assertNull($db->table('identities')->where('user_id', $rcuser->user_id)->first()); | |||||
} | } | ||||
} | } |