<?php

class Test_Draft_Child_URL extends WP_UnitTestCase {

	public function setUp() {

		parent::setUp();

		global $wp_rewrite;
		$wp_rewrite->set_permalink_structure('/%postname%/');

		// Set up custom post type - 'test'
		$args = array( 'hierarchical' => true, 'public' => true );
		register_post_type( 'test', $args );

	}

	public function test_draft_child_post_link() {
		$draft = $this->factory->post->create(array('post_type' => 'test', 'post_status' => 'draft'));
		$public_draft_child = $this->factory->post->create(array('post_type' => 'test', 'post_status' => 'publish', 'post_parent' => $draft));

		$public_draft_child = get_post( $public_draft_child );

		$permalink = get_post_permalink( $public_draft_child );
		$expected = 'http://example.org/test/post-title-1/';

		$this->assertEquals( $expected, $permalink );
	}
}
