Make WordPress Core


Ignore:
Timestamp:
09/24/2013 02:54:00 AM (13 years ago)
Author:
nacin
Message:

Introduce register_taxonomy_for_object_type().

props leewillis77.
fixes #11058.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/taxonomy.php

    r25002 r25596  
    104104                $this->assertInstanceOf( 'WP_Error', register_taxonomy( 'abcdefghijklmnopqrstuvwxyz0123456789', 'post', array() ) );
    105105        }
     106
     107        /**
     108         * @ticket 11058
     109         */
     110        function test_registering_taxonomies_to_object_types() {
     111                // Create a taxonomy to test with
     112                $tax = 'test_tax';
     113                $this->assertFalse( taxonomy_exists($tax) );
     114                register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) );
     115
     116                // Create a post type to test with
     117                $post_type = 'test_cpt';
     118                $this->assertFalse( get_post_type( $post_type ) );
     119                $this->assertObjectHasAttribute( 'name', register_post_type( $post_type ) );
     120
     121                // Core taxonomy, core post type
     122                $this->assertTrue( unregister_taxonomy_for_object_type( 'category', 'post' ) );
     123                $this->assertFalse( unregister_taxonomy_for_object_type( 'category', 'post' ) );
     124                $this->assertTrue( register_taxonomy_for_object_type( 'category', 'post' ) );
     125
     126                // Core taxonomy, non-core post type
     127                $this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) );
     128                $this->assertTrue( unregister_taxonomy_for_object_type( 'category', $post_type ) );
     129                $this->assertFalse( unregister_taxonomy_for_object_type( 'category', $post_type ) );
     130                $this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) );
     131
     132                // Core taxonomies, non-post object types
     133                $this->assertFalse( register_taxonomy_for_object_type( 'category', 'user' ) );
     134                $this->assertFalse( unregister_taxonomy_for_object_type( 'category', 'user' ) );
     135
     136                // Non-core taxonomy, core post type
     137                $this->assertTrue( unregister_taxonomy_for_object_type( $tax, 'post' ) );
     138                $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'post' ) );
     139                $this->assertTrue( register_taxonomy_for_object_type( $tax, 'post' ) );
     140
     141                // Non-core taxonomy, non-core post type
     142                $this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) );
     143                $this->assertTrue( unregister_taxonomy_for_object_type( $tax, $post_type ) );
     144                $this->assertFalse( unregister_taxonomy_for_object_type( $tax, $post_type ) );
     145                $this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) );
     146
     147                // Non-core taxonomies, non-post object types
     148                $this->assertFalse( register_taxonomy_for_object_type( $tax, 'user' ) );
     149                $this->assertFalse( unregister_taxonomy_for_object_type( $tax, 'user' ) );
     150
     151                unset($GLOBALS['wp_taxonomies'][$tax]);
     152                _unregister_post_type( $post_type );
     153
     154        }
    106155}
Note: See TracChangeset for help on using the changeset viewer.