Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions tests/Activators/ModuleActivatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -630,4 +630,56 @@ public function it_creates_valid_json_structure()
$this->assertNotNull($decoded);
$this->assertIsArray($decoded);
}

/** @test */
public function it_deletes_statuses_file_on_reset()
{
$this->activator->enable('items');
$this->activator->enable('categories');

$this->assertTrue($this->files->exists($this->statusFile));

$this->activator->reset();

$this->assertFalse($this->files->exists($this->statusFile));
}

/** @test */
public function it_clears_route_statuses_on_reset()
{
$this->activator->enable('items');
$this->activator->disable('categories');

$this->assertCount(2, $this->activator->getRoutesStatuses());

$this->activator->reset();

$statuses = $this->activator->getRoutesStatuses();
$this->assertIsArray($statuses);
$this->assertEmpty($statuses);
}

/** @test */
public function it_treats_all_routes_as_inactive_after_reset()
{
$this->activator->enable('items');
$this->assertTrue($this->activator->hasStatus('items', true));

$this->activator->reset();

// Once reset, the previously enabled route should be treated as inactive
$this->assertFalse($this->activator->hasStatus('items', true));
$this->assertTrue($this->activator->hasStatus('items', false));
}

/** @test */
public function it_does_not_fail_when_resetting_without_existing_file()
{
$this->assertFalse($this->files->exists($this->statusFile));

$this->activator->reset();

$this->assertFalse($this->files->exists($this->statusFile));
$this->assertEmpty($this->activator->getRoutesStatuses());
}
}
75 changes: 75 additions & 0 deletions tests/Entities/Enums/AssignmentStatusTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?php

namespace Unusualify\Modularous\Tests\Entities\Enums;

use Unusualify\Modularous\Entities\Enums\AssignmentStatus;
use Unusualify\Modularous\Tests\TestCase;

class AssignmentStatusTest extends TestCase
{
public function test_cases_have_expected_values()
{
$this->assertEquals('completed', AssignmentStatus::COMPLETED->value);
$this->assertEquals('pending', AssignmentStatus::PENDING->value);
$this->assertEquals('rejected', AssignmentStatus::REJECTED->value);
$this->assertEquals('cancelled', AssignmentStatus::CANCELLED->value);
}

public function test_it_lists_all_cases()
{
$this->assertSame([
AssignmentStatus::COMPLETED,
AssignmentStatus::PENDING,
AssignmentStatus::REJECTED,
AssignmentStatus::CANCELLED,
], AssignmentStatus::cases());
}

public function test_label_returns_translated_label()
{
$this->assertEquals(__('Completed'), AssignmentStatus::COMPLETED->label());
$this->assertEquals(__('Pending'), AssignmentStatus::PENDING->label());
$this->assertEquals(__('Rejected'), AssignmentStatus::REJECTED->label());
$this->assertEquals(__('Cancelled'), AssignmentStatus::CANCELLED->label());
}

public function test_color_returns_expected_class()
{
$this->assertEquals('text-success', AssignmentStatus::COMPLETED->color());
$this->assertEquals('text-warning', AssignmentStatus::PENDING->color());
$this->assertEquals('text-error', AssignmentStatus::REJECTED->color());
$this->assertEquals('text-grey', AssignmentStatus::CANCELLED->color());
}

public function test_icon_color_returns_expected_value()
{
$this->assertEquals('success', AssignmentStatus::COMPLETED->iconColor());
$this->assertEquals('info', AssignmentStatus::PENDING->iconColor());
$this->assertEquals('error', AssignmentStatus::REJECTED->iconColor());
$this->assertEquals('grey', AssignmentStatus::CANCELLED->iconColor());
}

public function test_icon_returns_expected_value()
{
$this->assertEquals('mdi-check-circle-outline', AssignmentStatus::COMPLETED->icon());
$this->assertEquals('mdi-clock-outline', AssignmentStatus::PENDING->icon());
$this->assertEquals('mdi-close-circle-outline', AssignmentStatus::REJECTED->icon());
$this->assertEquals('mdi-close-circle-outline', AssignmentStatus::CANCELLED->icon());
}

public function test_time_interval_description_returns_translated_value()
{
$this->assertEquals(__('Until'), AssignmentStatus::PENDING->timeIntervalDescription());
$this->assertEquals(__('Rejected'), AssignmentStatus::REJECTED->timeIntervalDescription());
$this->assertEquals(__('Cancelled'), AssignmentStatus::CANCELLED->timeIntervalDescription());
$this->assertEquals(__('Completed'), AssignmentStatus::COMPLETED->timeIntervalDescription());
}

public function test_time_classes_returns_expected_value()
{
$this->assertEquals('font-weight-bold text-blue-darken-1', AssignmentStatus::PENDING->timeClasses());
$this->assertEquals('font-weight-bold text-error', AssignmentStatus::REJECTED->timeClasses());
$this->assertEquals('font-weight-bold text-warning', AssignmentStatus::CANCELLED->timeClasses());
$this->assertEquals('font-weight-bold text-success', AssignmentStatus::COMPLETED->timeClasses());
}
}
65 changes: 65 additions & 0 deletions tests/Entities/Enums/PaymentStatusTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

namespace Unusualify\Modularous\Tests\Entities\Enums;

use Unusualify\Modularous\Entities\Enums\PaymentStatus;
use Unusualify\Modularous\Tests\TestCase;

class PaymentStatusTest extends TestCase
{
public function test_cases_have_expected_values()
{
$this->assertEquals('PENDING', PaymentStatus::PENDING->value);
$this->assertEquals('FAILED', PaymentStatus::FAILED->value);
$this->assertEquals('CHECKOUT', PaymentStatus::CHECKOUT->value);
$this->assertEquals('PROVISION', PaymentStatus::PROVISION->value);
$this->assertEquals('COMPLETED', PaymentStatus::COMPLETED->value);
$this->assertEquals('CANCELLED', PaymentStatus::CANCELLED->value);
$this->assertEquals('REFUNDED', PaymentStatus::REFUNDED->value);
}

public function test_get_returns_value_for_known_case_name()
{
$this->assertEquals('PENDING', PaymentStatus::get('PENDING'));
$this->assertEquals('REFUNDED', PaymentStatus::get('REFUNDED'));
}

public function test_get_returns_null_for_unknown_case_name()
{
$this->assertNull(PaymentStatus::get('UNKNOWN'));
$this->assertNull(PaymentStatus::get('pending'));
}

public function test_label_returns_translated_label()
{
$this->assertEquals(__('Pending'), PaymentStatus::PENDING->label());
$this->assertEquals(__('Failed'), PaymentStatus::FAILED->label());
$this->assertEquals(__('Checkout'), PaymentStatus::CHECKOUT->label());
$this->assertEquals(__('Provision'), PaymentStatus::PROVISION->label());
$this->assertEquals(__('Completed'), PaymentStatus::COMPLETED->label());
$this->assertEquals(__('Cancelled'), PaymentStatus::CANCELLED->label());
$this->assertEquals(__('Refunded'), PaymentStatus::REFUNDED->label());
}

public function test_color_returns_expected_value()
{
$this->assertEquals('grey', PaymentStatus::PENDING->color());
$this->assertEquals('warning', PaymentStatus::FAILED->color());
$this->assertEquals('primary', PaymentStatus::CHECKOUT->color());
$this->assertEquals('info', PaymentStatus::PROVISION->color());
$this->assertEquals('success', PaymentStatus::COMPLETED->color());
$this->assertEquals('error', PaymentStatus::CANCELLED->color());
$this->assertEquals('grey', PaymentStatus::REFUNDED->color());
}

public function test_icon_returns_expected_value()
{
$this->assertEquals('mdi-clock-alert-outline', PaymentStatus::PENDING->icon());
$this->assertEquals('mdi-close-circle-outline', PaymentStatus::FAILED->icon());
$this->assertEquals('mdi-cart-outline', PaymentStatus::CHECKOUT->icon());
$this->assertEquals('mdi-progress-clock', PaymentStatus::PROVISION->icon());
$this->assertEquals('mdi-check-circle-outline', PaymentStatus::COMPLETED->icon());
$this->assertEquals('mdi-close-circle-outline', PaymentStatus::CANCELLED->icon());
$this->assertEquals('mdi-credit-card-refund-outline', PaymentStatus::REFUNDED->icon());
}
}
66 changes: 66 additions & 0 deletions tests/Entities/Enums/PermissionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace Unusualify\Modularous\Tests\Entities\Enums;

use Unusualify\Modularous\Entities\Enums\Permission;
use Unusualify\Modularous\Tests\TestCase;

class PermissionTest extends TestCase
{
public function test_cases_have_expected_values()
{
$this->assertEquals('create', Permission::CREATE->value);
$this->assertEquals('view', Permission::VIEW->value);
$this->assertEquals('edit', Permission::EDIT->value);
$this->assertEquals('delete', Permission::DELETE->value);
$this->assertEquals('forceDelete', Permission::FORCEDELETE->value);
$this->assertEquals('restore', Permission::RESTORE->value);
$this->assertEquals('duplicate', Permission::DUPLICATE->value);
$this->assertEquals('reorder', Permission::REORDER->value);
$this->assertEquals('bulk', Permission::BULK->value);
$this->assertEquals('bulkDelete', Permission::BULKDELETE->value);
$this->assertEquals('bulkForceDelete', Permission::BULKFORCEDELETE->value);
$this->assertEquals('bulkRestore', Permission::BULKRESTORE->value);
$this->assertEquals('revisionApprove', Permission::REVISION_APPROVE->value);
$this->assertEquals('revisionReject', Permission::REVISION_REJECT->value);
$this->assertEquals('revisionRestore', Permission::REVISION_RESTORE->value);
$this->assertEquals('activity', Permission::ACTIVITY->value);
$this->assertEquals('show', Permission::SHOW->value);
}

public function test_get_resolves_by_case_name()
{
$this->assertEquals('create', Permission::get('CREATE'));
$this->assertEquals('forceDelete', Permission::get('FORCEDELETE'));
$this->assertEquals('revisionApprove', Permission::get('REVISION_APPROVE'));
}

public function test_get_resolves_by_case_value()
{
$this->assertEquals('edit', Permission::get('edit'));
$this->assertEquals('bulkRestore', Permission::get('bulkRestore'));
}

public function test_get_returns_null_for_unknown_value()
{
$this->assertNull(Permission::get('nonexistent'));
}

public function test_generate_permission_name_kebab_cases_route_name()
{
$this->assertEquals('blog-post_create', Permission::generatePermissionName('CREATE', 'blogPost'));
$this->assertEquals('user-profile_edit', Permission::generatePermissionName('edit', 'userProfile'));
}

public function test_generate_permission_middleware_definition()
{
$this->assertEquals(
'can:blog-post_create',
Permission::generatePermissionMiddlewareDefinition('CREATE', 'blogPost')
);
$this->assertEquals(
'can:user-profile_delete',
Permission::generatePermissionMiddlewareDefinition('delete', 'userProfile')
);
}
}
127 changes: 127 additions & 0 deletions tests/Entities/Enums/ProcessStatusTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace Unusualify\Modularous\Tests\Entities\Enums;

use Unusualify\Modularous\Entities\Enums\ProcessStatus;
use Unusualify\Modularous\Tests\TestCase;

class ProcessStatusTest extends TestCase
{
public function test_cases_have_expected_values()
{
$this->assertEquals('preparing', ProcessStatus::PREPARING->value);
$this->assertEquals('waiting_for_confirmation', ProcessStatus::WAITING_FOR_CONFIRMATION->value);
$this->assertEquals('waiting_for_reaction', ProcessStatus::WAITING_FOR_REACTION->value);
$this->assertEquals('rejected', ProcessStatus::REJECTED->value);
$this->assertEquals('confirmed', ProcessStatus::CONFIRMED->value);
}

public function test_get_returns_value_for_known_case_name()
{
$this->assertEquals('preparing', ProcessStatus::get('PREPARING'));
$this->assertEquals('confirmed', ProcessStatus::get('CONFIRMED'));
}

public function test_get_returns_null_for_unknown_case_name()
{
$this->assertNull(ProcessStatus::get('UNKNOWN'));
$this->assertNull(ProcessStatus::get('preparing'));
}

public function test_label_returns_translated_value()
{
$this->assertEquals(__('Preparing'), ProcessStatus::PREPARING->label());
$this->assertEquals(__('Waiting'), ProcessStatus::WAITING_FOR_CONFIRMATION->label());
$this->assertEquals(__('Waiting'), ProcessStatus::WAITING_FOR_REACTION->label());
$this->assertEquals(__('Rejected'), ProcessStatus::REJECTED->label());
$this->assertEquals(__('Confirmed'), ProcessStatus::CONFIRMED->label());
}

public function test_color_returns_expected_value()
{
$this->assertEquals('info', ProcessStatus::PREPARING->color());
$this->assertEquals('warning', ProcessStatus::WAITING_FOR_CONFIRMATION->color());
$this->assertEquals('warning', ProcessStatus::WAITING_FOR_REACTION->color());
$this->assertEquals('error', ProcessStatus::REJECTED->color());
$this->assertEquals('success', ProcessStatus::CONFIRMED->color());
}

public function test_card_color_returns_expected_value()
{
$this->assertEquals('grey', ProcessStatus::PREPARING->cardColor());
$this->assertEquals('blue-darken-1', ProcessStatus::WAITING_FOR_CONFIRMATION->cardColor());
$this->assertEquals('blue-darken-1', ProcessStatus::WAITING_FOR_REACTION->cardColor());
$this->assertEquals('red-darken-1', ProcessStatus::REJECTED->cardColor());
$this->assertEquals('green-darken-1', ProcessStatus::CONFIRMED->cardColor());
}

public function test_card_variant_returns_expected_value()
{
$this->assertEquals('outlined', ProcessStatus::PREPARING->cardVariant());
$this->assertEquals('outlined', ProcessStatus::WAITING_FOR_CONFIRMATION->cardVariant());
$this->assertEquals('outlined', ProcessStatus::WAITING_FOR_REACTION->cardVariant());
$this->assertEquals('tonal', ProcessStatus::REJECTED->cardVariant());
$this->assertEquals('tonal', ProcessStatus::CONFIRMED->cardVariant());
}

public function test_icon_returns_expected_value()
{
$this->assertEquals('mdi-progress-clock', ProcessStatus::PREPARING->icon());
$this->assertEquals('mdi-clock-check-outline', ProcessStatus::WAITING_FOR_CONFIRMATION->icon());
$this->assertEquals('mdi-clock-check-outline', ProcessStatus::WAITING_FOR_REACTION->icon());
$this->assertEquals('mdi-close-circle-outline', ProcessStatus::REJECTED->icon());
$this->assertEquals('mdi-check-circle-outline', ProcessStatus::CONFIRMED->icon());
}

public function test_next_action_label_returns_translated_value()
{
$this->assertEquals(__('Send for Confirmation'), ProcessStatus::PREPARING->nextActionLabel());
$this->assertEquals(__('Confirm'), ProcessStatus::WAITING_FOR_CONFIRMATION->nextActionLabel());
$this->assertEquals(__('Confirm'), ProcessStatus::WAITING_FOR_REACTION->nextActionLabel());
$this->assertEquals(__('Resend'), ProcessStatus::REJECTED->nextActionLabel());
$this->assertEquals(__('Revert'), ProcessStatus::CONFIRMED->nextActionLabel());
}

public function test_status_reason_label_returns_translated_value()
{
$this->assertEquals(__('Preparing'), ProcessStatus::PREPARING->statusReasonLabel());
$this->assertEquals(__('Arrangement'), ProcessStatus::WAITING_FOR_CONFIRMATION->statusReasonLabel());
$this->assertEquals(__('Arrangement'), ProcessStatus::WAITING_FOR_REACTION->statusReasonLabel());
$this->assertEquals(__('Reason'), ProcessStatus::REJECTED->statusReasonLabel());
$this->assertEquals(__('Confirmation Reason'), ProcessStatus::CONFIRMED->statusReasonLabel());
}

public function test_next_action_color_returns_expected_value()
{
$this->assertEquals('secondary', ProcessStatus::PREPARING->nextActionColor());
$this->assertEquals('success', ProcessStatus::WAITING_FOR_CONFIRMATION->nextActionColor());
$this->assertEquals('success', ProcessStatus::WAITING_FOR_REACTION->nextActionColor());
$this->assertEquals('secondary', ProcessStatus::REJECTED->nextActionColor());
$this->assertEquals('grey-lighten-2', ProcessStatus::CONFIRMED->nextActionColor());
}

public function test_informational_message_returns_translated_value()
{
$this->assertEquals(
__('The contents are being prepared or updated. Please check back later.'),
ProcessStatus::PREPARING->informationalMessage()
);
$this->assertEquals(
__('The contents has been rejected. The reason is under review, you will be informed soon.'),
ProcessStatus::REJECTED->informationalMessage()
);
$this->assertEquals(
__('The contents are confirmed.'),
ProcessStatus::CONFIRMED->informationalMessage()
);
// Cases without an explicit arm fall back to the default message.
$this->assertEquals(
__('The contents are being prepared or updated. Please check back later.'),
ProcessStatus::WAITING_FOR_CONFIRMATION->informationalMessage()
);
$this->assertEquals(
__('The contents are being prepared or updated. Please check back later.'),
ProcessStatus::WAITING_FOR_REACTION->informationalMessage()
);
}
}
Loading
Loading