Files
ladill-woo-manager/tests/Unit/WooStoreCurrencyTest.php
T
isaacclad e709de6593
Deploy Ladill Woo Manager / deploy (push) Successful in 35s
Use WooCommerce store currency for product and order money.
Sync currency from the plugin, format product prices and totals with it, and show the store currency on product price fields instead of hard-coding GHS.
2026-07-24 15:38:07 +00:00

85 lines
2.7 KiB
PHP

<?php
namespace Tests\Unit;
use App\Models\User;
use App\Models\WooProduct;
use App\Models\WooStore;
use App\Services\Woo\CatalogSyncService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class WooStoreCurrencyTest extends TestCase
{
use RefreshDatabase;
public function test_product_price_uses_store_woocommerce_currency_not_ghs_default(): void
{
$user = User::factory()->create();
$store = WooStore::query()->create([
'user_id' => $user->id,
'site_url' => 'https://shop.example.com',
'site_name' => 'Example Shop',
'status' => WooStore::STATUS_ACTIVE,
'metadata' => [
'currency' => 'USD',
'currency_symbol' => '$',
],
]);
$product = WooProduct::query()->create([
'woo_store_id' => $store->id,
'external_id' => 42,
'name' => 'Notebook',
'slug' => 'notebook',
'status' => WooProduct::STATUS_PUBLISH,
'type' => 'simple',
'regular_price_minor' => 1999,
]);
$product->setRelation('store', $store);
$this->assertSame('USD', $store->currency());
$this->assertSame('USD 19.99', $product->priceFormatted());
$this->assertStringNotContainsString('GHS', $product->priceFormatted());
}
public function test_apply_store_meta_persists_woocommerce_currency(): void
{
$user = User::factory()->create();
$store = WooStore::query()->create([
'user_id' => $user->id,
'site_url' => 'https://shop.example.com',
'site_name' => 'Old name',
'status' => WooStore::STATUS_ACTIVE,
'metadata' => null,
]);
app(CatalogSyncService::class)->applyStoreMeta($store, [
'currency' => 'eur',
'currency_symbol' => '€',
'site_name' => 'Euro Shop',
]);
$store->refresh();
$this->assertSame('EUR', $store->currency());
$this->assertSame('€', $store->currencySymbol());
$this->assertSame('Euro Shop', $store->site_name);
$this->assertSame('EUR 10.00', $store->formatMoney(1000));
}
public function test_unknown_currency_does_not_fall_back_to_ghs(): void
{
$user = User::factory()->create();
$store = WooStore::query()->create([
'user_id' => $user->id,
'site_url' => 'https://shop.example.com',
'status' => WooStore::STATUS_ACTIVE,
'metadata' => [],
]);
$this->assertSame('', $store->currency());
$this->assertSame('12.50', $store->formatMoney(1250));
$this->assertStringNotContainsString('GHS', $store->formatMoney(1250));
}
}