assertSame( '0.1.0-0', Build::id( '0.1.0', false ) ); $this->assertSame( '0.1.0-7', Build::id( '0.1.0', '7' ) ); $this->assertSame( '1.2x-0', Build::id( '1.2"', 'abc' ), 'junk characters are stripped, junk epoch is 0' ); $this->assertSame( '0-0', Build::id( '', null ) ); $this->assertNotSame( Build::id( '0.1.0', 1 ), Build::id( '0.1.1', 1 ) ); $this->assertNotSame( Build::id( '0.1.0', 1 ), Build::id( '0.1.0', 2 ) ); } public function test_headers_carry_only_the_build_and_never_touch_the_etag(): void { $this->assertSame( array( 'X-SG-Build' => '0.1.0-3' ), Build::headers( '0.1.0-3' ) ); $src = (string) file_get_contents( dirname( __DIR__, 2 ) . '/includes/Rest/OverlayController.php' ); $this->assertStringContainsString( 'Build::headers( Build::current() )', $src ); $this->assertStringContainsString( 'Payloads::etag( $payload, $service->etagSalt(', $src, 'ETag is still computed from the payload only' ); } public function test_epoch_bump_rules(): void { $this->assertSame( 1000, Build::nextEpoch( 0, 1000 ) ); $this->assertSame( 1000, Build::nextEpoch( false, 1000 ) ); $this->assertSame( 1000, Build::nextEpoch( '999', 1000 ) ); $this->assertSame( 2001, Build::nextEpoch( 2000, 1000 ), 'strictly increasing even if the clock went back' ); $this->assertSame( 1000, Build::nextEpoch( '-5', 1000 ) ); $this->assertSame( 1000, Build::nextEpoch( array( 9 ), 1000 ) ); $this->assertSame( 0, Build::epochInt( 1.5 ) ); $this->assertSame( 0, Build::epochInt( '99999999999999999999' ) ); } public function test_refresh_handler_is_guarded_registered_and_option_is_not_autoloaded(): void { $root = dirname( __DIR__, 2 ) . '/includes/'; $page = (string) file_get_contents( $root . 'Admin/OverlaysPage.php' ); $start = strpos( $page, 'function handleRefreshAll' ); $this->assertNotFalse( $start ); $this->assertStringContainsString( "Admin::guard( 'sg_refresh_overlays' )", substr( $page, $start, 200 ) ); $this->assertStringContainsString( "'sg_refresh_overlays' => array( OverlaysPage::class, 'handleRefreshAll' )", (string) file_get_contents( $root . 'Admin/Admin.php' ) ); $this->assertStringContainsString( 'Reloads every open OBS source. Done automatically after a plugin update.', $page ); $this->assertStringContainsString( ', false );', substr( (string) file_get_contents( $root . 'Overlay/Build.php' ), (int) strpos( (string) file_get_contents( $root . 'Overlay/Build.php' ), 'update_option' ) ) ); $this->assertStringContainsString( 'data-build=', (string) file_get_contents( $root . 'Overlay/Router.php' ) ); } public function test_media_version_suffix_builder(): void { $this->assertSame( 'https://x.test/a.png?v=123', Media::withVersion( 'https://x.test/a.png', 123 ) ); $this->assertSame( 'https://x.test/a.png?q=1&v=123', Media::withVersion( 'https://x.test/a.png?q=1', 123 ) ); $this->assertSame( 'https://x.test/a.png?v=123', Media::withVersion( 'https://x.test/a.png?v=5', 123 ), 'replaces an old v' ); $this->assertSame( 'https://x.test/a.png?q=1&v=123', Media::withVersion( 'https://x.test/a.png?v=5&q=1', 123 ) ); $this->assertSame( 'https://x.test/a.png?v=' . strtotime( '2024-05-06 07:08:09 UTC' ), Media::withVersion( 'https://x.test/a.png', 0, '2024-05-06 07:08:09' ), 'falls back to post_modified_gmt' ); $this->assertSame( 'https://x.test/a.png?v=50', Media::withVersion( 'https://x.test/a.png', 50, '2024-05-06 07:08:09' ), 'file mtime wins' ); $this->assertSame( 'https://x.test/a.png', Media::withVersion( 'https://x.test/a.png', 0, '0000-00-00 00:00:00x' ) ); $this->assertSame( 'https://x.test/a.png', Media::withVersion( 'https://x.test/a.png', 0 ) ); $this->assertSame( 'https://x.test/a.png#f', Media::withVersion( 'https://x.test/a.png#f', 9 ) ); $this->assertNotNull( Media::safeUrl( Media::withVersion( 'https://x.test/a.png', 123 ) ) ); } public function test_installer_has_frameless_column_and_version_five(): void { $src = (string) file_get_contents( dirname( __DIR__, 2 ) . '/includes/Core/Installer.php' ); $this->assertSame( 1, preg_match( "/DB_VERSION = '(\\d+)'/", $src, $m ) ); $this->assertGreaterThanOrEqual( 5, (int) $m[1] ); $this->assertMatchesRegularExpression( '/CREATE TABLE \{\$p\}alert_defs \([^;]*frameless TINYINT\(1\) NOT NULL DEFAULT 0,/s', $src ); } public function test_overlay_js_checks_build_on_every_response_including_304(): void { $js = (string) file_get_contents( dirname( __DIR__, 2 ) . '/assets/overlay/overlay.js' ); $this->assertLessThan( strpos( $js, 'r.status === 304' ), strpos( $js, 'checkBuild(r)' ), 'build is compared before the 304 shortcut' ); $this->assertStringContainsString( 'X-SG-Build', $js ); } }