48 | | } |
| 48 | |
| 49 | function test_add_metabox() { |
| 50 | |
| 51 | global $wp_meta_boxes; |
| 52 | |
| 53 | add_meta_box( 'testbox1', 'Test Metabox', '__return_false', 'post' ); |
| 54 | |
| 55 | $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] ); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * @ticket 15000 |
| 61 | */ |
| 62 | function test_add_meta_box_on_multiple_post_types() { |
| 63 | global $wp_meta_boxes; |
| 64 | |
| 65 | // Add a meta box to three different post types |
| 66 | add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'page', 'book' ) ); |
| 67 | |
| 68 | $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] ); |
| 69 | $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['page']['advanced']['default'] ); |
| 70 | $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['book']['advanced']['default'] ); |
| 71 | |
| 72 | // Add a meta box to the same post types but posts |
| 73 | add_meta_box( 'testbox2', 'Test Metabox', '__return_false', array( 'page', 'book' ) ); |
| 74 | |
| 75 | $this->assertArrayNotHasKey( 'testbox2', $wp_meta_boxes['post']['advanced']['default'] ); |
| 76 | $this->assertArrayHasKey( 'testbox2', $wp_meta_boxes['page']['advanced']['default'] ); |
| 77 | $this->assertArrayHasKey( 'testbox2', $wp_meta_boxes['book']['advanced']['default'] ); |
| 78 | } |
| 79 | |
| 80 | function test_remove_metabox() { |
| 81 | |
| 82 | global $wp_meta_boxes; |
| 83 | |
| 84 | // Add some meta boxes to remove |
| 85 | add_meta_box( 'testbox1', 'Test Metabox', '__return_false', 'post' ); |
| 86 | |
| 87 | // Remove one |
| 88 | remove_meta_box( 'testbox1', 'post', 'advanced' ); |
| 89 | |
| 90 | // Check that it was removed properly (The meta box should be set to false once that it has been removed) |
| 91 | $this->assertFalse( $wp_meta_boxes['post']['advanced']['default']['testbox1'] ); |
| 92 | |
| 93 | } |
| 94 | |
| 95 | /** |
| 96 | * @ticket 15000 |
| 97 | */ |
| 98 | function test_remove_meta_box_from_multiple_post_types() { |
| 99 | global $wp_meta_boxes; |
| 100 | |
| 101 | // Add a meta box to three different post types |
| 102 | add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'page', 'book' ) ); |
| 103 | |
| 104 | // Remove meta box from posts |
| 105 | remove_meta_box( 'testbox1', 'post', 'advanced' ); |
| 106 | |
| 107 | // Check that we have removed the meta boxes only from posts |
| 108 | $this->assertFalse( $wp_meta_boxes['post']['advanced']['default']['testbox1'] ); |
| 109 | $this->assertArrayHasKey( 'testbox2', $wp_meta_boxes['page']['advanced']['default'] ); |
| 110 | $this->assertArrayHasKey( 'testbox2', $wp_meta_boxes['book']['advanced']['default'] ); |
| 111 | |
| 112 | // Remove the meta box from the other post types |
| 113 | remove_meta_box( 'testbox1', array( 'page', 'book' ), 'advanced' ); |
| 114 | |
| 115 | $this->assertFalse( $wp_meta_boxes['page']['advanced']['default']['testbox1'] ); |
| 116 | $this->assertFalse( $wp_meta_boxes['book']['advanced']['default']['testbox1'] ); |
| 117 | } |
| 118 | |
| 119 | } |
| 120 | No newline at end of file |