/** * Test misc admin bar extensions. * * @covers CustomizeSnapshots\Customize_Snapshot_Manager::add_post_edit_screen_link() * @covers CustomizeSnapshots\Customize_Snapshot_Manager::add_snapshot_exit_link() * @covers CustomizeSnapshots\Customize_Snapshot_Manager::add_resume_snapshot_link() * @covers CustomizeSnapshots\Customize_Snapshot_Manager::remove_all_non_snapshot_admin_bar_links() */ public function test_add_post_edit_and_exit_links() { global $wp_admin_bar; set_current_screen('front'); require_once ABSPATH . WPINC . '/class-wp-admin-bar.php'; $this->manager->post_type->save(array('uuid' => self::UUID, 'data' => array('blogname' => array('value' => 'Hello')), 'status' => 'draft')); remove_all_actions('admin_bar_menu'); $manager = new Customize_Snapshot_Manager($this->plugin); $manager->init(); $wp_admin_bar = new \WP_Admin_Bar(); // WPCS: Override OK. $wp_admin_bar->initialize(); $wp_admin_bar->add_menus(); do_action_ref_array('admin_bar_menu', array(&$wp_admin_bar)); $this->assertEmpty($wp_admin_bar->get_node('inspect-customize-snapshot')); $this->assertEmpty($wp_admin_bar->get_node('exit-customize-snapshot')); $this->assertNotEmpty($wp_admin_bar->get_node('wporg')); $this->assertNotEmpty($wp_admin_bar->get_node('resume-customize-snapshot')); $this->go_to(home_url('?customize_snapshot_uuid=' . self::UUID)); $_REQUEST['customize_snapshot_uuid'] = self::UUID; remove_all_actions('admin_bar_menu'); $manager = new Customize_Snapshot_Manager($this->plugin); $manager->init(); $wp_admin_bar = new \WP_Admin_Bar(); // WPCS: Override OK. $wp_admin_bar->initialize(); $wp_admin_bar->add_menus(); do_action_ref_array('admin_bar_menu', array(&$wp_admin_bar)); $this->assertNotEmpty($wp_admin_bar->get_node('inspect-customize-snapshot')); $this->assertNotEmpty($wp_admin_bar->get_node('exit-customize-snapshot')); $this->assertEmpty($wp_admin_bar->get_node('wporg')); $this->assertNotEmpty($wp_admin_bar->get_node('resume-customize-snapshot')); }
/** * Initiate the plugin resources. * * Priority is 8 because \CustomizeWidgetsPlus\Widget_Posts::init() happens * at priority 9, and this calls \CustomizeWidgetsPlus\Widget_Posts::add_customize_hooks(). * So we need priority 8 so that the Customizer will be initialized before Widget Posts * initializes. * * @action after_setup_theme, 8 */ public function init() { $this->customize_snapshot_manager = new Customize_Snapshot_Manager($this); $this->customize_snapshot_manager->init(); }
/** * Test that the snapshot object is passed as the second filter param. * * @see Customize_Snapshot::save() */ function test_filter_customize_snapshot_save() { $manager = new Customize_Snapshot_Manager($this->plugin); $manager->ensure_customize_manager(); $manager->init(); $snapshot = new Customize_Snapshot($manager, self::UUID); $that = $this; // For PHP 5.3. add_filter('customize_snapshot_save', function ($data, $test_snapshot) use($that) { $that->filtered_snapshot = $test_snapshot; return $data; }, 10, 2); $snapshot->save(array('uuid' => self::UUID, 'data' => array('foo' => array('value' => 'bar')))); $this->assertEquals($snapshot, $this->filtered_snapshot); }