Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117755300
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
3 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/app/Jobs/Domain/DeleteJob.php b/src/app/Jobs/Domain/DeleteJob.php
index c856879d..381de849 100644
--- a/src/app/Jobs/Domain/DeleteJob.php
+++ b/src/app/Jobs/Domain/DeleteJob.php
@@ -1,42 +1,42 @@
<?php
namespace App\Jobs\Domain;
use App\Domain;
use App\Jobs\DomainJob;
use App\Support\Facades\LDAP;
class DeleteJob extends DomainJob
{
/**
* Execute the job.
*/
public function handle()
{
$domain = $this->getDomain();
if (!$domain) {
return;
}
// sanity checks
- if ($domain->trashed()) {
- $this->fail("Domain {$this->domainId} is not deleted.");
+ if (!$domain->trashed()) {
+ $this->fail("Domain {$domain->namespace} is not deleted.");
return;
}
if ($domain->isDeleted()) {
- $this->fail("Domain {$this->domainId} is already marked as deleted.");
+ $this->fail("Domain {$domain->namespace} is already marked as deleted.");
return;
}
if (\config('app.with_ldap') && $domain->isLdapReady()) {
LDAP::deleteDomain($domain);
$domain->status ^= Domain::STATUS_LDAP_READY;
}
$domain->status |= Domain::STATUS_DELETED;
$domain->save();
}
}
diff --git a/src/tests/Feature/Jobs/Domain/DeleteTest.php b/src/tests/Feature/Jobs/Domain/DeleteTest.php
index 345533ae..edc759ae 100644
--- a/src/tests/Feature/Jobs/Domain/DeleteTest.php
+++ b/src/tests/Feature/Jobs/Domain/DeleteTest.php
@@ -1,56 +1,68 @@
<?php
namespace Tests\Feature\Jobs\Domain;
use App\Domain;
use App\Jobs\Domain\DeleteJob;
use App\Support\Facades\LDAP;
use Tests\TestCase;
class DeleteTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
$this->deleteTestDomain('domain-create-test.com');
}
protected function tearDown(): void
{
$this->deleteTestDomain('domain-create-test.com');
parent::tearDown();
}
/**
* Test job handle
*/
public function testHandle(): void
{
$domain = $this->getTestDomain(
'domain-create-test.com',
[
'status' => Domain::STATUS_NEW | Domain::STATUS_LDAP_READY,
'type' => Domain::TYPE_EXTERNAL,
]
);
- \config(['app.with_ldap' => true]);
+ // Test job failure (domain not trashed)
+ $job = (new DeleteJob($domain->id))->withFakeQueueInteractions();
+ $job->handle();
+ $job->assertFailedWith("Domain {$domain->namespace} is not deleted.");
+
+ // Test job success
+ $domain->deleted_at = \now();
+ $domain->saveQuietly();
$this->assertTrue($domain->isLdapReady());
+ $this->assertTrue($domain->trashed());
$this->assertFalse($domain->isDeleted());
- LDAP::shouldReceive('deleteDomain')->once()->with($domain)->andReturn(true);
+ \config(['app.with_ldap' => true]);
+ LDAP::shouldReceive('deleteDomain')->once()->with($domain);
- $job = new DeleteJob($domain->id);
+ $job = (new DeleteJob($domain->id))->withFakeQueueInteractions();
$job->handle();
+ $job->assertNotFailed();
$domain->refresh();
$this->assertFalse($domain->isLdapReady());
$this->assertTrue($domain->isDeleted());
- // TODO: More cases
- $this->markTestIncomplete();
+ // Test job failure (domain marked as deleted)
+ $job = (new DeleteJob($domain->id))->withFakeQueueInteractions();
+ $job->handle();
+ $job->assertFailedWith("Domain {$domain->namespace} is already marked as deleted.");
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Apr 4, 7:56 AM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18823097
Default Alt Text
(3 KB)
Attached To
Mode
rK kolab
Attached
Detach File
Event Timeline