Skip to content

Commit

Permalink
Merge pull request #36 from /issues/21
Browse files Browse the repository at this point in the history
add EnumTests
  • Loading branch information
KrzysztofDziedziechEscolasoft authored Mar 23, 2022
2 parents e185c4d + 0e8ebc1 commit 9ab42b7
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/Enums/BasicEnumTest.php
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"));
}
}
53 changes: 53 additions & 0 deletions tests/Features/EscolaMigrationTest.php
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');
}
}
21 changes: 21 additions & 0 deletions tests/Features/RoleTableSeederTest.php
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());
}
}

0 comments on commit 9ab42b7

Please sign in to comment.