true, 'key' => 'phc_browser', 'host' => 'https://ingest.aisthetix.fyi', 'environment' => 'production', ), $overrides ); } echo "Plugin::replay_settings()\n"; // --- the merchant's switch --------------------------------------------------- given( array( 'enable_session_replay' => false ) ); check( 'is off when the merchant has not enabled it, even with a key from Core', array(), Plugin::replay_settings( remote() ) ); // --- the operator's switch, served by Core ----------------------------------- given( array( 'enable_session_replay' => true ) ); check( 'is off when Core says replay is globally disabled', array(), Plugin::replay_settings( remote( array( 'enabled' => false ) ) ) ); given( array( 'enable_session_replay' => true ) ); check( 'is off when Core serves no key', array(), Plugin::replay_settings( remote( array( 'key' => '' ) ) ) ); given( array( 'enable_session_replay' => true ) ); check( 'treats a whitespace-only key as no key', array(), Plugin::replay_settings( remote( array( 'key' => ' ' ) ) ) ); // --- no status at all -------------------------------------------------------- given( array( 'enable_session_replay' => true ) ); check( 'is off when Core could not be reached', array(), Plugin::replay_settings( array() ) ); // --- neither ---------------------------------------------------------------- given( array() ); check( 'is off by default', array(), Plugin::replay_settings( remote() ) ); // --- both ------------------------------------------------------------------- given( array( 'enable_session_replay' => true ), array(), array( 'aisthetix_tryon_store_id' => 'store_42' ) ); $result = Plugin::replay_settings( remote() ); check( 'is on only when the merchant enabled it AND Core allows it', true, isset( $result['analytics'] ) ); check( 'carries the key Core served', 'phc_browser', $result['analytics']['replayKey'] ); check( 'flags replay enabled', true, $result['analytics']['replayEnabled'] ); check( 'carries the environment Core is in', 'production', $result['analytics']['environment'] ); // The store id lives in its OWN option, not in the settings array. Reading it // from the settings array yields an empty string, and an empty store means every // recording lands unattributed — visible only to someone looking for it. check( 'carries the store id from the option that actually holds it', 'store_42', $result['analytics']['storeId'] ); check( 'never falls back to posthog.com', 'https://ingest.aisthetix.fyi', $result['analytics']['ingestHost'] ); // --- host from Core ---------------------------------------------------------- given( array( 'enable_session_replay' => true ), array(), array( 'aisthetix_tryon_store_id' => 'store_42' ) ); $result = Plugin::replay_settings( remote( array( 'host' => 'https://ingest-staging.aisthetix.fyi/' ) ) ); check( 'strips a trailing slash from the host Core served', 'https://ingest-staging.aisthetix.fyi', $result['analytics']['ingestHost'] ); // --- a store that never completed Connect ------------------------------------ given( array( 'enable_session_replay' => true ) ); $result = Plugin::replay_settings( remote() ); check( 'refuses to configure replay for a store with no id', array(), $result ); echo "\n{$passed} passed, {$failed} failed\n"; exit( $failed === 0 ? 0 : 1 );