QuickEdit.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Admin Ajax functions to be tested.
  4. */
  5. require_once ABSPATH . 'wp-admin/includes/ajax-actions.php';
  6. /**
  7. * Testing Quick Edit AJAX functionality.
  8. *
  9. * @group ajax
  10. */
  11. class Tests_Ajax_QuickEdit extends WP_Ajax_UnitTestCase {
  12. /**
  13. * @ticket 26948
  14. */
  15. public function test_dont_process_terms_if_taxonomy_does_not_allow_show_on_quick_edit() {
  16. register_taxonomy(
  17. 'wptests_tax_1',
  18. 'post',
  19. array(
  20. 'show_in_quick_edit' => false,
  21. 'hierarchical' => true,
  22. )
  23. );
  24. register_taxonomy(
  25. 'wptests_tax_2',
  26. 'post',
  27. array(
  28. 'show_in_quick_edit' => true,
  29. 'hierarchical' => true,
  30. )
  31. );
  32. $t1 = self::factory()->term->create(
  33. array(
  34. 'taxonomy' => 'wptests_tax_1',
  35. )
  36. );
  37. $t2 = self::factory()->term->create(
  38. array(
  39. 'taxonomy' => 'wptests_tax_2',
  40. )
  41. );
  42. // Become an administrator.
  43. $this->_setRole( 'administrator' );
  44. $post = self::factory()->post->create_and_get(
  45. array(
  46. 'post_author' => get_current_user_id(),
  47. )
  48. );
  49. // Set up a request.
  50. $_POST['_inline_edit'] = wp_create_nonce( 'inlineeditnonce' );
  51. $_POST['post_ID'] = $post->ID;
  52. $_POST['post_type'] = $post->post_type;
  53. $_POST['content'] = $post->post_content;
  54. $_POST['excerpt'] = $post->post_excerpt;
  55. $_POST['_status'] = $post->post_status;
  56. $_POST['post_status'] = $post->post_status;
  57. $_POST['screen'] = 'post';
  58. $_POST['post_view'] = 'excerpt';
  59. $_POST['tax_input'] = array(
  60. 'wptests_tax_1' => array( $t1 ),
  61. 'wptests_tax_2' => array( $t2 ),
  62. );
  63. // Make the request.
  64. try {
  65. $this->_handleAjax( 'inline-save' );
  66. } catch ( WPAjaxDieContinueException $e ) {
  67. unset( $e );
  68. }
  69. // 'wptests_tax_1' terms should have been refused.
  70. $post_terms_1 = wp_get_object_terms( $post->ID, 'wptests_tax_1' );
  71. $this->assertEmpty( $post_terms_1 );
  72. // 'wptests_tax_2' terms should have been added successfully.
  73. $post_terms_2 = wp_get_object_terms( $post->ID, 'wptests_tax_2' );
  74. $this->assertSameSets( array( $t2 ), wp_list_pluck( $post_terms_2, 'term_id' ) );
  75. }
  76. }