/** * Checks that even though the addon was upgraded, because it happened during * maintenance mode, we couldn't do any of its setup logic. (SO it should be run * later, when the site is taken out of MM by the migration manager) * @group 6910 */ public function test_detect_actiavtions_or_upgrade__upgrade_during_maintenance_mode() { global $wp_actions; //pretend an older version of this addon was activated a while ago $addon_activation_history = array('0.9.0.dev.000' => array(date('Y-m-d H:i:s', current_time('timestamp') - DAY_IN_SECONDS * 10))); update_option($this->_addon->get_activation_history_option_name(), $addon_activation_history); //and it also shouldn't be in the current db state $current_db_state = get_option(EE_Data_Migration_Manager::current_database_state); //just for assurance, make sure New Addon is the only existing addon unset($current_db_state[$this->_addon_name]); update_option(EE_Data_Migration_Manager::current_database_state, $current_db_state); $times_reactivation_hook_fired_before = isset($wp_actions["AHEE__{$this->_addon_classname}__upgrade"]) ? $wp_actions["AHEE__{$this->_addon_classname}__upgrade"] : 0; //lastly, and imporatntly SET MAINTENANCE MODE LEVEL 2 $this->_add_mock_dms(); //now check for activations/upgrades in addons EE_System::reset(); $this->assertEquals(EE_Maintenance_Mode::level_2_complete_maintenance, EE_Maintenance_Mode::instance()->level()); $this->assertEquals(EE_System::req_type_upgrade, $this->_addon->detect_req_type()); $this->assertEquals($times_reactivation_hook_fired_before + 1, isset($wp_actions["AHEE__{$this->_addon_classname}__upgrade"]) ? $wp_actions["AHEE__{$this->_addon_classname}__upgrade"] : 0); $this->assertArrayContains('New_Addon', EE_Data_Migration_Manager::instance()->get_db_initialization_queue()); $addon_activation_history = $this->_addon->get_activation_history(); $this->assertArrayHasKey('0.9.0.dev.000', $addon_activation_history); $this->assertArrayHasKey('1.0.0.dev.000', $addon_activation_history); $this->assertTableDoesNotExist('esp_new_addon_thing'); //ok, now let's pretend the site was teaken out of MM because migrations were finished $this->_remove_mock_dms(); EE_Maintenance_Mode::reset()->set_maintenance_level(EE_Maintenance_Mode::level_0_not_in_maintenance); EE_Data_Migration_Manager::instance()->initialize_db_for_enqueued_ee_plugins(); //now we also want to check that the addon will have created the necessary table //that it needed upon new activation $this->assertEquals(array(), EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()); $this->assertEquals(EE_Maintenance_Mode::level_0_not_in_maintenance, EE_Maintenance_Mode::instance()->real_level()); $this->assertTableExists('esp_new_addon_thing'); //check for activations/upgrades again. It should be a normal request EE_System::reset(); $this->assertEquals(EE_System::req_type_normal, $this->_addon->detect_req_type()); $this->assertEquals($times_reactivation_hook_fired_before + 1, $wp_actions["AHEE__{$this->_addon_classname}__upgrade"]); $this->assertWPOptionDoesNotExist($this->_addon->get_activation_indicator_option_name()); }