<?php

/**
 * @group post
 */
class Tests_Query_Is_Various extends WP_UnitTestCase {

	function setUp() {
		parent::setUp();

		update_option( 'comments_per_page', 5 );
		update_option( 'posts_per_page', 5 );

		global $wp_rewrite;
		update_option( 'permalink_structure', '/%year%/%monthnum%/%day%/%postname%/' );
		create_initial_taxonomies();
		$GLOBALS['wp_rewrite']->init();
		flush_rewrite_rules();
	}

	function tearDown() {
		parent::tearDown();
		$GLOBALS['wp_rewrite']->init();
	}

	function test_query_post_and_category() {
		// Bug 21821
		global $wp_query;
		$this->assertNull( get_post_type_object( 'foo' ) );
		register_post_type( 'foo', array( 'has_archive' => true ) );

		$pobj = get_post_type_object( 'foo' );
		$this->assertInstanceOf( 'stdClass', $pobj );
		$this->assertEquals( 'foo', $pobj->name );
		$this->assertEquals( true, $pobj->has_archive );

		register_taxonomy_for_object_type( 'category', 'foo' );
		$this->assertEquals( array( 'category' ), get_object_taxonomies( 'foo' ) );

		$cat_a = $this->factory->term->create( array( 'taxonomy' => 'category', 'name' => 'cat-a' ) );
		
		$this->factory->post->create( array( 'post_type' => 'foo', 'post_title' => 'foopost', 'post_date' => '2008-12-01 00:00:00', 'post_category' => array( $cat_a ) ) );

		$this->go_to('/?post_type=foo&category_name=cat-a');

		$this->assertEquals( true, is_category() );
		$this->assertEquals( true, is_post_type_archive() );

		$this->assertNotEquals( '', wp_title( '&raquo;', false ) );

		$GLOBALS['wp_taxonomies']['category']->object_type = array( 'post' );
	}
}
