| | 533 | |
| | 534 | /** |
| | 535 | * @ticket 35227 |
| | 536 | */ |
| | 537 | public function test_unregister_taxonomy() { |
| | 538 | register_taxonomy( 'foo', 'post' ); |
| | 539 | $this->assertWPError( unregister_taxonomy( 'foo' ) ); |
| | 540 | } |
| | 541 | |
| | 542 | /** |
| | 543 | * @ticket 35227 |
| | 544 | */ |
| | 545 | public function test_unregister_taxonomy_unknown_taxonomy() { |
| | 546 | $this->assertWPError( unregister_taxonomy( 'foo' ) ); |
| | 547 | } |
| | 548 | |
| | 549 | /** |
| | 550 | * @ticket 35227 |
| | 551 | */ |
| | 552 | public function test_unregister_taxonomy_twice() { |
| | 553 | register_taxonomy( 'foo', 'post' ); |
| | 554 | $this->assertTrue( unregister_taxonomy( 'foo' ) ); |
| | 555 | $this->assertWPError( unregister_taxonomy( 'foo' ) ); |
| | 556 | } |
| | 557 | |
| | 558 | /** |
| | 559 | * @ticket 35227 |
| | 560 | */ |
| | 561 | public function test_unregister_taxonomy_disallow_builtin_taxonomy() { |
| | 562 | $this->assertWPError( unregister_taxonomy( 'post_tag' ) ); |
| | 563 | $this->assertWPError( unregister_taxonomy( 'category' ) ); |
| | 564 | } |
| | 565 | |
| | 566 | /** |
| | 567 | * @ticket 35227 |
| | 568 | */ |
| | 569 | public function test_unregister_taxonomy_removes_query_vars() { |
| | 570 | global $wp; |
| | 571 | |
| | 572 | register_taxonomy( 'foo', 'post', array( 'query_var' => 'bar' ) ); |
| | 573 | |
| | 574 | $this->assertInternalType( 'int', array_search( 'bar', $wp->public_query_vars ) ); |
| | 575 | $this->assertTrue( unregister_taxonomy( 'foo' ) ); |
| | 576 | $this->assertFalse( array_search( 'bar', $wp->public_query_vars ) ); |
| | 577 | } |
| | 578 | |
| | 579 | /** |
| | 580 | * @ticket 35227 |
| | 581 | */ |
| | 582 | public function test_unregister_taxonomy_removes_rewrite_rules() { |
| | 583 | $this->set_permalink_structure( '/%postname%' ); |
| | 584 | |
| | 585 | global $wp_rewrite; |
| | 586 | |
| | 587 | register_taxonomy( 'foo', 'post', array( 'query_var' => 'bar' ) ); |
| | 588 | |
| | 589 | $count_before = count( $wp_rewrite->rewritereplace ); |
| | 590 | |
| | 591 | $this->assertInternalType( 'int', array_search( '%foo%', $wp_rewrite->rewritecode ) ); |
| | 592 | $this->assertInternalType( 'int', array_search( 'bar=', $wp_rewrite->queryreplace ) ); |
| | 593 | $this->assertTrue( unregister_taxonomy( 'foo' ) ); |
| | 594 | $this->assertFalse( array_search( '%foo%', $wp_rewrite->rewritecode ) ); |
| | 595 | $this->assertFalse( array_search( 'bar=', $wp_rewrite->queryreplace ) ); |
| | 596 | $this->assertSame( --$count_before, count( $wp_rewrite->rewritereplace ) ); // Array was reduced by one value. |
| | 597 | } |
| | 598 | |
| | 599 | /** |
| | 600 | * @ticket 35227 |
| | 601 | */ |
| | 602 | public function test_unregister_taxonomy_removes_taxonomy_from_global() { |
| | 603 | global $wp_taxonomies; |
| | 604 | |
| | 605 | register_taxonomy( 'foo', 'post' ); |
| | 606 | |
| | 607 | $this->assertInternalType( 'object', $wp_taxonomies['foo'] ); |
| | 608 | $this->assertInternalType( 'object', get_taxonomy( 'foo' ) ); |
| | 609 | |
| | 610 | $this->assertTrue( unregister_taxonomy( 'foo' ) ); |
| | 611 | |
| | 612 | $this->assertFalse( isset( $wp_taxonomies['foo'] ) ); |
| | 613 | $this->assertFalse( get_taxonomy( 'foo' ) ); |
| | 614 | } |
| | 615 | |
| | 616 | /** |
| | 617 | * @ticket 35227 |
| | 618 | */ |
| | 619 | public function test_unregister_taxonomy_removes_meta_box_callback() { |
| | 620 | global $wp_filter; |
| | 621 | |
| | 622 | register_taxonomy( 'foo', 'post' ); |
| | 623 | |
| | 624 | $this->assertSame( 1, count( $wp_filter['wp_ajax_add-foo'] ) ); |
| | 625 | $this->assertTrue( unregister_taxonomy( 'foo' ) ); |
| | 626 | $this->assertSame( array(), $wp_filter['wp_ajax_add-foo'] ); |
| | 627 | } |