function tearDown() {
		parent::tearDown();

		_unregister_taxonomy( 'testtax' );

		remove_action( 'pre_get_posts', array( $this, 'pre_get_posts_tax_category_tax_query' ) );
	}
 public function tearDown()
 {
     parent::tearDown();
     foreach ($this->cpts as $cpt => $cpto) {
         _unregister_post_type($cpt);
         _unregister_taxonomy("{$cpt}_category");
     }
 }
 function tearDown()
 {
     global $wp_rewrite;
     _unregister_taxonomy('testtax');
     $wp_rewrite->init();
     remove_action('pre_get_posts', array($this, 'pre_get_posts_tax_category_tax_query'));
     parent::tearDown();
 }
 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");
         }
     }
 }
 public function test_terms_contain_strings_and_ints_and_match_term_id_as_int()
 {
     register_taxonomy('wptests_tax', 'post');
     $t1 = self::factory()->term->create(array('taxonomy' => 'wptests_tax', 'slug' => 'foo'));
     $t2 = self::factory()->term->create(array('taxonomy' => 'wptests_tax', 'slug' => 'bar'));
     $posts = self::factory()->post->create_many(2);
     wp_set_object_terms($posts[0], array($t1), 'wptests_tax');
     $this->assertTrue(is_object_in_term($posts[0], 'wptests_tax', array($t1, 'bar')));
     $this->assertFalse(is_object_in_term($posts[1], 'wptests_tax', array($t1, 'bar')));
     _unregister_taxonomy('wptests_tax', 'post');
 }
Exemple #6
0
 /**
  * @ticket 14485
  */
 function test_hierachy_invalidation()
 {
     $tax = 'burrito';
     register_taxonomy($tax, 'post', array('hierarchical' => true));
     $this->assertTrue(get_taxonomy($tax)->hierarchical);
     $step = 1;
     $parent_id = 0;
     $children = 0;
     foreach (range(1, 99) as $i) {
         switch ($step) {
             case 1:
                 $parent = wp_insert_term('Parent' . $i, $tax);
                 $parent_id = $parent['term_id'];
                 break;
             case 2:
                 $parent = wp_insert_term('Child' . $i, $tax, array('parent' => $parent_id));
                 $parent_id = $parent['term_id'];
                 $children++;
                 break;
             case 3:
                 wp_insert_term('Grandchild' . $i, $tax, array('parent' => $parent_id));
                 $parent_id = 0;
                 $children++;
                 break;
         }
         $terms = get_terms($tax, array('hide_empty' => false));
         $this->assertEquals($i, count($terms));
         if ($i > 1) {
             $hierarchy = _get_term_hierarchy($tax);
             $this->assertNotEmpty($hierarchy);
             $this->assertEquals($children, count($hierarchy, COUNT_RECURSIVE) - count($hierarchy));
         }
         if ($i % 3 === 0) {
             $step = 1;
         } else {
             $step++;
         }
     }
     _unregister_taxonomy($tax);
 }
	function tearDown() {
		_unregister_taxonomy( 'test_tax_cat' );
		parent::tearDown();
	}
	/**
	 * @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 );
	}
 public function tearDown()
 {
     _unregister_post_type($this->post_type);
     _unregister_taxonomy($this->taxonomy, $this->post_type);
 }
 public function test_wp_insert_term_should_clean_term_cache()
 {
     register_taxonomy('wptests_tax', 'post', array('hierarchical' => true));
     $t = self::factory()->term->create(array('taxonomy' => 'wptests_tax'));
     /**
      * It doesn't appear that WordPress itself ever sets these
      * caches, but we should ensure that they're being cleared for
      * compatibility with third-party addons. Prime the caches
      * manually.
      */
     wp_cache_set('all_ids', array(1, 2, 3), 'wptests_tax');
     wp_cache_set('get', array(1, 2, 3), 'wptests_tax');
     $found = wp_insert_term('foo', 'wptests_tax', array('parent' => $t));
     _unregister_taxonomy('wptests_tax');
     $this->assertSame(false, wp_cache_get('all_ids', 'wptests_tax'));
     $this->assertSame(false, wp_cache_get('get', 'wptests_tax'));
     $cached_children = get_option('wptests_tax_children');
     $this->assertNotEmpty($cached_children[$t]);
     $this->assertTrue(in_array($found['term_id'], $cached_children[$t]));
 }
 /**
  * @after
  */
 public function removePostTypeTax()
 {
     _unregister_post_type('movie');
     _unregister_taxonomy('actors');
 }
	/**
	 * @group taxonomy
	 * @ticket 29738
	 */
	public function test_populate_tag_id_query_var_from_tax_query() {
		register_taxonomy( 'foo', 'post' );
		$t = $this->factory->term->create( array(
			'taxonomy' => 'foo',
		) );
		$tag = $this->factory->term->create( array(
			'taxonomy' => 'post_tag',
			'slug' => 'bar',
		) );

		$q = new WP_Query( array(
			'tax_query' => array(
				// Non-tag should be skipped
				array(
					'taxonomy' => 'foo',
					'terms' => array( $t ),
				),

				// Empty terms mean that this one should be skipped
				array(
					'taxonomy' => 'post_tag',
					'terms' => array(),
				),

				// Category and post tags should be skipped
				array(
					'taxonomy' => 'post_tag',
					'terms' => array( $tag ),
				),
			),
		) );

		$this->assertEquals( $tag, $q->get( 'tag_id' ) );

		_unregister_taxonomy( 'foo' );
	}
Exemple #13
0
 /**
  * @ticket 31364
  */
 public function test_orderby_description()
 {
     $tax = 'wptests_tax';
     register_taxonomy($tax, 'post');
     $t1 = $this->factory->term->create(array('taxonomy' => $tax, 'description' => 'fff'));
     $t2 = $this->factory->term->create(array('taxonomy' => $tax, 'description' => 'aaa'));
     $t3 = $this->factory->term->create(array('taxonomy' => $tax, 'description' => 'zzz'));
     $t4 = $this->factory->term->create(array('taxonomy' => $tax, 'description' => 'jjj'));
     $found = get_terms($tax, array('fields' => 'ids', 'orderby' => 'description', 'hide_empty' => false));
     _unregister_taxonomy('wptests_tax');
     $this->assertEquals(array($t2, $t1, $t4, $t3), $found);
 }
Exemple #14
0
 public function test_get_ancestors_taxonomy()
 {
     register_taxonomy('wptests_tax', 'post', array('hierarchical' => true));
     $t1 = $this->factory->term->create(array('taxonomy' => 'wptests_tax'));
     $t2 = $this->factory->term->create(array('taxonomy' => 'wptests_tax', 'parent' => $t1));
     $t3 = $this->factory->term->create(array('taxonomy' => 'wptests_tax', 'parent' => $t2));
     $t4 = $this->factory->term->create(array('taxonomy' => 'wptests_tax', 'parent' => $t1));
     $this->assertEqualSets(array($t2, $t1), get_ancestors($t3, 'wptests_tax'));
     _unregister_taxonomy('wptests_tax');
 }
 function test_custom_taxonomies_terms_should_not_return_a_child_before_its_parent_term()
 {
     register_taxonomy('heir', 'post', array('hierarchical' => true));
     $child_term_id = $this->factory->term->create(array('taxonomy' => 'heir'));
     $top_term_id = $this->factory->term->create(array('taxonomy' => 'heir'));
     wp_update_term($child_term_id, 'heir', array('parent' => $top_term_id));
     $export = new WP_Export_Query();
     $this->assertNoChildBeforeParent($export->custom_taxonomies_terms());
     _unregister_taxonomy('heir');
 }
Exemple #16
0
 /**
  * @ticket 29738
  */
 public function test_populate_tag_id_query_var_from_tax_query()
 {
     register_taxonomy('foo', 'post');
     $t = $this->factory->term->create(array('taxonomy' => 'foo'));
     $tag = $this->factory->term->create(array('taxonomy' => 'post_tag', 'slug' => 'bar'));
     $q = new WP_Query(array('tax_query' => array(array('taxonomy' => 'foo', 'terms' => array($t)), array('taxonomy' => 'post_tag', 'terms' => array()), array('taxonomy' => 'post_tag', 'terms' => array($tag)))));
     $this->assertEquals($tag, $q->get('tag_id'));
     _unregister_taxonomy('foo');
 }
Exemple #17
0
 /**
  * @ticket 25775
  */
 public function test_date_query_with_taxonomy_join()
 {
     $p1 = $this->factory->post->create(array('post_date' => '2013-04-27 01:01:01'));
     $p2 = $this->factory->post->create(array('post_date' => '2013-03-21 01:01:01'));
     register_taxonomy('foo', 'post');
     wp_set_object_terms($p1, 'bar', 'foo');
     $posts = $this->_get_query_result(array('date_query' => array('year' => 2013), 'tax_query' => array(array('taxonomy' => 'foo', 'terms' => array('bar'), 'field' => 'name'))));
     _unregister_taxonomy('foo');
     $this->assertEquals(array($p1), wp_list_pluck($posts, 'ID'));
 }
 public function testPrivateTaxonomyWithNoQueryVarDoesNotTriggerError()
 {
     register_taxonomy('private_taxonomy', 'post', array('public' => false, 'query_var' => true));
     register_extended_post_type('private_taxonomy');
     $this->assertTrue(post_type_exists('private_taxonomy'));
     _unregister_post_type('private_taxonomy');
     _unregister_taxonomy('private_taxonomy');
 }
 function tearDown()
 {
     parent::tearDown();
     _unregister_post_type($this->post_type);
     _unregister_taxonomy('foo');
 }
 /**
  * @ticket 29738
  */
 public function test_get_sql_operator_and_empty_terms()
 {
     register_taxonomy('wptests_tax', 'post');
     $tq = new WP_Tax_Query(array('relation' => 'OR', array('taxonomy' => 'wptests_tax', 'field' => 'term_id', 'operator' => 'AND', 'terms' => array())));
     global $wpdb;
     $expected = array('join' => '', 'where' => '');
     $this->assertSame($expected, $tq->get_sql($wpdb->posts, 'ID'));
     _unregister_taxonomy('wptests_tax');
 }
Exemple #21
0
 function test_term_exists_known()
 {
     register_taxonomy('wptests_tax', 'post');
     // insert a term
     $term = rand_str();
     $t = wp_insert_term($term, 'wptests_tax');
     $this->assertInternalType('array', $t);
     $this->assertEquals($t['term_id'], term_exists($t['term_id']));
     $this->assertEquals($t['term_id'], term_exists($term));
     // clean up
     $this->assertTrue(wp_delete_term($t['term_id'], 'wptests_tax'));
     _unregister_taxonomy('wptests_tax');
 }
 public function tearDown()
 {
     _unregister_taxonomy('batman');
     _unregister_taxonomy('robin');
     parent::tearDown();
 }
 /**
  * @ticket 30749
  */
 public function test_get_terms_should_update_cache_for_located_terms()
 {
     global $wpdb;
     register_taxonomy('wptests_tax', 'post');
     $terms = self::factory()->term->create_many(5, array('taxonomy' => 'wptests_tax'));
     $term_objects = get_terms('wptests_tax', array('hide_empty' => false));
     $num_queries = $wpdb->num_queries;
     foreach ($terms as $term_id) {
         get_term($term_id, 'wptests_tax');
     }
     $this->assertSame($num_queries, $wpdb->num_queries);
     _unregister_taxonomy('wptests_tax');
 }
	public function test_wp_set_object_terms_append_default_to_false() {
		register_taxonomy( 'wptests_tax', 'post' );
		$p = $this->factory->post->create();
		$t1 = $this->factory->term->create( array(
			'taxonomy' => 'wptests_tax',
		) );
		$t2 = $this->factory->term->create( array(
			'taxonomy' => 'wptests_tax',
		) );

		$added1 = wp_set_object_terms( $p, array( $t1 ), 'wptests_tax' );
		$this->assertNotEmpty( $added1 );
		$this->assertEqualSets( array( $t1 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );

		$added2 = wp_set_object_terms( $p, array( $t2 ), 'wptests_tax' );
		$this->assertNotEmpty( $added2 );
		$this->assertEqualSets( array( $t2 ), wp_get_object_terms( $p, 'wptests_tax', array( 'fields' => 'ids' ) ) );

		_unregister_taxonomy( 'wptests_tax' );
	}
	/**
	 * @ticket 23261
	 */
	public function test_orderby_include() {
		$tax = 'wptests_tax';
		register_taxonomy( $tax, 'post' );

		$t1 = $this->factory->term->create( array( 'taxonomy' => $tax ) );
		$t2 = $this->factory->term->create( array( 'taxonomy' => $tax ) );
		$t3 = $this->factory->term->create( array( 'taxonomy' => $tax ) );
		$t4 = $this->factory->term->create( array( 'taxonomy' => $tax ) );

		$found = get_terms( $tax, array(
			'fields' => 'ids',
			'include' => array( $t4, $t1, $t2 ),
			'orderby' => 'include',
			'hide_empty' => false,
		) );

		_unregister_taxonomy( 'wptests_tax' );

		$this->assertEquals( array( $t4, $t1, $t2 ), $found );
	}
Exemple #26
0
 /**
  * @ticket 26903
  */
 function test_get_terms_seven_levels_deep()
 {
     $tax = 'deep';
     register_taxonomy($tax, 'post', array('hierarchical' => true));
     $parent = 0;
     $t = array();
     foreach (range(1, 7) as $depth) {
         $t[$depth] = $this->factory->term->create(array('name' => 'term' . $depth, 'taxonomy' => $tax, 'parent' => $parent));
         $parent = $t[$depth];
     }
     $post_id = $this->factory->post->create();
     wp_set_post_terms($post_id, $t[7], $tax);
     $term = get_term($t[7], $tax);
     $this->assertEquals(1, $term->count);
     $terms = get_terms($tax, array('parent' => 0, 'cache_domain' => $tax));
     $this->assertEquals(1, count($terms));
     $this->assertEquals(array('term1'), wp_list_pluck($terms, 'name'));
     _unregister_taxonomy($tax);
 }
 /**
  * @ticket 30780
  */
 public function test_wp_update_term_should_not_assign_new_slug_when_reassigning_parent_as_long_as_there_is_no_other_slug_conflict_within_the_taxonomy()
 {
     register_taxonomy('wptests_tax', 'post', array('hierarchical' => true));
     register_taxonomy('wptests_tax_2', 'post', array('hierarchical' => true));
     $t1 = self::factory()->term->create(array('taxonomy' => 'wptests_tax', 'slug' => 'parent-term'));
     // Same slug but in a different tax.
     $t2 = self::factory()->term->create(array('taxonomy' => 'wptests_tax_2', 'slug' => 'foo'));
     $t3 = self::factory()->term->create(array('taxonomy' => 'wptests_tax', 'slug' => 'foo'));
     wp_update_term($t3, 'wptests_tax', array('parent' => $t1));
     $t3_term = get_term($t3, 'wptests_tax');
     $this->assertSame('foo', $t3_term->slug);
     _unregister_taxonomy('wptests_tax');
 }
Exemple #28
0
 /**
  * Unregister existing taxonomies and register defaults.
  *
  * Run before each test in order to clean up the global scope, in case
  * a test forgets to unregister a taxonomy on its own, or fails before
  * it has a chance to do so.
  */
 protected function reset_taxonomies()
 {
     foreach (get_taxonomies() as $tax) {
         _unregister_taxonomy($tax);
     }
     create_initial_taxonomies();
 }
 /**
  * @ticket 34533
  */
 public function test_term_should_be_returned_when_id_is_shared_only_with_invalid_taxonomies()
 {
     $terms = $this->generate_shared_terms();
     _unregister_taxonomy('wptests_tax');
     $found = get_term($terms[1]['term_id']);
     $this->assertInstanceOf('WP_Term', $found);
     $this->assertSame('wptests_tax_2', $found->taxonomy);
     $this->assertSame($terms[1]['term_id'], $found->term_id);
 }