f089b0934b
- hivepress-marketplace stores its filterable, sortable listing price as hp_price; hp_purchase_price never existed (dev34: 588 hp_price rows) - Drop hp_purchase_count: the addon keeps no per-listing sales counter - Remove the stale docblock note about the legacy core registration path Verify: vendor/bin/phpunit --filter test_on_register_fields_registers_hot_hp_price; addon unit 156 OK, integration 57 OK PR: PR-011
56 lines
1.9 KiB
PHP
56 lines
1.9 KiB
PHP
<?php
|
||
declare(strict_types=1);
|
||
|
||
use PHPUnit\Framework\TestCase;
|
||
|
||
/**
|
||
* Tests for WPDO_HivePress_Marketplace_Adapter (detect-only).
|
||
*
|
||
* @covers WPDO_HivePress_Marketplace_Adapter
|
||
*/
|
||
class HivePressMarketplaceAdapterTest extends TestCase {
|
||
|
||
use WpdbMockTrait;
|
||
|
||
private WPDO_HivePress_Marketplace_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_Marketplace_Adapter();
|
||
}
|
||
|
||
public function test_implements_adapter_interface(): void {
|
||
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
|
||
}
|
||
|
||
public function test_identity(): void {
|
||
$this->assertSame( 'hivepress-marketplace', $this->adapter->plugin_slug() );
|
||
$this->assertSame( 'HivePress\\Marketplace\\Plugin', $this->adapter->detection_class() );
|
||
}
|
||
|
||
public function test_on_register_fields_registers_hot_hp_price(): void {
|
||
$registry = WPDO_Schema_Registry::instance();
|
||
$this->adapter->on_register_fields( $registry );
|
||
|
||
// Marketplace's filterable, sortable listing "price" attribute is stored as hp_price.
|
||
$price = $registry->get_field( 'hp_listing', 'hp_price' );
|
||
$this->assertSame( 'hot', $price['zone'] );
|
||
$this->assertTrue( (bool) $price['indexed'] );
|
||
$this->assertStringContainsString( 'decimal', $price['data_type'] );
|
||
|
||
// Neither key exists in hivepress-marketplace.
|
||
$this->assertNull( $registry->get_field( 'hp_listing', 'hp_purchase_price' ) );
|
||
$this->assertNull( $registry->get_field( 'hp_listing', 'hp_purchase_count' ) );
|
||
}
|
||
|
||
public function test_score_aggregates_to_nine_eight_eight(): void {
|
||
// D8 = 0.9 → aggregate = (7×1.0 + 0.9)/8 × 10 = 9.875 → 9.88.
|
||
$this->assertSame( 9.88, $this->adapter->suitability_score()['aggregate'] );
|
||
}
|
||
}
|