Changeset 30494 for trunk/tests/phpunit/tests/term/splitSharedTerm.php
- Timestamp:
- 11/21/2014 03:16:08 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/term/splitSharedTerm.php
r30347 r30494 5 5 */ 6 6 class Tests_Term_SplitSharedTerm extends WP_UnitTestCase { 7 protected $t t_ids = array();7 protected $terms = array(); 8 8 9 9 public function setUp() { … … 41 41 ) ); 42 42 43 $this->t t_ids = array(44 't1' => $t1 ['term_taxonomy_id'],45 't2' => $t2 ['term_taxonomy_id'],46 't3' => $t3 ['term_taxonomy_id'],47 't2_child' => $t2_child ['term_taxonomy_id'],43 $this->terms = array( 44 't1' => $t1, 45 't2' => $t2, 46 't3' => $t3, 47 't2_child' => $t2_child, 48 48 ); 49 49 … … 56 56 */ 57 57 public function test_should_create_new_term_ids() { 58 $t1_term = get_term_by( 'term_taxonomy_id', $this->t t_ids['t1'], 'wptests_tax' );59 $t2_term = get_term_by( 'term_taxonomy_id', $this->t t_ids['t2'], 'wptests_tax_2' );60 $t3_term = get_term_by( 'term_taxonomy_id', $this->t t_ids['t3'], 'wptests_tax_3' );58 $t1_term = get_term_by( 'term_taxonomy_id', $this->terms['t1']['term_taxonomy_id'], 'wptests_tax' ); 59 $t2_term = get_term_by( 'term_taxonomy_id', $this->terms['t2']['term_taxonomy_id'], 'wptests_tax_2' ); 60 $t3_term = get_term_by( 'term_taxonomy_id', $this->terms['t3']['term_taxonomy_id'], 'wptests_tax_3' ); 61 61 62 62 $this->assertNotEquals( $t1_term->term_id, $t2_term->term_id ); … … 69 69 */ 70 70 public function test_should_retain_child_terms_when_using_get_terms_parent() { 71 $t2_term = get_term_by( 'term_taxonomy_id', $this->t t_ids['t2'], 'wptests_tax_2' );71 $t2_term = get_term_by( 'term_taxonomy_id', $this->terms['t2']['term_taxonomy_id'], 'wptests_tax_2' ); 72 72 $children = get_terms( 'wptests_tax_2', array( 73 73 'parent' => $t2_term->term_id, … … 75 75 ) ); 76 76 77 $this->assertEquals( $this->t t_ids['t2_child'], $children[0]->term_taxonomy_id );77 $this->assertEquals( $this->terms['t2_child']['term_taxonomy_id'], $children[0]->term_taxonomy_id ); 78 78 } 79 79 … … 82 82 */ 83 83 public function test_should_retain_child_terms_when_using_get_terms_child_of() { 84 $t2_term = get_term_by( 'term_taxonomy_id', $this->t t_ids['t2'], 'wptests_tax_2' );84 $t2_term = get_term_by( 'term_taxonomy_id', $this->terms['t2']['term_taxonomy_id'], 'wptests_tax_2' ); 85 85 $children = get_terms( 'wptests_tax_2', array( 86 86 'child_of' => $t2_term->term_id, … … 88 88 ) ); 89 89 90 $this->assertEquals( $this->t t_ids['t2_child'], $children[0]->term_taxonomy_id );90 $this->assertEquals( $this->terms['t2_child']['term_taxonomy_id'], $children[0]->term_taxonomy_id ); 91 91 } 92 92 … … 122 122 $this->assertEquals( array( $new_term_id ), $t2_children ); 123 123 } 124 125 /** 126 * @ticket 30335 127 */ 128 public function test_should_update_default_category_on_term_split() { 129 global $wpdb; 130 $t1 = wp_insert_term( 'Foo Default', 'category' ); 131 132 update_option( 'default_category', $t1['term_id'] ); 133 134 register_taxonomy( 'wptests_tax_5', 'post' ); 135 $t2 = wp_insert_term( 'Foo Default', 'wptests_tax_5' ); 136 137 // Manually modify because split terms shouldn't naturally occur. 138 $wpdb->update( $wpdb->term_taxonomy, 139 array( 'term_id' => $t1['term_id'] ), 140 array( 'term_taxonomy_id' => $t2['term_taxonomy_id'] ), 141 array( '%d' ), 142 array( '%d' ) 143 ); 144 145 $this->assertEquals( $t1['term_id'], get_option( 'default_category', -1 ) ); 146 147 $new_term_id = _split_shared_term( $t1['term_id'], $t1['term_taxonomy_id'] ); 148 149 $this->assertNotEquals( $new_term_id, $t1['term_id'] ); 150 $this->assertEquals( $new_term_id, get_option( 'default_category', -1 ) ); 151 } 152 153 /** 154 * @ticket 30335 155 */ 156 public function test_should_update_menus_on_term_split() { 157 global $wpdb; 158 159 $t1 = wp_insert_term( 'Foo Menu', 'category' ); 160 161 register_taxonomy( 'wptests_tax_6', 'post' ); 162 $t2 = wp_insert_term( 'Foo Menu', 'wptests_tax_6' ); 163 164 // Manually modify because split terms shouldn't naturally occur. 165 $wpdb->update( $wpdb->term_taxonomy, 166 array( 'term_id' => $t1['term_id'] ), 167 array( 'term_taxonomy_id' => $t2['term_taxonomy_id'] ), 168 array( '%d' ), 169 array( '%d' ) 170 ); 171 172 $menu_id = wp_create_nav_menu( rand_str() ); 173 $cat_menu_item = wp_update_nav_menu_item( $menu_id, 0, array( 174 'menu-item-type' => 'taxonomy', 175 'menu-item-object' => 'category', 176 'menu-item-object-id' => $t1['term_id'], 177 'menu-item-status' => 'publish' 178 ) ); 179 $this->assertEquals( $t1['term_id'], get_post_meta( $cat_menu_item, '_menu_item_object_id', true ) ); 180 181 $new_term_id = _split_shared_term( $t1['term_id'], $t1['term_taxonomy_id'] ); 182 $this->assertNotEquals( $new_term_id, $t1['term_id'] ); 183 $this->assertEquals( $new_term_id, get_post_meta( $cat_menu_item, '_menu_item_object_id', true ) ); 184 } 124 185 }
Note: See TracChangeset
for help on using the changeset viewer.