Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Controller/UsersTest.php
Show All 26 Lines | public function setUp(): void | ||||
$this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$this->deleteTestUser('UsersControllerTest2@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest2@userscontroller.com'); | ||||
$this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | ||||
$this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | $this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | ||||
$this->deleteTestUser('john2.doe2@kolab.org'); | $this->deleteTestUser('john2.doe2@kolab.org'); | ||||
$this->deleteTestUser('deleted@kolab.org'); | $this->deleteTestUser('deleted@kolab.org'); | ||||
$this->deleteTestUser('deleted@kolabnow.com'); | $this->deleteTestUser('deleted@kolabnow.com'); | ||||
$this->deleteTestDomain('userscontroller.com'); | $this->deleteTestDomain('userscontroller.com'); | ||||
$this->deleteTestGroup('group-test@kolabnow.com'); | |||||
$this->deleteTestGroup('group-test@kolab.org'); | |||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | $wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | ||||
$wallet->save(); | $wallet->save(); | ||||
$user->status |= User::STATUS_IMAP_READY; | $user->status |= User::STATUS_IMAP_READY; | ||||
$user->save(); | $user->save(); | ||||
} | } | ||||
/** | /** | ||||
* {@inheritDoc} | * {@inheritDoc} | ||||
*/ | */ | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('jane@kolabnow.com'); | $this->deleteTestUser('jane@kolabnow.com'); | ||||
$this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$this->deleteTestUser('UsersControllerTest2@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest2@userscontroller.com'); | ||||
$this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | $this->deleteTestUser('UsersControllerTest3@userscontroller.com'); | ||||
$this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | $this->deleteTestUser('UserEntitlement2A@UserEntitlement.com'); | ||||
$this->deleteTestUser('john2.doe2@kolab.org'); | $this->deleteTestUser('john2.doe2@kolab.org'); | ||||
$this->deleteTestUser('deleted@kolab.org'); | $this->deleteTestUser('deleted@kolab.org'); | ||||
$this->deleteTestUser('deleted@kolabnow.com'); | $this->deleteTestUser('deleted@kolabnow.com'); | ||||
$this->deleteTestDomain('userscontroller.com'); | $this->deleteTestDomain('userscontroller.com'); | ||||
$this->deleteTestGroup('group-test@kolabnow.com'); | |||||
$this->deleteTestGroup('group-test@kolab.org'); | |||||
$user = $this->getTestUser('john@kolab.org'); | $user = $this->getTestUser('john@kolab.org'); | ||||
$wallet = $user->wallets()->first(); | $wallet = $user->wallets()->first(); | ||||
$wallet->discount()->dissociate(); | $wallet->discount()->dissociate(); | ||||
$wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | $wallet->settings()->whereIn('key', ['mollie_id', 'stripe_id'])->delete(); | ||||
$wallet->save(); | $wallet->save(); | ||||
$user->status |= User::STATUS_IMAP_READY; | $user->status |= User::STATUS_IMAP_READY; | ||||
$user->save(); | $user->save(); | ||||
▲ Show 20 Lines • Show All 1,054 Lines • ▼ Show 20 Lines | public function testValidateEmailDeleted(): void | ||||
$this->assertSame(null, $deleted); | $this->assertSame(null, $deleted); | ||||
$result = UsersController::validateEmail('jack@kolab.org', $john, $deleted); | $result = UsersController::validateEmail('jack@kolab.org', $john, $deleted); | ||||
$this->assertSame('The specified email is not available.', $result); | $this->assertSame('The specified email is not available.', $result); | ||||
$this->assertSame(null, $deleted); | $this->assertSame(null, $deleted); | ||||
} | } | ||||
/** | /** | ||||
* User email validation - tests for an address being a group email address | |||||
* | |||||
* Note: Technically these include unit tests, but let's keep it here for now. | |||||
* FIXME: Shall we do a http request for each case? | |||||
*/ | |||||
public function testValidateEmailGroup(): void | |||||
{ | |||||
Queue::fake(); | |||||
$john = $this->getTestUser('john@kolab.org'); | |||||
$pub_group = $this->getTestGroup('group-test@kolabnow.com'); | |||||
$priv_group = $this->getTestGroup('group-test@kolab.org'); | |||||
// A group in a public domain, existing | |||||
$result = UsersController::validateEmail($pub_group->email, $john, $deleted); | |||||
$this->assertSame('The specified email is not available.', $result); | |||||
$this->assertNull($deleted); | |||||
$pub_group->delete(); | |||||
// A group in a public domain, deleted | |||||
$result = UsersController::validateEmail($pub_group->email, $john, $deleted); | |||||
$this->assertSame('The specified email is not available.', $result); | |||||
$this->assertNull($deleted); | |||||
// A group in a private domain, existing | |||||
$result = UsersController::validateEmail($priv_group->email, $john, $deleted); | |||||
$this->assertSame('The specified email is not available.', $result); | |||||
$this->assertNull($deleted); | |||||
$priv_group->delete(); | |||||
// A group in a private domain, deleted | |||||
$result = UsersController::validateEmail($priv_group->email, $john, $deleted); | |||||
$this->assertSame(null, $result); | |||||
$this->assertSame($priv_group->id, $deleted->id); | |||||
} | |||||
/** | |||||
* List of alias validation cases for testValidateAlias() | * List of alias validation cases for testValidateAlias() | ||||
* | * | ||||
* @return array Arguments for testValidateAlias() | * @return array Arguments for testValidateAlias() | ||||
*/ | */ | ||||
public function dataValidateAlias(): array | public function dataValidateAlias(): array | ||||
{ | { | ||||
$this->refreshApplication(); | $this->refreshApplication(); | ||||
$public_domains = Domain::getPublicDomains(); | $public_domains = Domain::getPublicDomains(); | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | public function testValidateAlias2(): void | ||||
$jack = $this->getTestUser('jack@kolab.org'); | $jack = $this->getTestUser('jack@kolab.org'); | ||||
$user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | $user = $this->getTestUser('UsersControllerTest1@userscontroller.com'); | ||||
$deleted_priv = $this->getTestUser('deleted@kolab.org'); | $deleted_priv = $this->getTestUser('deleted@kolab.org'); | ||||
$deleted_priv->setAliases(['deleted-alias@kolab.org']); | $deleted_priv->setAliases(['deleted-alias@kolab.org']); | ||||
$deleted_priv->delete(); | $deleted_priv->delete(); | ||||
$deleted_pub = $this->getTestUser('deleted@kolabnow.com'); | $deleted_pub = $this->getTestUser('deleted@kolabnow.com'); | ||||
$deleted_pub->setAliases(['deleted-alias@kolabnow.com']); | $deleted_pub->setAliases(['deleted-alias@kolabnow.com']); | ||||
$deleted_pub->delete(); | $deleted_pub->delete(); | ||||
$group = $this->getTestGroup('group-test@kolabnow.com'); | |||||
// An alias that was a user email before is allowed, but only for custom domains | // An alias that was a user email before is allowed, but only for custom domains | ||||
$result = UsersController::validateAlias('deleted@kolab.org', $john); | $result = UsersController::validateAlias('deleted@kolab.org', $john); | ||||
$this->assertSame(null, $result); | $this->assertSame(null, $result); | ||||
$result = UsersController::validateAlias('deleted-alias@kolab.org', $john); | $result = UsersController::validateAlias('deleted-alias@kolab.org', $john); | ||||
$this->assertSame(null, $result); | $this->assertSame(null, $result); | ||||
$result = UsersController::validateAlias('deleted@kolabnow.com', $john); | $result = UsersController::validateAlias('deleted@kolabnow.com', $john); | ||||
$this->assertSame('The specified alias is not available.', $result); | $this->assertSame('The specified alias is not available.', $result); | ||||
$result = UsersController::validateAlias('deleted-alias@kolabnow.com', $john); | $result = UsersController::validateAlias('deleted-alias@kolabnow.com', $john); | ||||
$this->assertSame('The specified alias is not available.', $result); | $this->assertSame('The specified alias is not available.', $result); | ||||
// A grpoup with the same email address exists | |||||
$result = UsersController::validateAlias($group->email, $john); | |||||
$this->assertSame('The specified alias is not available.', $result); | |||||
} | } | ||||
} | } |