You've already forked wc-composable-product
- 57 unit tests covering ProductType, StockManager, CartHandler, Plugin, Admin/ProductData, Admin/Settings using Brain Monkey + Mockery - WooCommerce class stubs for testing without WP installation - PHP lint and test jobs in release workflow (test gate blocks release) - PSR-4 namespace change: WC_Composable_Product -> Magdev\WcComposableProduct - PascalCase filenames for all classes under includes/ Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
85 lines
2.7 KiB
PHP
85 lines
2.7 KiB
PHP
<?php
|
|
/**
|
|
* Admin Settings Tests
|
|
*
|
|
* @package Magdev\WcComposableProduct\Tests
|
|
*/
|
|
|
|
namespace Magdev\WcComposableProduct\Tests\Unit\Admin;
|
|
|
|
use Magdev\WcComposableProduct\Tests\TestCase;
|
|
use Magdev\WcComposableProduct\Admin\Settings;
|
|
use Brain\Monkey\Functions;
|
|
|
|
class SettingsTest extends TestCase
|
|
{
|
|
public function testConstructor_SetsIdAndLabel(): void
|
|
{
|
|
$settings = new Settings();
|
|
|
|
$this->assertSame('composable_products', $settings->get_id());
|
|
}
|
|
|
|
public function testGetSettings_ReturnsExpectedFieldIds(): void
|
|
{
|
|
Functions\expect('apply_filters')
|
|
->once()
|
|
->with('wc_composable_settings', \Mockery::type('array'))
|
|
->andReturnUsing(function ($hook, $settings) {
|
|
return $settings;
|
|
});
|
|
|
|
$settings = new Settings();
|
|
$fields = $settings->get_settings();
|
|
|
|
// Extract all field IDs
|
|
$ids = array_column($fields, 'id');
|
|
|
|
$this->assertContains('wc_composable_settings', $ids);
|
|
$this->assertContains('wc_composable_default_limit', $ids);
|
|
$this->assertContains('wc_composable_default_pricing', $ids);
|
|
$this->assertContains('wc_composable_include_unpublished', $ids);
|
|
$this->assertContains('wc_composable_show_images', $ids);
|
|
$this->assertContains('wc_composable_show_prices', $ids);
|
|
$this->assertContains('wc_composable_show_total', $ids);
|
|
}
|
|
|
|
public function testGetSettings_HasCorrectFieldTypes(): void
|
|
{
|
|
Functions\expect('apply_filters')
|
|
->once()
|
|
->andReturnUsing(function ($hook, $settings) {
|
|
return $settings;
|
|
});
|
|
|
|
$settings = new Settings();
|
|
$fields = $settings->get_settings();
|
|
|
|
// Index fields by ID for easy lookup
|
|
$indexed = [];
|
|
foreach ($fields as $field) {
|
|
if (isset($field['id'])) {
|
|
$indexed[$field['id']] = $field;
|
|
}
|
|
}
|
|
|
|
$this->assertSame('number', $indexed['wc_composable_default_limit']['type']);
|
|
$this->assertSame('select', $indexed['wc_composable_default_pricing']['type']);
|
|
$this->assertSame('checkbox', $indexed['wc_composable_include_unpublished']['type']);
|
|
$this->assertSame('checkbox', $indexed['wc_composable_show_images']['type']);
|
|
}
|
|
|
|
public function testGetSettings_AppliesFilter(): void
|
|
{
|
|
Functions\expect('apply_filters')
|
|
->once()
|
|
->with('wc_composable_settings', \Mockery::type('array'))
|
|
->andReturnUsing(function ($hook, $settings) {
|
|
return $settings;
|
|
});
|
|
|
|
$settings = new Settings();
|
|
$settings->get_settings();
|
|
}
|
|
}
|