e443f20edb
- hivepress-bookings has no guests field; the places booked are stored as hp_quantity (only when "Allow multiple places" is enabled) - Verified against hivepress-bookings 1.5.5: start_time / end_time were already correct and stay unchanged Verify: vendor/bin/phpunit --filter test_on_register_fields_uses_real_booking_meta_keys; addon unit 155 OK, integration 57 OK PR: PR-009
73 lines
2.4 KiB
PHP
73 lines
2.4 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
|
||
use PHPUnit\Framework\TestCase;
|
||
|
||
/**
|
||
* Tests for WPDO_HivePress_Bookings_Adapter (detect-only).
|
||
*
|
||
* @covers WPDO_HivePress_Bookings_Adapter
|
||
*/
|
||
class HivePressBookingsAdapterTest extends TestCase {
|
||
|
||
use WpdbMockTrait;
|
||
|
||
private WPDO_HivePress_Bookings_Adapter $adapter;
|
||
|
||
protected function setUp(): void {
|
||
$this->install_wpdb_mock();
|
||
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
|
||
$prop = $reflect->getProperty( 'instance' );
|
||
$prop->setAccessible( true );
|
||
$prop->setValue( null, null );
|
||
|
||
$this->adapter = new WPDO_HivePress_Bookings_Adapter();
|
||
}
|
||
|
||
public function test_implements_adapter_interface(): void {
|
||
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||
}
|
||
|
||
public function test_identity(): void {
|
||
$this->assertSame( 'hivepress-bookings', $this->adapter->plugin_slug() );
|
||
$this->assertSame( 'HivePress\\Bookings\\Plugin', $this->adapter->detection_class() );
|
||
}
|
||
|
||
public function test_on_register_fields_reserves_booking_hot_columns(): void {
|
||
$registry = WPDO_Schema_Registry::instance();
|
||
$this->adapter->on_register_fields( $registry );
|
||
|
||
$start = $registry->get_field( 'hp_booking', 'hp_start_time' );
|
||
$this->assertSame( 'hot', $start['zone'] );
|
||
$this->assertTrue( (bool) $start['indexed'] );
|
||
|
||
$end = $registry->get_field( 'hp_booking', 'hp_end_time' );
|
||
$this->assertSame( 'hot', $end['zone'] );
|
||
$this->assertTrue( (bool) $end['indexed'] );
|
||
}
|
||
|
||
public function test_on_register_fields_uses_real_booking_meta_keys(): void {
|
||
$registry = WPDO_Schema_Registry::instance();
|
||
$this->adapter->on_register_fields( $registry );
|
||
|
||
// hivepress-bookings has no guests field; places are stored as hp_quantity.
|
||
$this->assertNull( $registry->get_field( 'hp_booking', 'hp_guests' ) );
|
||
|
||
$quantity = $registry->get_field( 'hp_booking', 'hp_quantity' );
|
||
$this->assertNotNull( $quantity );
|
||
$this->assertSame( 'hot', $quantity['zone'] );
|
||
}
|
||
|
||
public function test_score_reflects_unverified_perf_dimension(): void {
|
||
$score = $this->adapter->suitability_score();
|
||
// D8 reduced to 0.9 because schema is best-effort until addon installs.
|
||
$this->assertSame( 0.9, $score['d8_perf'] );
|
||
// Aggregate = (7 × 1.0 + 0.9) / 8 × 10 = 9.875 → 9.88.
|
||
$this->assertSame( 9.88, $score['aggregate'] );
|
||
}
|
||
|
||
public function test_migrations_lists_booking_module(): void {
|
||
$this->assertSame( array( 'hot_hp_booking' ), $this->adapter->migrations() );
|
||
}
|
||
}
|