| | 106 | |
| | 107 | function test_registering_taxonomies_to_object_types() { |
| | 108 | |
| | 109 | // Create a taonomy to test with |
| | 110 | $tax = rand_str(10); |
| | 111 | $this->assertFalse( taxonomy_exists($tax) ); |
| | 112 | register_taxonomy( $tax, 'post', array( 'hierarchical' => true ) ); |
| | 113 | |
| | 114 | // Create a post type to test with |
| | 115 | $post_type = rand_str(10); |
| | 116 | $this->assertFalse( get_post_type( $post_type ) ); |
| | 117 | $this->assertObjectHasAttribute( 'name', register_post_type( $post_type ) ); |
| | 118 | |
| | 119 | // Core taxonomy, core post type |
| | 120 | $this->assertTrue( unregister_taxonomy_from_object_type( 'category', 'post' ) ); |
| | 121 | $this->assertFalse( unregister_taxonomy_from_object_type( 'category', 'post' ) ); |
| | 122 | $this->assertTrue( register_taxonomy_for_object_type( 'category', 'post' ) ); |
| | 123 | |
| | 124 | // Core taxonomy, non-core post type |
| | 125 | $this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) ); |
| | 126 | $this->assertTrue( unregister_taxonomy_from_object_type( 'category', $post_type ) ); |
| | 127 | $this->assertFalse( unregister_taxonomy_from_object_type( 'category', $post_type ) ); |
| | 128 | $this->assertTrue( register_taxonomy_for_object_type( 'category', $post_type ) ); |
| | 129 | |
| | 130 | // Core taxonomies, non-post object types |
| | 131 | $this->assertFalse( register_taxonomy_for_object_type( 'category', 'user' ) ); |
| | 132 | $this->assertFalse( unregister_taxonomy_from_object_type( 'category', 'user' ) ); |
| | 133 | |
| | 134 | // Non-core taxonomy, core post type |
| | 135 | $this->assertTrue( unregister_taxonomy_from_object_type( $tax, 'post' ) ); |
| | 136 | $this->assertFalse( unregister_taxonomy_from_object_type( $tax, 'post' ) ); |
| | 137 | $this->assertTrue( register_taxonomy_for_object_type( $tax, 'post' ) ); |
| | 138 | |
| | 139 | // Non-core taxonomy, non-core post type |
| | 140 | $this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) ); |
| | 141 | $this->assertTrue( unregister_taxonomy_from_object_type( $tax, $post_type ) ); |
| | 142 | $this->assertFalse( unregister_taxonomy_from_object_type( $tax, $post_type ) ); |
| | 143 | $this->assertTrue( register_taxonomy_for_object_type( $tax, $post_type ) ); |
| | 144 | |
| | 145 | // Non-core taxonomies, non-post object types |
| | 146 | $this->assertFalse( register_taxonomy_for_object_type( $tax, 'user' ) ); |
| | 147 | $this->assertFalse( unregister_taxonomy_from_object_type( $tax, 'user' ) ); |
| | 148 | |
| | 149 | unset($GLOBALS['wp_taxonomies'][$tax]); |
| | 150 | _unregister_post_type( $post_type ); |
| | 151 | |
| | 152 | } |