query( 'DROP TABLE IF EXISTS `' . self::TABLE . '`' ); $wpdb->query( 'CREATE TABLE `' . self::TABLE . '` ( `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT, `post_id` bigint(20) unsigned NOT NULL DEFAULT 0, `hp_price` decimal(10,2) NOT NULL DEFAULT 0, `hp_featured` tinyint(1) NOT NULL DEFAULT 0, `updated_at` datetime NOT NULL DEFAULT \'0000-00-00 00:00:00\', PRIMARY KEY (`id`), UNIQUE KEY `post_id` (`post_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4' ); } public static function tearDownAfterClass(): void { global $wpdb; $wpdb->query( 'DROP TABLE IF EXISTS `' . self::TABLE . '`' ); } protected function setUp(): void { global $wpdb; $wpdb->query( 'TRUNCATE TABLE `' . self::TABLE . '`' ); } // ── set / get ──────────────────────────────────────────────────────── public function test_set_and_get_single_field(): void { WPDO_Zone_Hot::set( 1, self::POST_TYPE, 'hp_price', '199.99' ); $val = WPDO_Zone_Hot::get( 1, self::POST_TYPE, 'hp_price' ); $this->assertSame( '199.99', $val ); } public function test_get_returns_null_for_missing_post(): void { $val = WPDO_Zone_Hot::get( 9999, self::POST_TYPE, 'hp_price' ); $this->assertNull( $val ); } public function test_set_overwrites_existing_value(): void { WPDO_Zone_Hot::set( 2, self::POST_TYPE, 'hp_price', '50.00' ); WPDO_Zone_Hot::set( 2, self::POST_TYPE, 'hp_price', '75.00' ); $val = WPDO_Zone_Hot::get( 2, self::POST_TYPE, 'hp_price' ); $this->assertSame( '75.00', $val ); } public function test_set_featured_integer_field(): void { WPDO_Zone_Hot::set( 3, self::POST_TYPE, 'hp_featured', '1' ); $val = WPDO_Zone_Hot::get( 3, self::POST_TYPE, 'hp_featured' ); $this->assertSame( '1', $val ); } // ── set_many / get_row ─────────────────────────────────────────────── public function test_set_many_stores_multiple_columns(): void { WPDO_Zone_Hot::set_many( 4, self::POST_TYPE, [ 'hp_price' => '299.00', 'hp_featured' => '1', ] ); $row = WPDO_Zone_Hot::get_row( 4, self::POST_TYPE ); $this->assertIsArray( $row ); $this->assertSame( '299.00', $row['hp_price'] ); $this->assertSame( '1', $row['hp_featured'] ); } public function test_set_many_overwrites_on_second_call(): void { WPDO_Zone_Hot::set_many( 5, self::POST_TYPE, [ 'hp_price' => '100.00', 'hp_featured' => '0' ] ); WPDO_Zone_Hot::set_many( 5, self::POST_TYPE, [ 'hp_price' => '200.00', 'hp_featured' => '1' ] ); $row = WPDO_Zone_Hot::get_row( 5, self::POST_TYPE ); $this->assertSame( '200.00', $row['hp_price'] ); $this->assertSame( '1', $row['hp_featured'] ); } public function test_get_row_returns_null_for_missing_post(): void { $row = WPDO_Zone_Hot::get_row( 9998, self::POST_TYPE ); $this->assertNull( $row ); } // ── delete ─────────────────────────────────────────────────────────── public function test_delete_removes_row(): void { WPDO_Zone_Hot::set( 6, self::POST_TYPE, 'hp_price', '42.00' ); $this->assertNotNull( WPDO_Zone_Hot::get( 6, self::POST_TYPE, 'hp_price' ) ); WPDO_Zone_Hot::delete( 6, self::POST_TYPE ); $this->assertNull( WPDO_Zone_Hot::get( 6, self::POST_TYPE, 'hp_price' ) ); } public function test_delete_nonexistent_post_does_not_error(): void { // Should complete without throwing. WPDO_Zone_Hot::delete( 9997, self::POST_TYPE ); $this->assertTrue( true ); } // ── isolation ──────────────────────────────────────────────────────── public function test_different_post_ids_are_independent(): void { WPDO_Zone_Hot::set( 10, self::POST_TYPE, 'hp_price', '10.00' ); WPDO_Zone_Hot::set( 11, self::POST_TYPE, 'hp_price', '11.00' ); $this->assertSame( '10.00', WPDO_Zone_Hot::get( 10, self::POST_TYPE, 'hp_price' ) ); $this->assertSame( '11.00', WPDO_Zone_Hot::get( 11, self::POST_TYPE, 'hp_price' ) ); } }