-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #36 from /issues/21
add EnumTests
- Loading branch information
Showing
3 changed files
with
108 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Core\Tests\Enums; | ||
|
||
use EscolaLms\Core\Enums\StatusEnum; | ||
use EscolaLms\Core\Enums\UserRole; | ||
use EscolaLms\Core\Tests\TestCase; | ||
|
||
class BasicEnumTest extends TestCase | ||
{ | ||
public function testStatusEnum() | ||
{ | ||
$this->assertEquals([0 => "INACTIVE",1 => "ACTIVE"], StatusEnum::getAssoc()); | ||
$this->assertEquals(2, StatusEnum::getDetails()->count()); | ||
$this->assertTrue(StatusEnum::isValidName("INACTIVE")); | ||
$this->assertFalse(StatusEnum::isValidName(0)); | ||
$this->assertTrue(StatusEnum::isValidValue(1)); | ||
$this->assertFalse(StatusEnum::isValidValue("ACTIVE")); | ||
$this->assertEquals("ACTIVE", StatusEnum::getName(1)); | ||
$this->assertEquals(0, StatusEnum::getValue("INACTIVE")); | ||
} | ||
|
||
public function testUserRole() | ||
{ | ||
$this->assertEquals(["student" => "STUDENT","tutor" => "TUTOR","admin" => "ADMIN"], UserRole::getAssoc()); | ||
$this->assertEquals(3, UserRole::getDetails()->count()); | ||
$this->assertTrue(UserRole::isValidName("STUDENT")); | ||
$this->assertFalse(UserRole::isValidName("abc")); | ||
$this->assertTrue(UserRole::isValidValue("tutor")); | ||
$this->assertFalse(UserRole::isValidValue("SuperAdmin")); | ||
$this->assertEquals("ADMIN", UserRole::getName("admin")); | ||
$this->assertEquals("student", UserRole::getValue("STUDENT")); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Core\Tests\Features; | ||
|
||
use EscolaLms\Core\Migrations\EscolaMigration; | ||
use EscolaLms\Core\Tests\TestCase; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\DB; | ||
use Illuminate\Support\Facades\Schema; | ||
use RuntimeException; | ||
|
||
class EscolaMigrationTest extends TestCase | ||
{ | ||
public function testCreate() | ||
{ | ||
$migrate = new EscolaMigration(); | ||
Schema::dropIfExists('abc_test'); | ||
|
||
$response = $migrate->create('abc_test', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('title'); | ||
$table->timestamps(); | ||
}); | ||
|
||
$this->assertNull($response); | ||
|
||
Schema::dropIfExists('abc_test'); | ||
} | ||
|
||
public function testDuplicateTable() | ||
{ | ||
$migrate = new EscolaMigration(); | ||
Schema::dropIfExists('abc_test'); | ||
|
||
$response = $migrate->create('abc_test', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('title'); | ||
$table->timestamps(); | ||
}); | ||
DB::insert('insert into abc_test (id, title) values (?, ?)', [1, 'test']); | ||
|
||
$this->assertNull($response); | ||
$this->expectException(RuntimeException::class); | ||
|
||
$migrate->create('abc_test', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('title'); | ||
$table->timestamps(); | ||
}); | ||
|
||
Schema::dropIfExists('abc_test'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace EscolaLms\Core\Tests\Features; | ||
|
||
use EscolaLms\Core\Seeders\RoleTableSeeder; | ||
use EscolaLms\Core\Tests\TestCase; | ||
use Spatie\Permission\Models\Permission; | ||
|
||
class RoleTableSeederTest extends TestCase | ||
{ | ||
public function testCreatePermissionWithName() | ||
{ | ||
$seeder = new RoleTableSeeder(); | ||
$response = $seeder->createPermissionWithName('testPermissionForTest'); | ||
|
||
$permissionFromDb = Permission::query()->find($response->getKey()); | ||
|
||
$this->assertEquals('testPermissionForTest', $response->name); | ||
$this->assertEquals($permissionFromDb->getKey(), $response->getKey()); | ||
} | ||
} |