Make WordPress Core

Ticket #15000: 15000-tests.diff.2

File 15000-tests.diff.2, 3.3 KB (added by igmoweb, 11 years ago)

Unit tests included

Line 
1Index: tests/phpunit/tests/admin/includesScreen.php
2===================================================================
3--- tests/phpunit/tests/admin/includesScreen.php        (revision 29835)
4+++ tests/phpunit/tests/admin/includesScreen.php        (working copy)
5@@ -230,4 +230,6 @@
6 
7                $GLOBALS['current_screen'] = $screen;
8        }
9+
10+       
11 }
12Index: tests/phpunit/tests/admin/includesTemplate.php
13===================================================================
14--- tests/phpunit/tests/admin/includesTemplate.php      (revision 29835)
15+++ tests/phpunit/tests/admin/includesTemplate.php      (working copy)
16@@ -45,4 +45,75 @@
17                $this->assertEquals('', selected(0,false,false));
18                $this->assertEquals('', checked(0,false,false));
19        }
20-}
21+
22+       function test_add_metabox() {
23+
24+               global $wp_meta_boxes;
25+
26+               add_meta_box( 'testbox1', 'Test Metabox', '__return_false', 'post' );
27+               
28+               $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] );
29+
30+       }
31+
32+       /**
33+        * @ticket 15000
34+        */
35+       function test_add_meta_box_on_multiple_post_types() {
36+               global $wp_meta_boxes;
37+
38+               // Add a meta box to three different post types
39+               add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'page', 'book' ) );
40+
41+               $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['post']['advanced']['default'] );
42+               $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['page']['advanced']['default'] );
43+               $this->assertArrayHasKey( 'testbox1', $wp_meta_boxes['book']['advanced']['default'] );
44+
45+               // Add a meta box to the same post types but posts
46+               add_meta_box( 'testbox2', 'Test Metabox', '__return_false', array( 'page', 'book' ) );         
47+
48+               $this->assertArrayNotHasKey( 'testbox2', $wp_meta_boxes['post']['advanced']['default'] );
49+               $this->assertArrayHasKey( 'testbox2', $wp_meta_boxes['page']['advanced']['default'] );
50+               $this->assertArrayHasKey( 'testbox2', $wp_meta_boxes['book']['advanced']['default'] );
51+       }
52+
53+       function test_remove_metabox() {
54+
55+               global $wp_meta_boxes;
56+
57+               // Add some meta boxes to remove
58+               add_meta_box( 'testbox1', 'Test Metabox', '__return_false', 'post' );
59+
60+               // Remove one
61+               remove_meta_box( 'testbox1', 'post', 'advanced' );
62+               
63+               // Check that it was removed properly (The meta box should be set to false once that it has been removed)
64+               $this->assertFalse( $wp_meta_boxes['post']['advanced']['default']['testbox1'] );
65+
66+       }
67+
68+       /**
69+        * @ticket 15000
70+        */
71+       function test_remove_meta_box_from_multiple_post_types() {
72+               global $wp_meta_boxes;
73+
74+               // Add a meta box to three different post types
75+               add_meta_box( 'testbox1', 'Test Metabox', '__return_false', array( 'post', 'page', 'book' ) );
76+
77+               // Remove meta box from posts
78+               remove_meta_box( 'testbox1', 'post', 'advanced' );
79+
80+               // Check that we have removed the meta boxes only from posts
81+               $this->assertFalse( $wp_meta_boxes['post']['advanced']['default']['testbox1'] );
82+               $this->assertArrayHasKey( 'testbox2', $wp_meta_boxes['page']['advanced']['default'] );
83+               $this->assertArrayHasKey( 'testbox2', $wp_meta_boxes['book']['advanced']['default'] );
84+
85+               // Remove the meta box from the other post types
86+               remove_meta_box( 'testbox1', array( 'page', 'book' ), 'advanced' );
87+
88+               $this->assertFalse( $wp_meta_boxes['page']['advanced']['default']['testbox1'] );
89+               $this->assertFalse( $wp_meta_boxes['book']['advanced']['default']['testbox1'] );
90+       }
91+
92+}
93\ No newline at end of file