Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Feature/Jobs/UserVerifyTest.php
<?php | <?php | ||||
namespace Tests\Feature\Jobs; | namespace Tests\Feature\Jobs; | ||||
use App\Jobs\UserCreate; | use App\Jobs\UserCreate; | ||||
use App\Jobs\UserVerify; | use App\Jobs\UserVerify; | ||||
use App\User; | use App\User; | ||||
use Illuminate\Support\Facades\Queue; | use Illuminate\Support\Facades\Queue; | ||||
use Tests\TestCase; | use Tests\TestCase; | ||||
class UserVerifyTest extends TestCase | class UserVerifyTest extends TestCase | ||||
{ | { | ||||
public function setUp(): void | public function setUp(): void | ||||
{ | { | ||||
parent::setUp(); | parent::setUp(); | ||||
$this->deleteTestUser('jane@kolabnow.com'); | $ned = $this->getTestUser('ned@kolab.org'); | ||||
$ned->status |= User::STATUS_IMAP_READY; | |||||
$ned->save(); | |||||
} | } | ||||
public function tearDown(): void | public function tearDown(): void | ||||
{ | { | ||||
$this->deleteTestUser('jane@kolabnow.com'); | $ned = $this->getTestUser('ned@kolab.org'); | ||||
$ned->status |= User::STATUS_IMAP_READY; | |||||
$ned->save(); | |||||
parent::tearDown(); | parent::tearDown(); | ||||
} | } | ||||
/** | /** | ||||
* Test job handle | * Test job handle | ||||
* | * | ||||
* @group imap | * @group imap | ||||
*/ | */ | ||||
public function testHandle(): void | public function testHandle(): void | ||||
{ | { | ||||
Queue::fake(); | Queue::fake(); | ||||
$user = $this->getTestUser('jane@kolabnow.com'); | $user = $this->getTestUser('ned@kolab.org'); | ||||
$user->status ^= User::STATUS_IMAP_READY; | |||||
$user->save(); | |||||
// This is a valid assertion in a feature, not functional test environment. | |||||
$this->assertFalse($user->isImapReady()); | $this->assertFalse($user->isImapReady()); | ||||
$this->assertFalse($user->isLdapReady()); | |||||
$job = new UserCreate($user); | |||||
$job->handle(); | |||||
$this->assertFalse($user->isImapReady()); | |||||
$this->assertTrue($user->isLdapReady()); | |||||
for ($i = 0; $i < 10; $i++) { | for ($i = 0; $i < 10; $i++) { | ||||
$job = new UserVerify($user); | $job = new UserVerify($user); | ||||
$job->handle(); | $job->handle(); | ||||
if ($user->fresh()->isImapReady()) { | if ($user->fresh()->isImapReady()) { | ||||
$this->assertTrue(true); | $this->assertTrue(true); | ||||
return; | return; | ||||
} | } | ||||
sleep(1); | sleep(1); | ||||
} | } | ||||
$this->assertTrue(false, "Unable to verify the IMAP account is set up in time"); | $this->assertTrue(false, "Unable to verify the IMAP account is set up in time"); | ||||
} | } | ||||
} | } |