public function test_url_to_postid_cpt($structure)
{
update_option($this->post_type . "_structure", $structure);
register_taxonomy($this->taxonomy, $this->post_type, array("public" => true, "rewrite" => array("slug" => rand_str(12))));
register_post_type($this->post_type, array("public" => true, 'taxonomies' => array('category')));
$user_id = $this->factory->user->create();
$id = 0;
for ($i = 0; $i < 4; $i++) {
$id = $this->factory->post->create(array('post_type' => $this->post_type, "post_author" => $user_id, "post_parent" => $id));
}
$term_id = $this->factory->term->create(array("taxonomy" => $this->taxonomy));
wp_set_post_terms($id, array($term_id), $this->taxonomy);
$cat_id = $this->factory->category->create();
wp_set_post_categories($id, array($cat_id));
do_action('wp_loaded');
/** @var WP_Rewrite $wp_rewrite */
global $wp_rewrite;
$wp_rewrite->flush_rules();
$this->assertEquals($id, url_to_postid(get_permalink($id)));
$this->go_to(get_permalink($id));
$this->assertTrue(is_single());
$this->assertEquals($this->post_type, get_post_type());
$this->factory->comment->create_post_comments($id, 15);
$this->go_to(get_permalink($id) . "comment-page-2");
$this->assertEquals(get_query_var("cpage"), 2);
}