- Timestamp:
- 11/30/2017 11:09:33 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/widgets/media-gallery-widget.php
r41590 r42343 24 24 parent::clean_up_global_scope(); 25 25 $wp_scripts = null; 26 $wp_styles = null;26 $wp_styles = null; 27 27 } 28 28 … … 61 61 $test_image = '/tmp/' . $filename; 62 62 copy( DIR_TESTDATA . '/images/canola.jpg', $test_image ); 63 $attachment_id = self::factory()->attachment->create_object( array( 64 'file' => $test_image, 65 'post_parent' => 0, 66 'post_mime_type' => 'image/jpeg', 67 'post_title' => 'Canola', 68 ) ); 63 $attachment_id = self::factory()->attachment->create_object( 64 array( 65 'file' => $test_image, 66 'post_parent' => 0, 67 'post_mime_type' => 'image/jpeg', 68 'post_title' => 'Canola', 69 ) 70 ); 69 71 wp_update_attachment_metadata( $attachment_id, wp_generate_attachment_metadata( $attachment_id, $test_image ) ); 70 72 $attachments[ $filename ] = $attachment_id; 71 73 } 72 74 73 $instance = wp_list_pluck( $widget->get_instance_schema(), 'default' );74 $instance['size'] = 'thumbnail';75 $instance = wp_list_pluck( $widget->get_instance_schema(), 'default' ); 76 $instance['size'] = 'thumbnail'; 75 77 $instance['columns'] = 3; 76 $instance['ids'] = array_values( $attachments );78 $instance['ids'] = array_values( $attachments ); 77 79 ob_start(); 78 80 $widget->render_media( $instance ); … … 110 112 */ 111 113 public function test_update() { 112 $widget = new WP_Widget_Media_Gallery();113 $schema = $widget->get_instance_schema();114 $widget = new WP_Widget_Media_Gallery(); 115 $schema = $widget->get_instance_schema(); 114 116 $instance = wp_list_pluck( $schema, 'default' ); 115 117 116 118 // Field: title. 117 119 $instance['title'] = 'Hello <b>World</b> '; 118 $instance = $widget->update( $instance, array() );120 $instance = $widget->update( $instance, array() ); 119 121 $this->assertEquals( 'Hello World', $instance['title'] ); 120 122 121 123 // Field: ids. 122 124 $instance['ids'] = '1,2,3'; 123 $instance = $widget->update( $instance, array() );125 $instance = $widget->update( $instance, array() ); 124 126 $this->assertSame( array( 1, 2, 3 ), $instance['ids'] ); 125 127 126 128 $instance['ids'] = array( 1, 2, '3' ); 127 $instance = $widget->update( $instance, array() );129 $instance = $widget->update( $instance, array() ); 128 130 $this->assertSame( array( 1, 2, 3 ), $instance['ids'] ); 129 131 130 132 $instance['ids'] = array( 'too', 'bad' ); 131 $instance = $widget->update( $instance, array( 'ids' => array( 2, 3 ) ) );133 $instance = $widget->update( $instance, array( 'ids' => array( 2, 3 ) ) ); 132 134 $this->assertSame( array( 2, 3 ), $instance['ids'] ); 133 135 134 136 // Field: columns. 135 137 $instance['columns'] = 4; 136 $instance = $widget->update( $instance, array() );138 $instance = $widget->update( $instance, array() ); 137 139 $this->assertSame( 4, $instance['columns'] ); 138 140 139 141 $instance['columns'] = '2'; 140 $instance = $widget->update( $instance, array() );142 $instance = $widget->update( $instance, array() ); 141 143 $this->assertSame( 2, $instance['columns'] ); 142 144 143 145 $instance['columns'] = -1; // Under min of 1. 144 $instance = $widget->update( $instance, array( 'columns' => 3 ) );146 $instance = $widget->update( $instance, array( 'columns' => 3 ) ); 145 147 $this->assertSame( 3, $instance['columns'] ); 146 148 147 149 $instance['columns'] = 10; // Over max of 9. 148 $instance = $widget->update( $instance, array( 'columns' => 3 ) );150 $instance = $widget->update( $instance, array( 'columns' => 3 ) ); 149 151 $this->assertSame( 3, $instance['columns'] ); 150 152 151 153 // Field: size. 152 154 $instance['size'] = 'large'; 153 $instance = $widget->update( $instance, array() );155 $instance = $widget->update( $instance, array() ); 154 156 $this->assertSame( 'large', $instance['size'] ); 155 157 156 158 $instance['size'] = 'bad'; 157 $instance = $widget->update( $instance, array( 'size' => 'thumbnail' ) );159 $instance = $widget->update( $instance, array( 'size' => 'thumbnail' ) ); 158 160 $this->assertSame( 'thumbnail', $instance['size'] ); 159 161 160 162 // Field: link_type. 161 163 $instance['link_type'] = 'none'; 162 $instance = $widget->update( $instance, array() );164 $instance = $widget->update( $instance, array() ); 163 165 $this->assertSame( 'none', $instance['link_type'] ); 164 166 165 167 $instance['link_type'] = 'unknown'; 166 $instance = $widget->update( $instance, array( 'link_type' => 'file' ) );168 $instance = $widget->update( $instance, array( 'link_type' => 'file' ) ); 167 169 $this->assertSame( 'file', $instance['link_type'] ); 168 170 169 171 // Field: orderby_random. 170 172 $instance['orderby_random'] = '1'; 171 $instance = $widget->update( $instance, array() );173 $instance = $widget->update( $instance, array() ); 172 174 $this->assertTrue( $instance['orderby_random'] ); 173 175 174 176 $instance['orderby_random'] = true; 175 $instance = $widget->update( $instance, array() );177 $instance = $widget->update( $instance, array() ); 176 178 $this->assertTrue( $instance['orderby_random'] ); 177 179 178 180 $instance['orderby_random'] = ''; 179 $instance = $widget->update( $instance, array() );181 $instance = $widget->update( $instance, array() ); 180 182 $this->assertFalse( $instance['orderby_random'] ); 181 183 182 184 $instance['orderby_random'] = false; 183 $instance = $widget->update( $instance, array() );185 $instance = $widget->update( $instance, array() ); 184 186 $this->assertFalse( $instance['orderby_random'] ); 185 187 }
Note: See TracChangeset
for help on using the changeset viewer.