array( 'user' => 'shadow_read' ) ); $GLOBALS['_wp_filter_callbacks'] = array(); $GLOBALS['_wp_current_user_can'] = array( 'manage_options' => true ); TMDO_Mode_Manager::reset_cache(); TMDO_Entity_Registry::init(); TMDO_Entity_Registry::register_adapter( 'user', new TMDO_Adapter_User() ); TMDO_Entity_Registry::register_group( 'user', 'ap_one', array( array( 'key' => 'ap_a', 'type' => 'text' ) ) ); TMDO_Entity_Registry::register_group( 'user', 'ap_two', array( array( 'key' => 'ap_b', 'type' => 'text' ) ) ); } protected function tearDown(): void { TMDO_Entity_Registry::init(); TMDO_Mode_Manager::reset_cache(); } private function drift( string $group, int $diff, int $age = 0 ): void { $GLOBALS['_wp_options'][ TMDO_Drift_Check::OPTION ]['user'][ $group ] = array( 'miss' => 0, 'diff' => $diff, 'extra' => 0, 'sample' => TMDO_Drift_Check::CRON_SAMPLE, 'checked_at' => gmdate( 'Y-m-d H:i:s', time() - $age ), ); } private function check(): string { return TMDO_Auto_Promoter::check_entity( 'user', 7, array( 'user' => time() - self::TEN_DAYS_AGO ) ); } public function test_promotes_when_every_group_checked_clean_recently(): void { $this->drift( 'ap_one', 0 ); $this->drift( 'ap_two', 0 ); $this->assertSame( 'promoted', $this->check() ); $this->assertSame( 'aeav_only', TMDO_Mode_Manager::get( 'user' ) ); } public function test_drift_in_one_group_blocks_promotion(): void { $this->drift( 'ap_one', 0 ); $this->drift( 'ap_two', 1 ); $this->assertSame( 'drift_not_clean', $this->check() ); $this->assertSame( 'shadow_read', TMDO_Mode_Manager::get( 'user' ) ); } public function test_a_group_never_checked_blocks_promotion(): void { $this->drift( 'ap_one', 0 ); $this->assertSame( 'drift_not_clean', $this->check() ); } public function test_a_check_older_than_two_days_blocks_promotion(): void { $this->drift( 'ap_one', 0 ); $this->drift( 'ap_two', 0, 3 * DAY_IN_SECONDS ); $this->assertSame( 'drift_not_clean', $this->check() ); } }