/** * Unregister existing post types and register defaults. * * Run before each test in order to clean up the global scope, in case * a test forgets to unregister a post type on its own, or fails before * it has a chance to do so. */ protected function reset_post_types() { foreach (get_post_types() as $pt) { _unregister_post_type($pt); } create_initial_post_types(); }
function tearDown() { parent::tearDown(); $bp = buddypress(); _unregister_post_type('using_old_filter'); remove_filter('bp_blogs_record_post_post_types', array($this, 'filter_post_types'), 10); remove_filter('bp_blogs_record_comment_post_types', array($this, 'filter_post_types'), 10); }
function test_current_post_type_custom_post_type() { register_post_type('content'); set_current_screen('content'); $this->assertEquals('content', self::$EditFlowModule->get_current_post_type()); _unregister_post_type('content'); set_current_screen('front'); }
public function tearDown() { parent::tearDown(); foreach ($this->cpts as $cpt => $cpto) { _unregister_post_type($cpt); _unregister_taxonomy("{$cpt}_category"); } }
/** * @ticket 30904 */ function test_get_the_author_posts_with_custom_post_type() { register_post_type('wptests_pt'); $cpt_ids = self::factory()->post->create_many(2, array('post_author' => $this->author_id, 'post_type' => 'wptests_pt')); $GLOBALS['post'] = $cpt_ids[0]; $this->assertEquals(2, get_the_author_posts()); _unregister_post_type('wptests_pt'); }
function test_url_to_postid_custom_post_type() { delete_option('rewrite_rules'); $post_type = rand_str(12); register_post_type($post_type, array('public' => true)); $id = $this->factory->post->create(array('post_type' => $post_type)); $this->assertEquals($id, url_to_postid(get_permalink($id))); _unregister_post_type($post_type); }
/** * @ticket 23302 */ function test_post_type_with_no_feed() { global $wp_rewrite; $old_permastruct = get_option('permalink_structure'); update_option('permalink_structure', '%postname%'); register_post_type('foo', array('rewrite' => array('feeds' => false))); $this->assertFalse($wp_rewrite->extra_permastructs['foo']['feed']); update_option('permalink_structure', $old_permastruct); _unregister_post_type('foo'); }
/** * @ticket 21117 */ function test_content_post_type() { register_post_type('content', array('show_in_admin_bar' => true)); $admin_bar = new WP_Admin_Bar(); wp_admin_bar_new_content_menu($admin_bar); $nodes = $admin_bar->get_nodes(); $this->assertFalse($nodes['new-content']->parent); $this->assertEquals('new-content', $nodes['add-new-content']->parent); _unregister_post_type('content'); }
public function tearDown() { parent::tearDown(); foreach ($this->cpts as $cpt => $cpto) { $pto = get_post_type_object($cpt); if (!$pto->_builtin) { _unregister_post_type($cpt); _unregister_taxonomy("{$cpt}_category"); } } }
/** * @ticket BP6865 */ public function test_sort_new_post_type_twice() { $actions = bp_activity_get_actions(); $expected = array('new_blog_post' => 'new_blog_post', 'new_blog_comment' => 'new_blog_comment'); $this->assertSame($expected, wp_list_pluck((array) $actions->blogs, 'key')); register_post_type('foo', array('label' => 'foo', 'public' => true, 'supports' => array('buddypress-activity'), 'bp_activity' => array('component_id' => 'blogs', 'action_id' => 'new_foo', 'position' => 1))); $actions = bp_activity_get_actions(); _unregister_post_type('foo'); $expected = array('new_foo' => 'new_foo', 'new_blog_post' => 'new_blog_post', 'new_blog_comment' => 'new_blog_comment'); $this->assertSame($expected, wp_list_pluck((array) $actions->blogs, 'key')); }
function tearDown() { parent::tearDown(); $bp = buddypress(); _unregister_post_type('using_old_filter'); remove_filter('bp_blogs_record_post_post_types', array($this, 'filter_post_types'), 10, 1); remove_filter('bp_blogs_record_comment_post_types', array($this, 'filter_post_types'), 10, 1); // Reset activity actions $bp->activity->actions = $this->activity_actions; $bp->activity->track = array(); }
/** * @ticket 21586 */ function test_post_type_with_no_support() { register_post_type('foo', array('supports' => array())); $this->assertTrue(post_type_supports('foo', 'editor')); $this->assertTrue(post_type_supports('foo', 'title')); _unregister_post_type('foo'); register_post_type('foo', array('supports' => false)); $this->assertFalse(post_type_supports('foo', 'editor')); $this->assertFalse(post_type_supports('foo', 'title')); _unregister_post_type('foo'); }
/** * @ticket 21117 */ function test_content_post_type() { wp_set_current_user($this->factory->user->create(array('role' => 'editor'))); register_post_type('content', array('show_in_admin_bar' => true)); $admin_bar = new WP_Admin_Bar(); wp_admin_bar_new_content_menu($admin_bar); $nodes = $admin_bar->get_nodes(); $this->assertFalse($nodes['new-content']->parent); $this->assertEquals('new-content', $nodes['add-new-content']->parent); _unregister_post_type('content'); }
/** * @group bp_activity_catch_transition_post_type_status * @group activity_tracking */ public function test_bp_activity_catch_transition_post_type_status_publish_trash() { $bp = buddypress(); register_post_type('foo', array('label' => 'foo', 'public' => true, 'supports' => array('buddypress-activity'))); $post_id = $this->factory->post->create(array('post_status' => 'publish', 'post_type' => 'foo')); $post = get_post($post_id); // 'new' => 'publish' $this->assertTrue($this->activity_exists_for_post($post_id, 'new_foo'), 'Published post type should have activity'); wp_trash_post($post->ID); // 'publish' => 'publish' (password protected) $this->assertFalse($this->activity_exists_for_post($post_id, 'new_foo'), 'Unpublished post type should not have activity'); _unregister_post_type('foo'); // Reset globals unset($bp->activity->actions->activity->new_foo); $bp->activity->track = array(); }
/** * @ticket 18962 */ function test_wp_unique_post_slug_with_hierarchy_and_attachments() { register_post_type('post-type-1', array('hierarchical' => true)); $args = array('post_type' => 'post-type-1', 'post_name' => 'some-slug', 'post_status' => 'publish'); $one = $this->factory->post->create($args); $args = array('post_mime_type' => 'image/jpeg', 'post_type' => 'attachment', 'post_name' => 'image'); $attachment = $this->factory->attachment->create_object('image.jpg', $one, $args); $args = array('post_type' => 'post-type-1', 'post_name' => 'image', 'post_status' => 'publish', 'post_parent' => $one); $two = $this->factory->post->create($args); $this->assertEquals('some-slug', get_post($one)->post_name); $this->assertEquals('image', get_post($attachment)->post_name); $this->assertEquals('image-2', get_post($two)->post_name); // 'image' can be a child of image-2 $this->assertEquals('image', wp_unique_post_slug('image', 0, 'publish', 'post-type-1', $two)); _unregister_post_type('post-type-1'); }
function test_register_dashboard_note_post_type() { //As part of the Edit Flow initialziation process //EF_Dashboard_Notepad_Widget should have already //created the dashboard-note post type $pobj = get_post_type_object('dashboard-note'); $this->assertEquals('dashboard-note', $pobj->name); //Testing EF_Dashboard_Notepad_Widget::init explicitly _unregister_post_type('dashboard-note'); $EditFlowDashboardNote = new EF_Dashboard_Notepad_Widget(); $this->assertNull(get_post_type_object('dashboard-note')); //Should create the post type 'dashboard-note' $EditFlowDashboardNote->init(); $pobj = get_post_type_object('dashboard-note'); $this->assertEquals('dashboard-note', $pobj->name); }
public function tearDown() { _unregister_post_type($this->post_type); _unregister_taxonomy($this->taxonomy, $this->post_type); }
/** * @ticket 30018 */ function test_parse_request_home_path_non_public_type() { register_post_type('foo', array('public' => false)); $url = add_query_arg('foo', '1', home_url()); $this->go_to($url); _unregister_post_type('foo'); $this->assertEquals(array(), $GLOBALS['wp']->query_vars); }
/** * @ticket 16714 */ function test_create_posts_caps() { $author = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) ); $admin = new WP_User( $this->factory->user->create( array( 'role' => 'administrator' ) ) ); $author_2 = new WP_User( $this->factory->user->create( array( 'role' => 'author' ) ) ); $editor = new WP_User( $this->factory->user->create( array( 'role' => 'editor' ) ) ); $contributor = new WP_User( $this->factory->user->create( array( 'role' => 'contributor' ) ) ); // create_posts isn't a real cap. $this->assertFalse($admin->has_cap('create_posts')); $this->assertFalse($author->has_cap('create_posts')); $this->assertFalse($editor->has_cap('create_posts')); $this->assertFalse($author_2->has_cap('create_posts')); $this->assertFalse($contributor->has_cap('create_posts')); register_post_type( 'foobar' ); $cap = get_post_type_object( 'foobar' )->cap; $this->assertEquals( 'edit_posts', $cap->create_posts ); $this->assertTrue($admin->has_cap( $cap->create_posts )); $this->assertTrue($admin->has_cap( $cap->create_posts )); $this->assertTrue($author->has_cap( $cap->create_posts )); $this->assertTrue($editor->has_cap( $cap->create_posts )); $this->assertTrue($author_2->has_cap( $cap->create_posts )); $this->assertTrue($contributor->has_cap( $cap->create_posts )); _unregister_post_type( 'foobar' ); // Primitive capability edit_foobars is not assigned to any users. register_post_type( 'foobar', array( 'capability_type' => array( 'foobar', 'foobars' ) ) ); $cap = get_post_type_object( 'foobar' )->cap; $this->assertEquals( 'edit_foobars', $cap->create_posts ); $this->assertFalse($admin->has_cap( $cap->create_posts )); $this->assertFalse($author->has_cap( $cap->create_posts )); $this->assertFalse($editor->has_cap( $cap->create_posts )); $this->assertFalse($author_2->has_cap( $cap->create_posts )); $this->assertFalse($contributor->has_cap( $cap->create_posts )); // Add edit_foobars primitive cap to a user. $admin->add_cap( 'edit_foobars', true ); $admin = new WP_User( $admin->ID ); $this->assertTrue($admin->has_cap( $cap->create_posts )); $this->assertFalse($author->has_cap( $cap->create_posts )); $this->assertFalse($editor->has_cap( $cap->create_posts )); $this->assertFalse($author_2->has_cap( $cap->create_posts )); $this->assertFalse($contributor->has_cap( $cap->create_posts )); _unregister_post_type( 'foobar' ); $cap = get_post_type_object( 'attachment' )->cap; $this->assertEquals( 'upload_files', $cap->create_posts ); $this->assertEquals( 'edit_posts', $cap->edit_posts ); $this->assertTrue( $author->has_cap( $cap->create_posts ) ); $this->assertTrue( $author->has_cap( $cap->edit_posts ) ); $this->assertTrue( $contributor->has_cap( $cap->edit_posts ) ); $this->assertFalse( $contributor->has_cap( $cap->create_posts ) ); }
function tearDown() { _unregister_post_type( $this->post_type ); unset( $this->q ); parent::tearDown(); }
/** * @ticket 15029 */ public function test_get_ancestors_taxonomy_post_type_conflict_resource_type_taxonomy() { register_post_type('wptests_conflict', array('hierarchical' => true)); $p1 = $this->factory->post->create(array('post_type' => 'wptests_conflict')); $p2 = $this->factory->post->create(array('post_type' => 'wptests_conflict', 'post_parent' => $p1)); register_taxonomy('wptests_conflict', 'post', array('hierarchical' => true)); $t1 = $this->factory->term->create(array('taxonomy' => 'wptests_conflict')); $t2 = $this->factory->term->create(array('taxonomy' => 'wptests_conflict', 'parent' => $t1)); $this->assertEqualSets(array($p1), get_ancestors($p2, 'wptests_conflict', 'post_type')); $this->assertEqualSets(array($t1), get_ancestors($t2, 'wptests_conflict', 'taxonomy')); $this->assertEqualSets(array($t1), get_ancestors($t2, 'wptests_conflict')); _unregister_post_type('wptests_pt'); }
public function tearDown() { _unregister_post_type( 'wptests_pt' ); parent::tearDown(); }
/** * @ticket 20006 */ public function test_post_type_array() { register_post_type('post-type-1'); register_post_type('post-type-2'); $p1 = self::factory()->post->create(array('post_type' => 'post-type-1')); $p2 = self::factory()->post->create(array('post_type' => 'post-type-2')); $p3 = self::factory()->post->create(array('post_type' => 'post-type-3')); $c1 = self::factory()->comment->create_post_comments($p1, 1); $c2 = self::factory()->comment->create_post_comments($p2, 1); $c3 = self::factory()->comment->create_post_comments($p3, 1); $q = new WP_Comment_Query(); $found = $q->query(array('fields' => 'ids', 'post_type' => array('post-type-1', 'post-type-3'))); $this->assertEqualSets(array_merge($c1, $c3), $found); _unregister_post_type('post-type-1'); _unregister_post_type('post-type-2'); }
function test_wp_list_pages_classes() { $type = 'taco'; register_post_type($type, array('hierarchical' => true, 'public' => true)); $posts = $this->factory->post->create_many(2, array('post_type' => $type)); $post_id = reset($posts); $this->go_to("/?p={$post_id}&post_type={$type}"); $this->assertEquals($post_id, get_queried_object_id()); $output = wp_list_pages(array('echo' => false, 'title_li' => '', 'post_type' => $type)); $this->assertNotEmpty($output); $this->assertEquals(2, substr_count($output, 'class="page_item ')); $this->assertContains('current_page_item', $output); $this->assertEquals(1, substr_count($output, 'current_page_item')); _unregister_post_type($type); }
public function tearDown() { _unregister_post_type('youseeeme'); if (isset($this->attachment_id)) { $this->remove_added_uploads(); } parent::tearDown(); }
public function test_user_has_access_only_to_private_posts_for_certain_post_types() { register_post_type('foo', array('capabilities' => array('read_private_posts' => 'read_private_foo'))); register_post_type('bar', array('capabilities' => array('read_private_posts' => 'read_private_bar'))); register_post_type('baz', array('capabilities' => array('read_private_posts' => 'read_private_baz'))); $current_user = get_current_user_id(); $u = self::factory()->user->create(array('role' => 'editor')); $editor_role = get_role('editor'); $editor_role->add_cap('read_private_baz'); wp_set_current_user($u); $maybe_string = get_posts_by_author_sql(array('foo', 'bar', 'baz')); $editor_role->remove_cap('read_private_baz'); $this->assertNotContains("post_type = 'foo' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string); $this->assertNotContains("post_type = 'bar' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string); $this->assertContains("post_type = 'baz' AND ( post_status = 'publish' OR post_status = 'private' )", $maybe_string); _unregister_post_type('foo'); _unregister_post_type('bar'); _unregister_post_type('baz'); wp_set_current_user($current_user); }
/** * @ticket 25566 */ function test_wp_tag_cloud_link_with_post_type() { $post_type = 'new_post_type'; $tax = 'new_tag'; register_post_type( $post_type, array( 'taxonomies' => array( 'post_tag', $tax ) ) ); register_taxonomy( $tax, $post_type ); $post = $this->factory->post->create( array( 'post_type' => $post_type ) ); wp_set_object_terms( $post, rand_str(), $tax ); $wp_tag_cloud = wp_tag_cloud( array( 'post_type' => $post_type, 'taxonomy' => $tax, 'echo' => false, 'link' => 'edit' ) ); $terms = get_terms( $tax ); $term = reset( $terms ); $url = sprintf( '%s?action=edit&taxonomy=%s&tag_ID=%d&post_type=%s', admin_url( 'edit-tags.php' ), $tax, $term->term_id, $post_type ); $expected_wp_tag_cloud = sprintf( "<a href='%s' class='tag-link-%d' title='1 topic' style='font-size: 8pt;'>%s</a>", $url, $term->term_id, $term->name ); $this->assertEquals( $expected_wp_tag_cloud, $wp_tag_cloud ); _unregister_post_type( $post_type ); _unregister_taxonomy( $tax ); }
function test_post_meta_caps() { // simple tests for some common meta capabilities // Make our author $author = new WP_User($this->factory->user->create(array('role' => 'author'))); // make a post $post = $this->factory->post->create(array('post_author' => $author->ID, 'post_type' => 'post')); // the author of the post $this->assertTrue($author->exists(), "Problem getting user {$author->ID}"); // add some other users $admin = new WP_User($this->factory->user->create(array('role' => 'administrator'))); $author_2 = new WP_User($this->factory->user->create(array('role' => 'author'))); $editor = new WP_User($this->factory->user->create(array('role' => 'editor'))); $contributor = new WP_User($this->factory->user->create(array('role' => 'contributor'))); // administrators, editors and the post owner can edit it $this->assertTrue($admin->has_cap('edit_post', $post)); $this->assertTrue($author->has_cap('edit_post', $post)); $this->assertTrue($editor->has_cap('edit_post', $post)); // other authors and contributors can't $this->assertFalse($author_2->has_cap('edit_post', $post)); $this->assertFalse($contributor->has_cap('edit_post', $post)); // administrators, editors and the post owner can delete it $this->assertTrue($admin->has_cap('delete_post', $post)); $this->assertTrue($author->has_cap('delete_post', $post)); $this->assertTrue($editor->has_cap('delete_post', $post)); // other authors and contributors can't $this->assertFalse($author_2->has_cap('delete_post', $post)); $this->assertFalse($contributor->has_cap('delete_post', $post)); // administrators, editors, and authors can publish it $this->assertTrue($admin->has_cap('publish_post', $post)); $this->assertTrue($author->has_cap('publish_post', $post)); $this->assertTrue($editor->has_cap('publish_post', $post)); $this->assertTrue($author_2->has_cap('publish_post', $post)); // contributors can't $this->assertFalse($contributor->has_cap('publish_post', $post)); // administrators, editors, and authors can create posts $this->assertTrue($admin->has_cap('create_posts', 'post')); $this->assertTrue($author->has_cap('create_posts', 'post')); $this->assertTrue($editor->has_cap('create_posts', 'post')); $this->assertTrue($author_2->has_cap('create_posts', 'post')); $this->assertTrue($contributor->has_cap('create_posts', 'post')); // Defaults to post_type of post $this->assertTrue($admin->has_cap('create_posts')); $this->assertTrue($author->has_cap('create_posts')); $this->assertTrue($editor->has_cap('create_posts')); $this->assertTrue($author_2->has_cap('create_posts')); $this->assertTrue($contributor->has_cap('create_posts')); // Dummy post type $this->assertFalse($admin->has_cap('create_posts', 'foobar')); $this->assertFalse($author->has_cap('create_posts', 'foobar')); $this->assertFalse($editor->has_cap('create_posts', 'foobar')); $this->assertFalse($author_2->has_cap('create_posts', 'foobar')); $this->assertFalse($contributor->has_cap('create_posts', 'foobar')); // No longer a dummy type. Maps to primitive capability edit_posts. register_post_type('foobar'); $this->assertTrue($admin->has_cap('create_posts', 'foobar')); $this->assertTrue($author->has_cap('create_posts', 'foobar')); $this->assertTrue($editor->has_cap('create_posts', 'foobar')); $this->assertTrue($author_2->has_cap('create_posts', 'foobar')); $this->assertTrue($contributor->has_cap('create_posts', 'foobar')); // Primitive capability edit_foobars is not assigned to any users. register_post_type('foobar', array('capability_type' => array('foobar', 'foobars'))); $this->assertFalse($admin->has_cap('create_posts', 'foobar')); $this->assertFalse($author->has_cap('create_posts', 'foobar')); $this->assertFalse($editor->has_cap('create_posts', 'foobar')); $this->assertFalse($author_2->has_cap('create_posts', 'foobar')); $this->assertFalse($contributor->has_cap('create_posts', 'foobar')); // Add edit_foobars primitive cap to a user. $admin->add_cap('edit_foobars', true); $admin = new WP_User($admin->ID); $this->assertTrue($admin->has_cap('create_posts', 'foobar')); $this->assertFalse($author->has_cap('create_posts', 'foobar')); $this->assertFalse($editor->has_cap('create_posts', 'foobar')); $this->assertFalse($author_2->has_cap('create_posts', 'foobar')); $this->assertFalse($contributor->has_cap('create_posts', 'foobar')); _unregister_post_type('foobar'); register_post_type('something', array('capabilities' => array('edit_posts' => 'draw_somethings'))); $something = get_post_type_object('something'); $this->assertEquals('draw_somethings', $something->cap->edit_posts); $this->assertEquals('draw_somethings', $something->cap->create_posts); register_post_type('something', array('capabilities' => array('edit_posts' => 'draw_somethings', 'create_posts' => 'create_somethings'))); $something = get_post_type_object('something'); $this->assertEquals('draw_somethings', $something->cap->edit_posts); $this->assertEquals('create_somethings', $something->cap->create_posts); _unregister_post_type('something'); // Test meta authorization callbacks if (function_exists('register_meta')) { $this->assertTrue($admin->has_cap('edit_post_meta', $post)); $this->assertTrue($admin->has_cap('add_post_meta', $post)); $this->assertTrue($admin->has_cap('delete_post_meta', $post)); $this->assertFalse($admin->has_cap('edit_post_meta', $post, '_protected')); $this->assertFalse($admin->has_cap('add_post_meta', $post, '_protected')); $this->assertFalse($admin->has_cap('delete_post_meta', $post, '_protected')); register_meta('post', '_protected', array(&$this, '_meta_filter'), array(&$this, '_meta_yes_you_can')); $this->assertTrue($admin->has_cap('edit_post_meta', $post, '_protected')); $this->assertTrue($admin->has_cap('add_post_meta', $post, '_protected')); $this->assertTrue($admin->has_cap('delete_post_meta', $post, '_protected')); $this->assertTrue($admin->has_cap('edit_post_meta', $post, 'not_protected')); $this->assertTrue($admin->has_cap('add_post_meta', $post, 'not_protected')); $this->assertTrue($admin->has_cap('delete_post_meta', $post, 'not_protected')); register_meta('post', 'not_protected', array(&$this, '_meta_filter'), array(&$this, '_meta_no_you_cant')); $this->assertFalse($admin->has_cap('edit_post_meta', $post, 'not_protected')); $this->assertFalse($admin->has_cap('add_post_meta', $post, 'not_protected')); $this->assertFalse($admin->has_cap('delete_post_meta', $post, 'not_protected')); } }
function test_filters() { $this->make_user_by_role('editor'); $cpt_name = 'test_wp_getposts_cpt'; register_post_type($cpt_name, array('taxonomies' => array('post_tag', 'category'), 'public' => true)); $post_ids = array(); $num_posts = 4; foreach (range(1, $num_posts) as $i) { $post_ids[] = self::factory()->post->create(array('post_type' => $cpt_name, 'post_date' => date('Y-m-d H:i:s', time() + $i))); } // get them all $filter = array('post_type' => $cpt_name, 'number' => $num_posts + 10); $results = $this->myxmlrpcserver->wp_getPosts(array(1, 'editor', 'editor', $filter)); $this->assertNotInstanceOf('IXR_Error', $results); $this->assertEquals($num_posts, count($results)); // page through results $posts_found = array(); $filter['number'] = 2; $filter['offset'] = 0; do { $presults = $this->myxmlrpcserver->wp_getPosts(array(1, 'editor', 'editor', $filter)); $posts_found = array_merge($posts_found, wp_list_pluck($presults, 'post_id')); $filter['offset'] += $filter['number']; } while (count($presults) > 0); // verify that $post_ids matches $posts_found $this->assertEquals(0, count(array_diff($post_ids, $posts_found))); // add comments to some of the posts foreach ($post_ids as $key => $post_id) { // Larger post IDs will get more comments. self::factory()->comment->create_post_comments($post_id, $key); } // get results ordered by comment count $filter2 = array('post_type' => $cpt_name, 'number' => $num_posts, 'orderby' => 'comment_count', 'order' => 'DESC'); $results2 = $this->myxmlrpcserver->wp_getPosts(array(1, 'editor', 'editor', $filter2)); $this->assertNotInstanceOf('IXR_Error', $results2); $last_comment_count = 100; foreach ($results2 as $post) { $comment_count = intval(get_comments_number($post['post_id'])); $this->assertLessThanOrEqual($last_comment_count, $comment_count); $last_comment_count = $comment_count; } // set one of the posts to draft and get drafts $post = get_post($post_ids[0]); $post->post_status = 'draft'; wp_update_post($post); $filter3 = array('post_type' => $cpt_name, 'post_status' => 'draft'); $results3 = $this->myxmlrpcserver->wp_getPosts(array(1, 'editor', 'editor', $filter3)); $this->assertNotInstanceOf('IXR_Error', $results3); $this->assertEquals(1, count($results3)); $this->assertEquals($post->ID, $results3[0]['post_id']); _unregister_post_type($cpt_name); }
/** * @ticket 33665 */ function test_invalid_nav_menu_item() { $menu_id = wp_create_nav_menu('Primary'); register_post_type('poem', array('public' => true)); $post_id = self::factory()->post->create(array('post_type' => 'poem', 'post_title' => 'Code is poetry.')); $post = get_post($post_id); $item_id = wp_update_nav_menu_item($menu_id, 0, array('menu-item-type' => 'post_type', 'menu-item-object' => 'poem', 'menu-item-object-id' => $post_id, 'menu-item-title' => $post->post_title, 'menu-item-status' => 'publish', 'menu-item-position' => 1)); $setting_id = "nav_menu_item[{$item_id}]"; do_action('customize_register', $this->wp_customize); $setting = $this->wp_customize->get_setting($setting_id); $this->assertNotEmpty($setting); $value = $setting->value(); $this->assertFalse($value['_invalid']); $value_object = $setting->value_as_wp_post_nav_menu_item(); $this->assertFalse($value_object->_invalid); $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); $value = $setting->value(); $this->assertFalse($value['_invalid']); $value_object = $setting->value_as_wp_post_nav_menu_item(); $this->assertFalse($value_object->_invalid); _unregister_post_type('poem'); $setting = new WP_Customize_Nav_Menu_Item_Setting($this->wp_customize, $setting_id); $value = $setting->value(); $this->assertTrue($value['_invalid']); $value_object = $setting->value_as_wp_post_nav_menu_item(); $this->assertTrue($value_object->_invalid); }