first
This commit is contained in:
182
tests/Feature/RateMasWorkflowTest.php
Normal file
182
tests/Feature/RateMasWorkflowTest.php
Normal file
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\UploadedFile;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Tests\TestCase;
|
||||
|
||||
class RateMasWorkflowTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_user_can_login_and_open_account_search(): void
|
||||
{
|
||||
User::create([
|
||||
'name' => 'User Cukai',
|
||||
'username' => 'cukai',
|
||||
'email' => 'cukai@example.local',
|
||||
'password' => '123',
|
||||
]);
|
||||
|
||||
$this->post('/login', [
|
||||
'username' => 'cukai',
|
||||
'password' => '123',
|
||||
])->assertRedirect('/tables');
|
||||
|
||||
$this->get('/tables')
|
||||
->assertOk()
|
||||
->assertSee('Carian Akaun')
|
||||
->assertSee('A010100001');
|
||||
}
|
||||
|
||||
public function test_authenticated_user_can_submit_account_and_year_to_print_record(): void
|
||||
{
|
||||
$this->actingAs(User::create([
|
||||
'name' => 'User Cukai',
|
||||
'username' => 'cukai',
|
||||
'email' => 'cukai@example.local',
|
||||
'password' => '123',
|
||||
]));
|
||||
|
||||
$this->createRateMasTable('2013_ratemas');
|
||||
|
||||
$this->get('/records/search?noakaun=A001&year=2013')
|
||||
->assertRedirect('/tables/2013_ratemas/records?noakaun=A001');
|
||||
|
||||
$this->get('/tables/2013_ratemas/records?noakaun=A001')
|
||||
->assertOk()
|
||||
->assertSee('RateMas 2013')
|
||||
->assertSee('A001')
|
||||
->assertSee('Ali Ahmad')
|
||||
->assertSee('Next 2014')
|
||||
->assertSee('/records/search', false)
|
||||
->assertSee('Cetak');
|
||||
}
|
||||
|
||||
public function test_print_record_has_previous_and_next_year_navigation(): void
|
||||
{
|
||||
$this->actingAs(User::create([
|
||||
'name' => 'User Cukai',
|
||||
'username' => 'cukai',
|
||||
'email' => 'cukai@example.local',
|
||||
'password' => '123',
|
||||
]));
|
||||
|
||||
$this->createRateMasTable('2014_ratemas');
|
||||
|
||||
$this->get('/tables/2014_ratemas/records?noakaun=A001')
|
||||
->assertOk()
|
||||
->assertSee('Prev 2013')
|
||||
->assertSee('Next 2015')
|
||||
->assertSee('value="2014"', false);
|
||||
}
|
||||
|
||||
public function test_regular_user_cannot_open_admin_upload_page(): void
|
||||
{
|
||||
$this->actingAs(User::create([
|
||||
'name' => 'User Cukai',
|
||||
'username' => 'cukai',
|
||||
'email' => 'cukai@example.local',
|
||||
'password' => '123',
|
||||
]));
|
||||
|
||||
$this->get('/admin/ratemas/upload')->assertForbidden();
|
||||
}
|
||||
|
||||
public function test_admin_can_upload_csv_and_create_year_table(): void
|
||||
{
|
||||
$this->actingAs(User::create([
|
||||
'name' => 'Admin',
|
||||
'username' => 'admin',
|
||||
'role' => 'admin',
|
||||
'email' => 'admin@example.local',
|
||||
'password' => 'admin123',
|
||||
]));
|
||||
|
||||
$csv = implode("\n", [
|
||||
'no_akaun,nama_pemilik,jumlah_baki',
|
||||
'A009,Siti Aminah,123.45',
|
||||
]);
|
||||
|
||||
$this->post('/admin/ratemas/upload', [
|
||||
'year' => 2020,
|
||||
'file' => UploadedFile::fake()->createWithContent('ratemas-2020.csv', $csv),
|
||||
])->assertRedirect('/admin/ratemas/upload');
|
||||
|
||||
$this->assertTrue(Schema::hasTable('2020_ratemas'));
|
||||
$this->assertSame('Siti Aminah', DB::table('2020_ratemas')->where('no_akaun', 'A009')->value('nama_pemilik'));
|
||||
|
||||
$this->get('/tables/2020_ratemas/records?noakaun=A009')
|
||||
->assertOk()
|
||||
->assertSee('RateMas 2020')
|
||||
->assertSee('Siti Aminah');
|
||||
}
|
||||
|
||||
private function createRateMasTable(string $table): void
|
||||
{
|
||||
Schema::create($table, function ($table) {
|
||||
$table->string('no_akaun')->primary();
|
||||
$table->string('no_akaun_lama')->nullable();
|
||||
$table->string('nama_pemilik')->nullable();
|
||||
$table->string('alamatpos_1')->nullable();
|
||||
$table->string('alamatpos_2')->nullable();
|
||||
$table->string('alamatpos_3')->nullable();
|
||||
$table->string('ic_no')->nullable();
|
||||
$table->string('old_ic_no')->nullable();
|
||||
$table->string('bangsa')->nullable();
|
||||
$table->string('warganegara')->nullable();
|
||||
$table->string('nolot')->nullable();
|
||||
$table->string('nogeran')->nullable();
|
||||
$table->string('kegunaan')->nullable();
|
||||
$table->string('mukim')->nullable();
|
||||
$table->string('no_bangunan')->nullable();
|
||||
$table->string('lokasiharta_1')->nullable();
|
||||
$table->string('lokasiharta_2')->nullable();
|
||||
$table->string('kawasan')->nullable();
|
||||
$table->string('jenisbangunan')->nullable();
|
||||
$table->decimal('new_taksiran', 12, 2)->default(0);
|
||||
$table->decimal('kadar', 6, 2)->default(0);
|
||||
$table->decimal('cukai_setengahtahun', 12, 2)->default(0);
|
||||
$table->string('tarikh_kuatkuasa')->nullable();
|
||||
$table->decimal('old_taksiran', 12, 2)->default(0);
|
||||
$table->decimal('old_kadar', 6, 2)->default(0);
|
||||
$table->decimal('tunggakan_cukai', 12, 2)->default(0);
|
||||
$table->decimal('cukai_semasa_1', 12, 2)->default(0);
|
||||
$table->decimal('cukai_semasa_2', 12, 2)->default(0);
|
||||
$table->decimal('pelarasan_cukai', 12, 2)->default(0);
|
||||
$table->decimal('bayaran_cukai_diterima', 12, 2)->default(0);
|
||||
$table->decimal('baki_cukai', 12, 2)->default(0);
|
||||
$table->decimal('baki_najis', 12, 2)->default(0);
|
||||
$table->decimal('baki_notis', 12, 2)->default(0);
|
||||
$table->decimal('baki_waran', 12, 2)->default(0);
|
||||
$table->decimal('jumlah_baki', 12, 2)->default(0);
|
||||
});
|
||||
|
||||
\DB::table($table)->insert([
|
||||
'no_akaun' => 'A001',
|
||||
'no_akaun_lama' => 'OLD001',
|
||||
'nama_pemilik' => 'Ali Ahmad',
|
||||
'alamatpos_1' => 'Alamat 1',
|
||||
'alamatpos_2' => 'Alamat 2',
|
||||
'alamatpos_3' => 'Alamat 3',
|
||||
'ic_no' => '900101010101',
|
||||
'old_ic_no' => 'A1234567',
|
||||
'bangsa' => 'Melayu',
|
||||
'warganegara' => 'Malaysia',
|
||||
'nolot' => 'Lot 1',
|
||||
'nogeran' => 'DHM 1',
|
||||
'kegunaan' => 'Kediaman',
|
||||
'mukim' => 'Mukim A',
|
||||
'no_bangunan' => 'B1',
|
||||
'lokasiharta_1' => 'Lokasi 1',
|
||||
'lokasiharta_2' => 'Lokasi 2',
|
||||
'kawasan' => 'Kawasan A',
|
||||
'jenisbangunan' => 'Rumah',
|
||||
'tarikh_kuatkuasa' => '01/01/2013',
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user