Files
2meet-data-optimizer-hivepr…/tests/unit/SocialLinksAdapterTest.php
T
wpdev d3ddbb8933 fix(2meet-data-optimizer-hivepress-addon): register enabled social links as hp_{name}
- hivepress-social-links stores each link as hp_{name} (hp_facebook, not
  hp_facebook_url) and lets admins enable links separately for listings
  and vendors; the hardcoded 7 *_url vendor keys never matched real meta
- Read hp_listing_social_links / hp_vendor_social_links and register each
  enabled link on its own post type, so custom links (e.g. line_oa) work
- dev34 check: meta holds hp_instagram / hp_website, and zero *_url keys

Verify: vendor/bin/phpunit --filter HivePressSocialLinksAdapterTest;
  addon unit 156 OK, integration 57 OK
PR: PR-010
2026-09-25 22:35:30 +08:00

74 lines
2.7 KiB
PHP

<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
/**
* Tests for WPDO_HivePress_Social_Links_Adapter.
*
* @covers WPDO_HivePress_Social_Links_Adapter
*/
class HivePressSocialLinksAdapterTest extends TestCase {
private WPDO_HivePress_Social_Links_Adapter $adapter;
protected function setUp(): void {
$reflect = new ReflectionClass( WPDO_Schema_Registry::class );
$prop = $reflect->getProperty( 'instance' );
$prop->setAccessible( true );
$prop->setValue( null, null );
unset( $GLOBALS['_wp_options']['hp_vendor_social_links'], $GLOBALS['_wp_options']['hp_listing_social_links'] );
$this->adapter = new WPDO_HivePress_Social_Links_Adapter();
}
public function test_implements_adapter_interface(): void {
$this->assertInstanceOf( WPDO_HivePress_Adapter::class, $this->adapter );
}
public function test_identity(): void {
$this->assertSame( 'hivepress-social-links', $this->adapter->plugin_slug() );
$this->assertSame( 'HivePress\\SocialLinks\\Plugin', $this->adapter->detection_class() );
}
public function test_registers_enabled_links_per_model(): void {
// hivepress-social-links stores each enabled link as the attribute hp_{name},
// with separate admin selections for listings and vendors.
update_option( 'hp_vendor_social_links', array( 'facebook', 'website' ) );
update_option( 'hp_listing_social_links', array( 'instagram' ) );
$registry = WPDO_Schema_Registry::instance();
$this->adapter->on_register_fields( $registry );
$this->assertSame( 'cold', $registry->get_field( 'hp_vendor', 'hp_facebook' )['zone'] );
$this->assertSame( 'cold', $registry->get_field( 'hp_vendor', 'hp_website' )['zone'] );
$this->assertSame( 'cold', $registry->get_field( 'hp_listing', 'hp_instagram' )['zone'] );
$this->assertNull( $registry->get_field( 'hp_vendor', 'hp_instagram' ) );
$this->assertNull( $registry->get_field( 'hp_vendor', 'hp_facebook_url' ) );
}
public function test_registers_nothing_when_no_links_enabled(): void {
$registry = WPDO_Schema_Registry::instance();
$this->adapter->on_register_fields( $registry );
$this->assertNull( $registry->get_field( 'hp_vendor', 'hp_facebook' ) );
$this->assertNull( $registry->get_field( 'hp_listing', 'hp_facebook' ) );
}
public function test_doctor_check_reports_registered_count(): void {
update_option( 'hp_vendor_social_links', array( 'facebook', 'website' ) );
update_option( 'hp_listing_social_links', array( 'instagram' ) );
$result = $this->adapter->doctor_check();
$this->assertTrue( $result['ok'] );
$this->assertStringContainsString( '3 cold fields', $result['message'] );
}
public function test_score_aggregates_to_perfect_ten(): void {
$this->assertSame( 10.0, $this->adapter->suitability_score()['aggregate'] );
}
}