- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/customize/nav-menu-item-setting.php
r41697 r42343 26 26 global $wp_customize; 27 27 $this->wp_customize = new WP_Customize_Manager(); 28 $wp_customize = $this->wp_customize;28 $wp_customize = $this->wp_customize; 29 29 } 30 30 … … 77 77 78 78 $default = array( 79 'object_id' => 0,80 'object' => '',79 'object_id' => 0, 80 'object' => '', 81 81 'menu_item_parent' => 0, 82 'position' => 0,83 'type' => 'custom',84 'title' => '',85 'url' => '',86 'target' => '',87 'attr_title' => '',88 'description' => '',89 'classes' => '',90 'xfn' => '',91 'status' => 'publish',92 'original_title' => '',82 'position' => 0, 83 'type' => 'custom', 84 'title' => '', 85 'url' => '', 86 'target' => '', 87 'attr_title' => '', 88 'description' => '', 89 'classes' => '', 90 'xfn' => '', 91 'status' => 'publish', 92 'original_title' => '', 93 93 'nav_menu_term_id' => 0, 94 '_invalid' => false,94 '_invalid' => false, 95 95 ); 96 96 $this->assertEquals( $default, $setting->default ); … … 112 112 do_action( 'customize_register', $this->wp_customize ); 113 113 $_wp_customize = $this->wp_customize; 114 unset( $_wp_customize->nav_menus);114 unset( $_wp_customize->nav_menus ); 115 115 116 116 $exception = null; … … 132 132 do_action( 'customize_register', $this->wp_customize ); 133 133 $default = array( 134 'title' => 'Lorem',135 'description' => 'ipsum',134 'title' => 'Lorem', 135 'description' => 'ipsum', 136 136 'menu_item_parent' => 123, 137 137 ); … … 152 152 $post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) ); 153 153 154 $menu_id = wp_create_nav_menu( 'Menu' );154 $menu_id = wp_create_nav_menu( 'Menu' ); 155 155 $item_title = 'Greetings'; 156 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 157 'menu-item-type' => 'post_type', 158 'menu-item-object' => 'post', 159 'menu-item-object-id' => $post_id, 160 'menu-item-title' => $item_title, 161 'menu-item-status' => 'publish', 162 ) ); 163 164 $post = get_post( $item_id ); 156 $item_id = wp_update_nav_menu_item( 157 $menu_id, 0, array( 158 'menu-item-type' => 'post_type', 159 'menu-item-object' => 'post', 160 'menu-item-object-id' => $post_id, 161 'menu-item-title' => $item_title, 162 'menu-item-status' => 'publish', 163 ) 164 ); 165 166 $post = get_post( $item_id ); 165 167 $menu_item = wp_setup_nav_menu_item( $post ); 166 168 $this->assertEquals( $item_title, $menu_item->title ); 167 169 168 170 $setting_id = "nav_menu_item[$item_id]"; 169 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );171 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 170 172 171 173 $value = $setting->value(); … … 177 179 178 180 $other_menu_id = wp_create_nav_menu( 'Menu2' ); 179 wp_update_nav_menu_item( $other_menu_id, $item_id, array( 180 'menu-item-title' => 'Hola', 181 ) ); 181 wp_update_nav_menu_item( 182 $other_menu_id, $item_id, array( 183 'menu-item-title' => 'Hola', 184 ) 185 ); 182 186 $value = $setting->value(); 183 187 $this->assertEquals( 'Hola', $value['title'] ); … … 194 198 195 199 $original_title = 'Hello World'; 196 $post_id = self::factory()->post->create( array( 'post_title' => $original_title ) );200 $post_id = self::factory()->post->create( array( 'post_title' => $original_title ) ); 197 201 198 202 $menu_id = wp_create_nav_menu( 'Menu' ); 199 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 200 'menu-item-type' => 'post_type', 201 'menu-item-object' => 'post', 202 'menu-item-object-id' => $post_id, 203 'menu-item-title' => '', 204 'menu-item-status' => 'publish', 205 ) ); 203 $item_id = wp_update_nav_menu_item( 204 $menu_id, 0, array( 205 'menu-item-type' => 'post_type', 206 'menu-item-object' => 'post', 207 'menu-item-object-id' => $post_id, 208 'menu-item-title' => '', 209 'menu-item-status' => 'publish', 210 ) 211 ); 206 212 207 213 $setting_id = "nav_menu_item[$item_id]"; 208 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );214 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 209 215 210 216 $value = $setting->value(); … … 223 229 $tax_id = self::factory()->category->create( array( 'name' => 'Salutations' ) ); 224 230 225 $menu_id = wp_create_nav_menu( 'Menu' );231 $menu_id = wp_create_nav_menu( 'Menu' ); 226 232 $item_title = 'Greetings'; 227 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 228 'menu-item-type' => 'taxonomy', 229 'menu-item-object' => 'category', 230 'menu-item-object-id' => $tax_id, 231 'menu-item-title' => $item_title, 232 'menu-item-status' => 'publish', 233 ) ); 234 235 $post = get_post( $item_id ); 233 $item_id = wp_update_nav_menu_item( 234 $menu_id, 0, array( 235 'menu-item-type' => 'taxonomy', 236 'menu-item-object' => 'category', 237 'menu-item-object-id' => $tax_id, 238 'menu-item-title' => $item_title, 239 'menu-item-status' => 'publish', 240 ) 241 ); 242 243 $post = get_post( $item_id ); 236 244 $menu_item = wp_setup_nav_menu_item( $post ); 237 245 $this->assertEquals( $item_title, $menu_item->title ); 238 246 239 247 $setting_id = "nav_menu_item[$item_id]"; 240 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );248 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 241 249 242 250 $value = $setting->value(); … … 258 266 259 267 $menu_id = wp_create_nav_menu( 'Menu' ); 260 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 261 'menu-item-type' => 'custom_type', 262 'menu-item-object' => 'custom_object', 263 'menu-item-title' => 'Cool beans', 264 'menu-item-status' => 'publish', 265 ) ); 266 267 $post = get_post( $item_id ); 268 $item_id = wp_update_nav_menu_item( 269 $menu_id, 0, array( 270 'menu-item-type' => 'custom_type', 271 'menu-item-object' => 'custom_object', 272 'menu-item-title' => 'Cool beans', 273 'menu-item-status' => 'publish', 274 ) 275 ); 276 277 $post = get_post( $item_id ); 268 278 $menu_item = wp_setup_nav_menu_item( $post ); 269 279 270 280 $setting_id = "nav_menu_item[$item_id]"; 271 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );281 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 272 282 273 283 $value = $setting->value(); … … 284 294 do_action( 'customize_register', $this->wp_customize ); 285 295 286 $menu_id = -123;296 $menu_id = -123; 287 297 $post_value = array( 288 'name' => 'Secondary',298 'name' => 'Secondary', 289 299 'description' => '', 290 'parent' => 0,291 'auto_add' => false,300 'parent' => 0, 301 'auto_add' => false, 292 302 ); 293 303 $setting_id = "nav_menu[$menu_id]"; 294 $menu = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id );304 $menu = new WP_Customize_Nav_Menu_Setting( $this->wp_customize, $setting_id ); 295 305 296 306 $this->wp_customize->set_post_value( $menu->id, $post_value ); … … 300 310 301 311 $post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) ); 302 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 303 'menu-item-type' => 'post_type', 304 'menu-item-object' => 'post', 305 'menu-item-object-id' => $post_id, 306 'menu-item-title' => 'Hello World', 307 'menu-item-status' => 'publish', 308 ) ); 309 310 $post = get_post( $item_id ); 312 $item_id = wp_update_nav_menu_item( 313 $menu_id, 0, array( 314 'menu-item-type' => 'post_type', 315 'menu-item-object' => 'post', 316 'menu-item-object-id' => $post_id, 317 'menu-item-title' => 'Hello World', 318 'menu-item-status' => 'publish', 319 ) 320 ); 321 322 $post = get_post( $item_id ); 311 323 $menu_item = wp_setup_nav_menu_item( $post ); 312 324 313 325 $setting_id = "nav_menu_item[$item_id]"; 314 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );315 $value = $setting->value();326 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 327 $value = $setting->value(); 316 328 $this->assertEquals( 0, $value['nav_menu_term_id'] ); 317 329 } … … 325 337 do_action( 'customize_register', $this->wp_customize ); 326 338 327 $first_post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) );339 $first_post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) ); 328 340 $second_post_id = self::factory()->post->create( array( 'post_title' => 'Hola Muno' ) ); 329 341 330 $primary_menu_id = wp_create_nav_menu( 'Primary' );342 $primary_menu_id = wp_create_nav_menu( 'Primary' ); 331 343 $secondary_menu_id = wp_create_nav_menu( 'Secondary' ); 332 $item_title = 'Greetings'; 333 $item_id = wp_update_nav_menu_item( $primary_menu_id, 0, array( 334 'menu-item-type' => 'post_type', 335 'menu-item-object' => 'post', 336 'menu-item-object-id' => $first_post_id, 337 'menu-item-title' => $item_title, 338 'menu-item-status' => 'publish', 339 ) ); 344 $item_title = 'Greetings'; 345 $item_id = wp_update_nav_menu_item( 346 $primary_menu_id, 0, array( 347 'menu-item-type' => 'post_type', 348 'menu-item-object' => 'post', 349 'menu-item-object-id' => $first_post_id, 350 'menu-item-title' => $item_title, 351 'menu-item-status' => 'publish', 352 ) 353 ); 340 354 $this->assertNotEmpty( wp_get_nav_menu_items( $primary_menu_id, array( 'post_status' => 'publish,draft' ) ) ); 341 355 342 356 $post_value = array( 343 'type' => 'post_type',344 'object' => 'post',345 'object_id' => $second_post_id,346 'title' => 'Saludos',347 'status' => 'publish',357 'type' => 'post_type', 358 'object' => 'post', 359 'object_id' => $second_post_id, 360 'title' => 'Saludos', 361 'status' => 'publish', 348 362 'nav_menu_term_id' => $secondary_menu_id, 349 363 ); 350 364 $setting_id = "nav_menu_item[$item_id]"; 351 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );365 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 352 366 $this->wp_customize->set_post_value( $setting_id, $post_value ); 353 367 unset( $post_value['nav_menu_term_id'] ); … … 357 371 $this->assertNotContains( $item_id, wp_list_pluck( wp_get_nav_menu_items( $primary_menu_id ), 'db_id' ) ); 358 372 $menu_items = wp_get_nav_menu_items( $secondary_menu_id ); 359 $db_ids = wp_list_pluck( $menu_items, 'db_id' );373 $db_ids = wp_list_pluck( $menu_items, 'db_id' ); 360 374 $this->assertContains( $item_id, $db_ids ); 361 $i = array_search( $item_id, $db_ids );362 $updated_item = $menu_items[ $i ];375 $i = array_search( $item_id, $db_ids ); 376 $updated_item = $menu_items[ $i ]; 363 377 $post_value['post_status'] = $post_value['status']; 364 378 unset( $post_value['status'] ); … … 376 390 do_action( 'customize_register', $this->wp_customize ); 377 391 378 $menu_id = wp_create_nav_menu( 'Primary' );379 $post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) );392 $menu_id = wp_create_nav_menu( 'Primary' ); 393 $post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) ); 380 394 $item_ids = array(); 381 395 for ( $i = 0; $i < 5; $i += 1 ) { 382 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 383 'menu-item-type' => 'post_type', 384 'menu-item-object' => 'post', 385 'menu-item-object-id' => $post_id, 386 'menu-item-title' => "Item $i", 387 'menu-item-status' => 'publish', 388 'menu-item-position' => $i + 1, 389 ) ); 396 $item_id = wp_update_nav_menu_item( 397 $menu_id, 0, array( 398 'menu-item-type' => 'post_type', 399 'menu-item-object' => 'post', 400 'menu-item-object-id' => $post_id, 401 'menu-item-title' => "Item $i", 402 'menu-item-status' => 'publish', 403 'menu-item-position' => $i + 1, 404 ) 405 ); 390 406 $item_ids[] = $item_id; 391 407 } 392 408 393 409 $post_value = array( 394 'type' => 'post_type',395 'object' => 'post',396 'object_id' => $post_id,397 'title' => 'Inserted item',398 'status' => 'publish',410 'type' => 'post_type', 411 'object' => 'post', 412 'object_id' => $post_id, 413 'title' => 'Inserted item', 414 'status' => 'publish', 399 415 'nav_menu_term_id' => $menu_id, 400 'position' => count( $item_ids ) + 1,416 'position' => count( $item_ids ) + 1, 401 417 ); 402 418 403 419 $new_item_id = -10; 404 $setting_id = "nav_menu_item[$new_item_id]";405 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );420 $setting_id = "nav_menu_item[$new_item_id]"; 421 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 406 422 $this->wp_customize->set_post_value( $setting_id, $post_value ); 407 423 unset( $post_value['nav_menu_term_id'] ); … … 431 447 do_action( 'customize_register', $this->wp_customize ); 432 448 433 $menu_id = wp_create_nav_menu( 'Primary' );434 $post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) );449 $menu_id = wp_create_nav_menu( 'Primary' ); 450 $post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) ); 435 451 $item_ids = array(); 436 452 for ( $i = 0; $i < 5; $i += 1 ) { 437 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 438 'menu-item-type' => 'post_type', 439 'menu-item-object' => 'post', 440 'menu-item-object-id' => $post_id, 441 'menu-item-title' => "Item $i", 442 'menu-item-status' => 'publish', 443 'menu-item-position' => $i + 1, 444 ) ); 453 $item_id = wp_update_nav_menu_item( 454 $menu_id, 0, array( 455 'menu-item-type' => 'post_type', 456 'menu-item-object' => 'post', 457 'menu-item-object-id' => $post_id, 458 'menu-item-title' => "Item $i", 459 'menu-item-status' => 'publish', 460 'menu-item-position' => $i + 1, 461 ) 462 ); 445 463 $item_ids[] = $item_id; 446 464 } 447 465 448 466 $delete_item_id = $item_ids[2]; 449 $setting_id = "nav_menu_item[$delete_item_id]";450 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );467 $setting_id = "nav_menu_item[$delete_item_id]"; 468 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 451 469 $this->wp_customize->set_post_value( $setting_id, false ); 452 470 … … 512 530 513 531 $unsanitized = array( 514 'object_id' => 'bad',515 'object' => '<b>hello</b>',532 'object_id' => 'bad', 533 'object' => '<b>hello</b>', 516 534 'menu_item_parent' => 'asdasd', 517 'position' => -123,518 'type' => 'custom<b>',519 'title' => '\o/ o\'o Hi<script>unfilteredHtml()</script>',520 'url' => '', // Note the javascript: protocol is checked above and results in a hard validation error, beyond mere sanitization.521 'target' => '" onclick="',522 'attr_title' => '\o/ o\'o <b>bolded</b><script>unfilteredHtml()</script>',523 'description' => '\o/ o\'o <b>Hello world</b><script>unfilteredHtml()</script>',524 'classes' => 'hello " inject="',525 'xfn' => 'hello " inject="',526 'status' => 'forbidden',527 'original_title' => 'Hi<script>unfilteredHtml()</script>',535 'position' => -123, 536 'type' => 'custom<b>', 537 'title' => '\o/ o\'o Hi<script>unfilteredHtml()</script>', 538 'url' => '', // Note the javascript: protocol is checked above and results in a hard validation error, beyond mere sanitization. 539 'target' => '" onclick="', 540 'attr_title' => '\o/ o\'o <b>bolded</b><script>unfilteredHtml()</script>', 541 'description' => '\o/ o\'o <b>Hello world</b><script>unfilteredHtml()</script>', 542 'classes' => 'hello " inject="', 543 'xfn' => 'hello " inject="', 544 'status' => 'forbidden', 545 'original_title' => 'Hi<script>unfilteredHtml()</script>', 528 546 'nav_menu_term_id' => 'heilo', 529 '_invalid' => false,547 '_invalid' => false, 530 548 ); 531 549 532 550 $expected_sanitized = array( 533 'object_id' => 0,534 'object' => 'bhellob',551 'object_id' => 0, 552 'object' => 'bhellob', 535 553 'menu_item_parent' => 0, 536 'position' => -123,537 'type' => 'customb',538 'title' => current_user_can( 'unfiltered_html' ) ? '\o/ o\'o Hi<script>unfilteredHtml()</script>' : '\o/ o\'o HiunfilteredHtml()',539 'url' => '',540 'target' => 'onclick',541 'attr_title' => current_user_can( 'unfiltered_html' ) ? '\o/ o\'o <b>bolded</b><script>unfilteredHtml()</script>' : '\o/ o\'o <b>bolded</b>unfilteredHtml()',542 'description' => current_user_can( 'unfiltered_html' ) ? '\o/ o\'o <b>Hello world</b><script>unfilteredHtml()</script>' : '\o/ o\'o <b>Hello world</b>unfilteredHtml()',543 'classes' => 'hello inject',544 'xfn' => 'hello inject',545 'status' => 'draft',546 'original_title' => 'Hi',554 'position' => -123, 555 'type' => 'customb', 556 'title' => current_user_can( 'unfiltered_html' ) ? '\o/ o\'o Hi<script>unfilteredHtml()</script>' : '\o/ o\'o HiunfilteredHtml()', 557 'url' => '', 558 'target' => 'onclick', 559 'attr_title' => current_user_can( 'unfiltered_html' ) ? '\o/ o\'o <b>bolded</b><script>unfilteredHtml()</script>' : '\o/ o\'o <b>bolded</b>unfilteredHtml()', 560 'description' => current_user_can( 'unfiltered_html' ) ? '\o/ o\'o <b>Hello world</b><script>unfilteredHtml()</script>' : '\o/ o\'o <b>Hello world</b>unfilteredHtml()', 561 'classes' => 'hello inject', 562 'xfn' => 'hello inject', 563 'status' => 'draft', 564 'original_title' => 'Hi', 547 565 'nav_menu_term_id' => 0, 548 566 ); … … 555 573 } 556 574 557 $nav_menu_item_id = wp_update_nav_menu_item( $menu_id, 0, wp_slash( array( 558 'menu-item-object-id' => $unsanitized['object_id'], 559 'menu-item-object' => $unsanitized['object'], 560 'menu-item-parent-id' => $unsanitized['menu_item_parent'], 561 'menu-item-position' => $unsanitized['position'], 562 'menu-item-type' => $unsanitized['type'], 563 'menu-item-title' => $unsanitized['title'], 564 'menu-item-url' => $unsanitized['url'], 565 'menu-item-description' => $unsanitized['description'], 566 'menu-item-attr-title' => $unsanitized['attr_title'], 567 'menu-item-target' => $unsanitized['target'], 568 'menu-item-classes' => $unsanitized['classes'], 569 'menu-item-xfn' => $unsanitized['xfn'], 570 'menu-item-status' => $unsanitized['status'], 571 ) ) ); 572 573 $post = get_post( $nav_menu_item_id ); 575 $nav_menu_item_id = wp_update_nav_menu_item( 576 $menu_id, 0, wp_slash( 577 array( 578 'menu-item-object-id' => $unsanitized['object_id'], 579 'menu-item-object' => $unsanitized['object'], 580 'menu-item-parent-id' => $unsanitized['menu_item_parent'], 581 'menu-item-position' => $unsanitized['position'], 582 'menu-item-type' => $unsanitized['type'], 583 'menu-item-title' => $unsanitized['title'], 584 'menu-item-url' => $unsanitized['url'], 585 'menu-item-description' => $unsanitized['description'], 586 'menu-item-attr-title' => $unsanitized['attr_title'], 587 'menu-item-target' => $unsanitized['target'], 588 'menu-item-classes' => $unsanitized['classes'], 589 'menu-item-xfn' => $unsanitized['xfn'], 590 'menu-item-status' => $unsanitized['status'], 591 ) 592 ) 593 ); 594 595 $post = get_post( $nav_menu_item_id ); 574 596 $nav_menu_item = wp_setup_nav_menu_item( clone $post ); 575 597 … … 597 619 do_action( 'customize_register', $this->wp_customize ); 598 620 599 $first_post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) );621 $first_post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) ); 600 622 $second_post_id = self::factory()->post->create( array( 'post_title' => 'Hola Muno' ) ); 601 623 602 $primary_menu_id = wp_create_nav_menu( 'Primary' );624 $primary_menu_id = wp_create_nav_menu( 'Primary' ); 603 625 $secondary_menu_id = wp_create_nav_menu( 'Secondary' ); 604 $item_title = 'Greetings'; 605 $item_id = wp_update_nav_menu_item( $primary_menu_id, 0, array( 606 'menu-item-type' => 'post_type', 607 'menu-item-object' => 'post', 608 'menu-item-object-id' => $first_post_id, 609 'menu-item-title' => $item_title, 610 'menu-item-status' => 'publish', 611 ) ); 626 $item_title = 'Greetings'; 627 $item_id = wp_update_nav_menu_item( 628 $primary_menu_id, 0, array( 629 'menu-item-type' => 'post_type', 630 'menu-item-object' => 'post', 631 'menu-item-object-id' => $first_post_id, 632 'menu-item-title' => $item_title, 633 'menu-item-status' => 'publish', 634 ) 635 ); 612 636 $this->assertNotEmpty( wp_get_nav_menu_items( $primary_menu_id, array( 'post_status' => 'publish,draft' ) ) ); 613 637 614 638 $post_value = array( 615 'type' => 'post_type',616 'object' => 'post',617 'object_id' => $second_post_id,618 'title' => 'Saludos \o/ o\'o',619 'status' => 'publish',639 'type' => 'post_type', 640 'object' => 'post', 641 'object_id' => $second_post_id, 642 'title' => 'Saludos \o/ o\'o', 643 'status' => 'publish', 620 644 'nav_menu_term_id' => $secondary_menu_id, 621 645 ); 622 646 $setting_id = "nav_menu_item[$item_id]"; 623 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );647 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 624 648 $this->wp_customize->set_post_value( $setting_id, $post_value ); 625 649 unset( $post_value['nav_menu_term_id'] ); … … 629 653 $this->assertNotContains( $item_id, wp_list_pluck( wp_get_nav_menu_items( $primary_menu_id ), 'db_id' ) ); 630 654 $menu_items = wp_get_nav_menu_items( $secondary_menu_id ); 631 $db_ids = wp_list_pluck( $menu_items, 'db_id' );655 $db_ids = wp_list_pluck( $menu_items, 'db_id' ); 632 656 $this->assertContains( $item_id, $db_ids ); 633 $i = array_search( $item_id, $db_ids );634 $updated_item = $menu_items[ $i ];657 $i = array_search( $item_id, $db_ids ); 658 $updated_item = $menu_items[ $i ]; 635 659 $post_value['post_status'] = $post_value['status']; 636 660 unset( $post_value['status'] ); … … 662 686 do_action( 'customize_register', $this->wp_customize ); 663 687 664 $menu_id = wp_create_nav_menu( 'Primary' );665 $post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) );688 $menu_id = wp_create_nav_menu( 'Primary' ); 689 $post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) ); 666 690 $item_ids = array(); 667 691 for ( $i = 0; $i < 5; $i += 1 ) { 668 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 669 'menu-item-type' => 'post_type', 670 'menu-item-object' => 'post', 671 'menu-item-object-id' => $post_id, 672 'menu-item-title' => "Item $i", 673 'menu-item-status' => 'publish', 674 'menu-item-position' => $i + 1, 675 ) ); 692 $item_id = wp_update_nav_menu_item( 693 $menu_id, 0, array( 694 'menu-item-type' => 'post_type', 695 'menu-item-object' => 'post', 696 'menu-item-object-id' => $post_id, 697 'menu-item-title' => "Item $i", 698 'menu-item-status' => 'publish', 699 'menu-item-position' => $i + 1, 700 ) 701 ); 676 702 $item_ids[] = $item_id; 677 703 } 678 704 679 705 $post_value = array( 680 'type' => 'post_type',681 'object' => 'post',682 'object_id' => $post_id,683 'title' => 'Inserted item',684 'status' => 'publish',706 'type' => 'post_type', 707 'object' => 'post', 708 'object_id' => $post_id, 709 'title' => 'Inserted item', 710 'status' => 'publish', 685 711 'nav_menu_term_id' => $menu_id, 686 'position' => count( $item_ids ) + 1,712 'position' => count( $item_ids ) + 1, 687 713 ); 688 714 689 715 $new_item_id = -10; 690 $setting_id = "nav_menu_item[$new_item_id]";691 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );716 $setting_id = "nav_menu_item[$new_item_id]"; 717 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 692 718 $this->wp_customize->set_post_value( $setting_id, $post_value ); 693 719 unset( $post_value['nav_menu_term_id'] ); … … 731 757 do_action( 'customize_register', $this->wp_customize ); 732 758 733 $menu_id = wp_create_nav_menu( 'Primary' );734 $post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) );759 $menu_id = wp_create_nav_menu( 'Primary' ); 760 $post_id = self::factory()->post->create( array( 'post_title' => 'Hello World' ) ); 735 761 $item_ids = array(); 736 762 for ( $i = 0; $i < 5; $i += 1 ) { 737 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 738 'menu-item-type' => 'post_type', 739 'menu-item-object' => 'post', 740 'menu-item-object-id' => $post_id, 741 'menu-item-title' => "Item $i", 742 'menu-item-status' => 'publish', 743 'menu-item-position' => $i + 1, 744 ) ); 763 $item_id = wp_update_nav_menu_item( 764 $menu_id, 0, array( 765 'menu-item-type' => 'post_type', 766 'menu-item-object' => 'post', 767 'menu-item-object-id' => $post_id, 768 'menu-item-title' => "Item $i", 769 'menu-item-status' => 'publish', 770 'menu-item-position' => $i + 1, 771 ) 772 ); 745 773 $item_ids[] = $item_id; 746 774 } 747 775 748 776 $delete_item_id = $item_ids[2]; 749 $setting_id = "nav_menu_item[$delete_item_id]";750 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id );777 $setting_id = "nav_menu_item[$delete_item_id]"; 778 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 751 779 $this->wp_customize->set_post_value( $setting_id, false ); 752 780 … … 778 806 function test_invalid_nav_menu_item() { 779 807 $menu_id = wp_create_nav_menu( 'Primary' ); 780 register_post_type( 'poem', array( 781 'public' => true, 782 ) ); 783 784 $post_id = self::factory()->post->create( array( 'post_type' => 'poem', 'post_title' => 'Code is poetry.' ) ); 785 $post = get_post( $post_id ); 786 $item_id = wp_update_nav_menu_item( $menu_id, 0, array( 787 'menu-item-type' => 'post_type', 788 'menu-item-object' => 'poem', 789 'menu-item-object-id' => $post_id, 790 'menu-item-title' => $post->post_title, 791 'menu-item-status' => 'publish', 792 'menu-item-position' => 1, 793 ) ); 808 register_post_type( 809 'poem', array( 810 'public' => true, 811 ) 812 ); 813 814 $post_id = self::factory()->post->create( 815 array( 816 'post_type' => 'poem', 817 'post_title' => 'Code is poetry.', 818 ) 819 ); 820 $post = get_post( $post_id ); 821 $item_id = wp_update_nav_menu_item( 822 $menu_id, 0, array( 823 'menu-item-type' => 'post_type', 824 'menu-item-object' => 'poem', 825 'menu-item-object-id' => $post_id, 826 'menu-item-title' => $post->post_title, 827 'menu-item-status' => 'publish', 828 'menu-item-position' => 1, 829 ) 830 ); 794 831 $setting_id = "nav_menu_item[$item_id]"; 795 832 … … 803 840 804 841 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 805 $value = $setting->value();842 $value = $setting->value(); 806 843 $this->assertFalse( $value['_invalid'] ); 807 844 $value_object = $setting->value_as_wp_post_nav_menu_item(); … … 810 847 _unregister_post_type( 'poem' ); 811 848 $setting = new WP_Customize_Nav_Menu_Item_Setting( $this->wp_customize, $setting_id ); 812 $value = $setting->value();849 $value = $setting->value(); 813 850 $this->assertTrue( $value['_invalid'] ); 814 851 $value_object = $setting->value_as_wp_post_nav_menu_item(); … … 824 861 $post_id = self::factory()->post->create(); 825 862 826 $setting = new WP_Customize_Nav_Menu_Item_Setting(863 $setting = new WP_Customize_Nav_Menu_Item_Setting( 827 864 $this->wp_customize, 828 865 'nav_menu_item[123]' … … 883 920 function test_value_as_wp_post_nav_menu_item_term_urls() { 884 921 $term_id = self::factory()->term->create( array( 'taxonomy' => 'category' ) ); 885 register_post_type( 'press_release', array( 886 'has_archive' => true, 887 ) ); 922 register_post_type( 923 'press_release', array( 924 'has_archive' => true, 925 ) 926 ); 888 927 $post_id = self::factory()->post->create( array( 'post_type' => 'press_release' ) ); 889 928 … … 893 932 'nav_menu_item[-1]' 894 933 ); 895 $this->wp_customize->set_post_value( $setting->id, array( 896 'type' => 'taxonomy', 897 'object' => 'category', 898 'object_id' => $term_id, 899 'title' => 'Category', 900 'url' => '', 901 ) ); 934 $this->wp_customize->set_post_value( 935 $setting->id, array( 936 'type' => 'taxonomy', 937 'object' => 'category', 938 'object_id' => $term_id, 939 'title' => 'Category', 940 'url' => '', 941 ) 942 ); 902 943 $setting->preview(); 903 944 $nav_menu_item = $setting->value_as_wp_post_nav_menu_item(); … … 909 950 'nav_menu_item[-2]' 910 951 ); 911 $this->wp_customize->set_post_value( $setting->id, array( 912 'type' => 'post_type', 913 'object' => 'press_release', 914 'object_id' => $post_id, 915 'title' => 'PR', 916 'url' => '', 917 ) ); 952 $this->wp_customize->set_post_value( 953 $setting->id, array( 954 'type' => 'post_type', 955 'object' => 'press_release', 956 'object_id' => $post_id, 957 'title' => 'PR', 958 'url' => '', 959 ) 960 ); 918 961 $setting->preview(); 919 962 $nav_menu_item = $setting->value_as_wp_post_nav_menu_item(); … … 925 968 'nav_menu_item[-3]' 926 969 ); 927 $this->wp_customize->set_post_value( $setting->id, array( 928 'type' => 'post_type_archive', 929 'object' => 'press_release', 930 'title' => 'PR', 931 'url' => '', 932 ) ); 970 $this->wp_customize->set_post_value( 971 $setting->id, array( 972 'type' => 'post_type_archive', 973 'object' => 'press_release', 974 'title' => 'PR', 975 'url' => '', 976 ) 977 ); 933 978 $setting->preview(); 934 979 $nav_menu_item = $setting->value_as_wp_post_nav_menu_item(); … … 944 989 function test_get_original_title() { 945 990 $menu_id = wp_create_nav_menu( 'Menu' ); 946 register_post_type( 'press_release', array( 947 'has_archive' => true, 948 'labels' => array( 949 'name' => 'PRs', 950 'singular_name' => 'PR', 951 'archives' => 'All PRs', 952 ), 953 ) ); 991 register_post_type( 992 'press_release', array( 993 'has_archive' => true, 994 'labels' => array( 995 'name' => 'PRs', 996 'singular_name' => 'PR', 997 'archives' => 'All PRs', 998 ), 999 ) 1000 ); 954 1001 $original_post_title = 'The PR Post'; 955 $post_id = self::factory()->post->create( array( 'post_type' => 'press_release', 'post_title' => $original_post_title ) ); 1002 $post_id = self::factory()->post->create( 1003 array( 1004 'post_type' => 'press_release', 1005 'post_title' => $original_post_title, 1006 ) 1007 ); 956 1008 $original_term_title = 'The Category Term'; 957 $term_id = self::factory()->term->create( array( 'taxonomy' => 'category', 'name' => $original_term_title ) ); 1009 $term_id = self::factory()->term->create( 1010 array( 1011 'taxonomy' => 'category', 1012 'name' => $original_term_title, 1013 ) 1014 ); 958 1015 959 1016 // Post: existing nav menu item. 960 $nav_menu_item_id = wp_update_nav_menu_item( $menu_id, 0, array( 961 'menu-item-object-id' => $post_id, 962 'menu-item-type' => 'post_type', 963 'menu-item-object' => 'press_release', 964 'menu-item-title' => '', 965 'menu-item-status' => 'publish', 966 ) ); 967 $setting = new WP_Customize_Nav_Menu_Item_Setting( 1017 $nav_menu_item_id = wp_update_nav_menu_item( 1018 $menu_id, 0, array( 1019 'menu-item-object-id' => $post_id, 1020 'menu-item-type' => 'post_type', 1021 'menu-item-object' => 'press_release', 1022 'menu-item-title' => '', 1023 'menu-item-status' => 'publish', 1024 ) 1025 ); 1026 $setting = new WP_Customize_Nav_Menu_Item_Setting( 968 1027 $this->wp_customize, 969 1028 'nav_menu_item[' . $nav_menu_item_id . ']' 970 1029 ); 971 $item_value = $setting->value();1030 $item_value = $setting->value(); 972 1031 $this->assertEquals( $original_post_title, $item_value['original_title'] ); 973 1032 $this->assertEquals( '', $item_value['title'] ); … … 985 1044 'nav_menu_item[-1]' 986 1045 ); 987 $this->wp_customize->set_post_value( $setting->id, array( 988 'object_id' => $post_id, 989 'type' => 'post_type', 990 'object' => 'press_release', 991 'title' => '', 992 'status' => 'publish', 993 ) ); 1046 $this->wp_customize->set_post_value( 1047 $setting->id, array( 1048 'object_id' => $post_id, 1049 'type' => 'post_type', 1050 'object' => 'press_release', 1051 'title' => '', 1052 'status' => 'publish', 1053 ) 1054 ); 994 1055 $setting->preview(); 995 1056 $item_value = $setting->value(); … … 1005 1066 1006 1067 // Term: existing nav menu item. 1007 $nav_menu_item_id = wp_update_nav_menu_item( $menu_id, 0, array( 1008 'menu-item-object-id' => $term_id, 1009 'menu-item-type' => 'taxonomy', 1010 'menu-item-object' => 'category', 1011 'menu-item-title' => '', 1012 'menu-item-status' => 'publish', 1013 ) ); 1014 $setting = new WP_Customize_Nav_Menu_Item_Setting( 1068 $nav_menu_item_id = wp_update_nav_menu_item( 1069 $menu_id, 0, array( 1070 'menu-item-object-id' => $term_id, 1071 'menu-item-type' => 'taxonomy', 1072 'menu-item-object' => 'category', 1073 'menu-item-title' => '', 1074 'menu-item-status' => 'publish', 1075 ) 1076 ); 1077 $setting = new WP_Customize_Nav_Menu_Item_Setting( 1015 1078 $this->wp_customize, 1016 1079 'nav_menu_item[' . $nav_menu_item_id . ']' 1017 1080 ); 1018 $item_value = $setting->value();1081 $item_value = $setting->value(); 1019 1082 $this->assertEquals( $original_term_title, $item_value['original_title'] ); 1020 1083 $this->assertEquals( '', $item_value['title'] ); … … 1032 1095 'nav_menu_item[-2]' 1033 1096 ); 1034 $this->wp_customize->set_post_value( $setting->id, array( 1035 'object_id' => $term_id, 1036 'type' => 'taxonomy', 1037 'object' => 'category', 1038 'title' => '', 1039 'status' => 'publish', 1040 ) ); 1097 $this->wp_customize->set_post_value( 1098 $setting->id, array( 1099 'object_id' => $term_id, 1100 'type' => 'taxonomy', 1101 'object' => 'category', 1102 'title' => '', 1103 'status' => 'publish', 1104 ) 1105 ); 1041 1106 $setting->preview(); 1042 1107 $item_value = $setting->value(); … … 1052 1117 1053 1118 // Post Type Archive: existing nav menu item. 1054 $nav_menu_item_id = wp_update_nav_menu_item( $menu_id, 0, array( 1055 'menu-item-type' => 'post_type_archive', 1056 'menu-item-object' => 'press_release', 1057 'menu-item-title' => '', 1058 'menu-item-status' => 'publish', 1059 ) ); 1060 $setting = new WP_Customize_Nav_Menu_Item_Setting( 1119 $nav_menu_item_id = wp_update_nav_menu_item( 1120 $menu_id, 0, array( 1121 'menu-item-type' => 'post_type_archive', 1122 'menu-item-object' => 'press_release', 1123 'menu-item-title' => '', 1124 'menu-item-status' => 'publish', 1125 ) 1126 ); 1127 $setting = new WP_Customize_Nav_Menu_Item_Setting( 1061 1128 $this->wp_customize, 1062 1129 'nav_menu_item[' . $nav_menu_item_id . ']' 1063 1130 ); 1064 $item_value = $setting->value();1131 $item_value = $setting->value(); 1065 1132 $this->assertEquals( get_post_type_object( 'press_release' )->labels->archives, $item_value['original_title'] ); 1066 1133 $this->assertEquals( '', $item_value['title'] ); … … 1078 1145 'nav_menu_item[-3]' 1079 1146 ); 1080 $this->wp_customize->set_post_value( $setting->id, array( 1081 'type' => 'post_type_archive', 1082 'object' => 'press_release', 1083 'title' => '', 1084 'status' => 'publish', 1085 ) ); 1147 $this->wp_customize->set_post_value( 1148 $setting->id, array( 1149 'type' => 'post_type_archive', 1150 'object' => 'press_release', 1151 'title' => '', 1152 'status' => 'publish', 1153 ) 1154 ); 1086 1155 $setting->preview(); 1087 1156 $item_value = $setting->value(); … … 1105 1174 function test_value_as_wp_post_nav_menu_item_with_empty_title() { 1106 1175 $original_title = 'The Original Title'; 1107 $post_id = self::factory()->post->create( array( 'post_title' => $original_title ) );1176 $post_id = self::factory()->post->create( array( 'post_title' => $original_title ) ); 1108 1177 1109 1178 $setting = new WP_Customize_Nav_Menu_Item_Setting(
Note: See TracChangeset
for help on using the changeset viewer.