createMock( TMDO_Entity_Adapter_Interface::class ) ); } private function fields(): array { return array( array( 'key' => 'x_flag', 'type' => 'integer' ), array( 'key' => 'x_price', 'type' => 'decimal' ), ); } public function test_declared_indexes_are_kept_per_group(): void { TMDO_Entity_Registry::register_group( 'post', 'x_core', $this->fields(), array( 'indexes' => array( 'flag_price' => array( 'x_flag', 'x_price' ) ) ) ); $this->assertSame( array( 'flag_price' => array( 'x_flag', 'x_price' ) ), TMDO_Entity_Registry::get_group_indexes( 'post', 'x_core' ) ); $this->assertSame( array(), TMDO_Entity_Registry::get_group_indexes( 'post', 'other' ) ); } public function test_indexes_on_unknown_columns_are_dropped(): void { TMDO_Entity_Registry::register_group( 'post', 'x_core', $this->fields(), array( 'indexes' => array( 'bad' => array( 'x_flag', 'nope' ), 'ok' => array( 'x_price' ) ) ) ); $this->assertSame( array( 'ok' => array( 'x_price' ) ), TMDO_Entity_Registry::get_group_indexes( 'post', 'x_core' ) ); } public function test_indexes_leave_the_field_definition_and_hash_alone(): void { TMDO_Entity_Registry::register_group( 'post', 'plain', $this->fields() ); TMDO_Entity_Registry::register_group( 'post', 'indexed', $this->fields(), array( 'indexes' => array( 'flag_price' => array( 'x_flag', 'x_price' ) ) ) ); $plain = TMDO_Schema_Manager::calculate_schema_hash( TMDO_Entity_Registry::get_group_fields( 'post', 'plain' ) ); $indexed = TMDO_Schema_Manager::calculate_schema_hash( TMDO_Entity_Registry::get_group_fields( 'post', 'indexed' ) ); $this->assertSame( $plain, $indexed ); } public function test_init_clears_indexes(): void { TMDO_Entity_Registry::register_group( 'post', 'x_core', $this->fields(), array( 'indexes' => array( 'ok' => array( 'x_price' ) ) ) ); TMDO_Entity_Registry::init(); $this->assertSame( array(), TMDO_Entity_Registry::get_group_indexes( 'post', 'x_core' ) ); } }