diff --git a/src/app/Domain.php b/src/app/Domain.php index 0217f1b7..84fac81c 100644 --- a/src/app/Domain.php +++ b/src/app/Domain.php @@ -1,147 +1,157 @@ morphOne('App\Entitlement', 'entitleable'); } /** * Returns whether this domain is active. * - * @return boolean + * @return bool */ - public function isActive() + public function isActive(): bool { return $this->status & self::STATUS_ACTIVE; } /** * Returns whether this domain is confirmed the ownership of. * - * @return boolean + * @return bool */ - public function isConfirmed() + public function isConfirmed(): bool { return $this->status & self::STATUS_CONFIRMED; } /** * Returns whether this domain is deleted. * - * @return boolean + * @return bool */ - public function isDeleted() + public function isDeleted(): bool { return $this->status & self::STATUS_DELETED; } /** * Returns whether this domain is registered with us. * - * @return boolean + * @return bool */ - public function isExternal() + public function isExternal(): bool { return $this->type & self::TYPE_EXTERNAL; } /** * Returns whether this domain is hosted with us. * - * @return boolean + * @return bool */ - public function isHosted() + public function isHosted(): bool { return $this->type & self::TYPE_HOSTED; } /** * Returns whether this domain is new. * - * @return boolean + * @return bool */ - public function isNew() + public function isNew(): bool { return $this->status & self::STATUS_NEW; } + /** + * Returns whether this domain is public. + * + * @return bool + */ + public function isPublic(): bool + { + return $this->type & self::TYPE_PUBLIC; + } + /** * Returns whether this domain is suspended. * - * @return boolean + * @return bool */ - public function isSuspended() + public function isSuspended(): bool { return $this->status & self::STATUS_SUSPENDED; } /* public function setStatusAttribute($status) { $_status = $this->status; switch ($status) { case "new": $_status += self::STATUS_NEW; break; case "active": $_status += self::STATUS_ACTIVE; $_status -= self::STATUS_NEW; break; case "confirmed": $_status += self::STATUS_CONFIRMED; $_status -= self::STATUS_NEW; break; case "suspended": $_status += self::STATUS_SUSPENDED; break; case "deleted": $_status += self::STATUS_DELETED; break; default: $_status = $status; //throw new \Exception("Invalid domain status: {$status}"); break; } $this->status = $_status; } */ } diff --git a/src/tests/Unit/DomainTest.php b/src/tests/Unit/DomainTest.php new file mode 100644 index 00000000..5e8833f1 --- /dev/null +++ b/src/tests/Unit/DomainTest.php @@ -0,0 +1,70 @@ + 'test.com', + 'status' => \array_sum($domain_statuses), + 'type' => Domain::TYPE_EXTERNAL + ] + ); + + $this->assertTrue($domain->isNew() === in_array(Domain::STATUS_NEW, $domain_statuses)); + $this->assertTrue($domain->isActive() === in_array(Domain::STATUS_ACTIVE, $domain_statuses)); + $this->assertTrue($domain->isConfirmed() === in_array(Domain::STATUS_CONFIRMED, $domain_statuses)); + $this->assertTrue($domain->isSuspended() === in_array(Domain::STATUS_SUSPENDED, $domain_statuses)); + $this->assertTrue($domain->isDeleted() === in_array(Domain::STATUS_DELETED, $domain_statuses)); + } + } + + /** + * Test basic Domain funtionality + */ + public function testDomainType() + { + $types = [ + Domain::TYPE_PUBLIC, + Domain::TYPE_HOSTED, + Domain::TYPE_EXTERNAL, + ]; + + $domains = \App\Utils::powerSet($types); + + foreach ($domains as $domain_types) { + $domain = new Domain( + [ + 'namespace' => 'test.com', + 'status' => Domain::STATUS_NEW, + 'type' => \array_sum($domain_types), + ] + ); + + $this->assertTrue($domain->isPublic() === in_array(Domain::TYPE_PUBLIC, $domain_types)); + $this->assertTrue($domain->isHosted() === in_array(Domain::TYPE_HOSTED, $domain_types)); + $this->assertTrue($domain->isExternal() === in_array(Domain::TYPE_EXTERNAL, $domain_types)); + } + } +} diff --git a/src/tests/Unit/Mail/SignupVerificationTest.php b/src/tests/Unit/Mail/SignupVerificationTest.php index 8c0e054e..603d1265 100644 --- a/src/tests/Unit/Mail/SignupVerificationTest.php +++ b/src/tests/Unit/Mail/SignupVerificationTest.php @@ -1,39 +1,39 @@ 'code', 'short_code' => 'short-code', 'data' => [ 'email' => 'test@email', 'name' => 'Test Name', ], ]); $mail = new SignupVerification($code); $html = $mail->build()->render(); $url = \config('app.url') . '/signup/' . $code->short_code . '-' . $code->code; $link = "$url"; $this->assertSame(\config('app.name') . ' Registration', $mail->subject); $this->assertStringStartsWith('', $html); $this->assertTrue(strpos($html, $link) > 0); $this->assertTrue(strpos($html, $code->data['name']) > 0); } }