Changeset 55590
- Timestamp:
- 03/24/2023 04:12:35 PM (19 months ago)
- Location:
- trunk/tests/phpunit/tests/post
- Files:
-
- 1 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/post/getPages.php
r55588 r55590 485 485 $pages = get_pages( array( 'parent' => array( $page_id1, $page_id2 ) ) ); 486 486 $this->assertSameSets( array( $page_id2, $page_id3, $page_id4 ), wp_list_pluck( $pages, 'ID' ) ); 487 }488 489 /**490 * @ticket 22389491 */492 public function test_wp_dropdown_pages() {493 self::factory()->post->create_many( 5, array( 'post_type' => 'page' ) );494 495 preg_match_all( '#<option#', wp_dropdown_pages( 'echo=0' ), $matches );496 497 $this->assertCount( 5, $matches[0] );498 487 } 499 488 -
trunk/tests/phpunit/tests/post/template.php
r52010 r55590 132 132 } 133 133 134 public function test_wp_dropdown_pages() {135 $none = wp_dropdown_pages( array( 'echo' => 0 ) );136 $this->assertEmpty( $none );137 138 $bump = ' ';139 $page_id = self::factory()->post->create( array( 'post_type' => 'page' ) );140 $child_id = self::factory()->post->create(141 array(142 'post_type' => 'page',143 'post_parent' => $page_id,144 )145 );146 $grandchild_id = self::factory()->post->create(147 array(148 'post_type' => 'page',149 'post_parent' => $child_id,150 )151 );152 153 $title1 = get_post( $page_id )->post_title;154 $title2 = get_post( $child_id )->post_title;155 $title3 = get_post( $grandchild_id )->post_title;156 157 $lineage = <<<LINEAGE158 <select name='page_id' id='page_id'>159 <option class="level-0" value="$page_id">$title1</option>160 <option class="level-1" value="$child_id">{$bump}$title2</option>161 <option class="level-2" value="$grandchild_id">{$bump}{$bump}$title3</option>162 </select>163 164 LINEAGE;165 166 $output = wp_dropdown_pages( array( 'echo' => 0 ) );167 $this->assertSameIgnoreEOL( $lineage, $output );168 169 $depth = <<<DEPTH170 <select name='page_id' id='page_id'>171 <option class="level-0" value="$page_id">$title1</option>172 </select>173 174 DEPTH;175 176 $output = wp_dropdown_pages(177 array(178 'echo' => 0,179 'depth' => 1,180 )181 );182 $this->assertSameIgnoreEOL( $depth, $output );183 184 $option_none = <<<NONE185 <select name='page_id' id='page_id'>186 <option value="Woo">Hoo</option>187 <option class="level-0" value="$page_id">$title1</option>188 </select>189 190 NONE;191 192 $output = wp_dropdown_pages(193 array(194 'echo' => 0,195 'depth' => 1,196 'show_option_none' => 'Hoo',197 'option_none_value' => 'Woo',198 )199 );200 $this->assertSameIgnoreEOL( $option_none, $output );201 202 $option_no_change = <<<NO203 <select name='page_id' id='page_id'>204 <option value="-1">Burrito</option>205 <option value="Woo">Hoo</option>206 <option class="level-0" value="$page_id">$title1</option>207 </select>208 209 NO;210 211 $output = wp_dropdown_pages(212 array(213 'echo' => 0,214 'depth' => 1,215 'show_option_none' => 'Hoo',216 'option_none_value' => 'Woo',217 'show_option_no_change' => 'Burrito',218 )219 );220 $this->assertSameIgnoreEOL( $option_no_change, $output );221 }222 223 /**224 * @ticket 12494225 */226 public function test_wp_dropdown_pages_value_field_should_default_to_ID() {227 $p = self::factory()->post->create(228 array(229 'post_type' => 'page',230 )231 );232 233 $found = wp_dropdown_pages(234 array(235 'echo' => 0,236 )237 );238 239 // Should contain page ID by default.240 $this->assertStringContainsString( 'value="' . $p . '"', $found );241 }242 243 /**244 * @ticket 12494245 */246 public function test_wp_dropdown_pages_value_field_ID() {247 $p = self::factory()->post->create(248 array(249 'post_type' => 'page',250 )251 );252 253 $found = wp_dropdown_pages(254 array(255 'echo' => 0,256 'value_field' => 'ID',257 )258 );259 260 $this->assertStringContainsString( 'value="' . $p . '"', $found );261 }262 263 /**264 * @ticket 12494265 */266 public function test_wp_dropdown_pages_value_field_post_name() {267 $p = self::factory()->post->create(268 array(269 'post_type' => 'page',270 'post_name' => 'foo',271 )272 );273 274 $found = wp_dropdown_pages(275 array(276 'echo' => 0,277 'value_field' => 'post_name',278 )279 );280 281 $this->assertStringContainsString( 'value="foo"', $found );282 }283 284 /**285 * @ticket 12494286 */287 public function test_wp_dropdown_pages_value_field_should_fall_back_on_ID_when_an_invalid_value_is_provided() {288 $p = self::factory()->post->create(289 array(290 'post_type' => 'page',291 'post_name' => 'foo',292 )293 );294 295 $found = wp_dropdown_pages(296 array(297 'echo' => 0,298 'value_field' => 'foo',299 )300 );301 302 $this->assertStringContainsString( 'value="' . $p . '"', $found );303 }304 305 /**306 * @ticket 30082307 */308 public function test_wp_dropdown_pages_should_not_contain_class_attribute_when_no_class_is_passed() {309 $p = self::factory()->post->create(310 array(311 'post_type' => 'page',312 'post_name' => 'foo',313 )314 );315 316 $found = wp_dropdown_pages(317 array(318 'echo' => 0,319 )320 );321 322 $this->assertDoesNotMatchRegularExpression( '/<select[^>]+class=\'/', $found );323 }324 325 /**326 * @ticket 30082327 */328 public function test_wp_dropdown_pages_should_obey_class_parameter() {329 $p = self::factory()->post->create(330 array(331 'post_type' => 'page',332 'post_name' => 'foo',333 )334 );335 336 $found = wp_dropdown_pages(337 array(338 'echo' => 0,339 'class' => 'bar',340 )341 );342 343 $this->assertMatchesRegularExpression( '/<select[^>]+class=\'bar\'/', $found );344 }345 346 134 /** 347 135 * @ticket 31389
Note: See TracChangeset
for help on using the changeset viewer.