Changeset 41626 for trunk/tests/phpunit/tests/customize/manager.php
- Timestamp:
- 09/27/2017 10:24:37 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/customize/manager.php
r41558 r41626 121 121 $this->assertEquals( $theme, $wp_customize->get_stylesheet() ); 122 122 $this->assertEquals( $messenger_channel, $wp_customize->get_messenger_channel() ); 123 $this->assertFalse( $wp_customize->autosaved() ); 124 $this->assertTrue( $wp_customize->branching() ); 125 126 $wp_customize = new WP_Customize_Manager( array( 127 'changeset_uuid' => null, 128 ) ); 129 $this->assertTrue( wp_is_uuid( $wp_customize->changeset_uuid(), 4 ) ); 123 130 124 131 $theme = 'twentyfourteen'; … … 134 141 $wp_customize = new WP_Customize_Manager(); 135 142 $this->assertEquals( $theme, $wp_customize->get_stylesheet() ); 136 $this->assertNotEmpty( $wp_customize->changeset_uuid() ); 143 $this->assertTrue( wp_is_uuid( $wp_customize->changeset_uuid(), 4 ) ); 144 } 145 146 /** 147 * Test constructor when deferring UUID. 148 * 149 * @ticket 39896 150 * @covers WP_Customize_Manager::establish_loaded_changeset() 151 * @covers WP_Customize_Manager::__construct() 152 */ 153 public function test_constructor_deferred_changeset_uuid() { 154 $data = array( 155 'blogname' => array( 156 'value' => 'Test', 157 ), 158 ); 159 $uuid = wp_generate_uuid4(); 160 $post_id = $this->factory()->post->create( array( 161 'post_type' => 'customize_changeset', 162 'post_name' => $uuid, 163 'post_status' => 'draft', 164 'post_content' => wp_json_encode( $data ), 165 ) ); 166 $wp_customize = new WP_Customize_Manager( array( 167 'changeset_uuid' => false, // Cause UUID to be deferred. 168 'branching' => false, // To cause drafted changeset to be autoloaded. 169 ) ); 170 $this->assertEquals( $uuid, $wp_customize->changeset_uuid() ); 171 $this->assertEquals( $post_id, $wp_customize->changeset_post_id() ); 137 172 } 138 173 … … 255 290 256 291 /** 292 * Test WP_Customize_Manager::autosaved(). 293 * 294 * @ticket 39896 295 * @covers WP_Customize_Manager::autosaved() 296 */ 297 public function test_autosaved() { 298 $wp_customize = new WP_Customize_Manager(); 299 $this->assertFalse( $wp_customize->autosaved() ); 300 301 $wp_customize = new WP_Customize_Manager( array( 'autosaved' => false ) ); 302 $this->assertFalse( $wp_customize->autosaved() ); 303 304 $wp_customize = new WP_Customize_Manager( array( 'autosaved' => true ) ); 305 $this->assertTrue( $wp_customize->autosaved() ); 306 } 307 308 /** 309 * Test WP_Customize_Manager::branching(). 310 * 311 * @ticket 39896 312 * @covers WP_Customize_Manager::branching() 313 */ 314 public function test_branching() { 315 $wp_customize = new WP_Customize_Manager(); 316 $this->assertTrue( $wp_customize->branching(), 'Branching should default to true since it is original behavior in 4.7.' ); 317 318 $wp_customize = new WP_Customize_Manager( array( 'branching' => false ) ); 319 $this->assertFalse( $wp_customize->branching() ); 320 add_filter( 'customize_changeset_branching', '__return_true' ); 321 $this->assertTrue( $wp_customize->branching() ); 322 remove_filter( 'customize_changeset_branching', '__return_true' ); 323 324 $wp_customize = new WP_Customize_Manager( array( 'branching' => true ) ); 325 $this->assertTrue( $wp_customize->branching() ); 326 add_filter( 'customize_changeset_branching', '__return_false' ); 327 $this->assertFalse( $wp_customize->branching() ); 328 } 329 330 /** 257 331 * Test WP_Customize_Manager::changeset_uuid(). 258 332 * … … 338 412 */ 339 413 function test_changeset_data() { 414 wp_set_current_user( self::$admin_user_id ); 340 415 $uuid = wp_generate_uuid4(); 341 416 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); … … 343 418 344 419 $uuid = wp_generate_uuid4(); 345 $data = array( 'blogname' => array( 'value' => 'Hello World' ) ); 420 $data = array( 421 'blogname' => array( 'value' => 'Hello World' ), 422 'blogdescription' => array( 'value' => 'Greet the world' ), 423 ); 346 424 $this->factory()->post->create( array( 347 425 'post_name' => $uuid, 348 426 'post_type' => 'customize_changeset', 349 'post_status' => ' auto-draft',427 'post_status' => 'draft', 350 428 'post_content' => wp_json_encode( $data ), 351 429 ) ); 352 430 $wp_customize = new WP_Customize_Manager( array( 'changeset_uuid' => $uuid ) ); 353 431 $this->assertEquals( $data, $wp_customize->changeset_data() ); 432 433 // Autosave. 434 $wp_customize->set_post_value( 'blogname', 'Hola Mundo' ); 435 $wp_customize->register_controls(); // That is, settings, so blogname setting is registered. 436 $r = $wp_customize->save_changeset_post( array( 437 'autosave' => true, 438 ) ); 439 $this->assertNotInstanceOf( 'WP_Error', $r ); 440 441 // No change to data if not requesting autosave. 442 $wp_customize = new WP_Customize_Manager( array( 443 'changeset_uuid' => $uuid, 444 'autosaved' => false, 445 ) ); 446 $wp_customize->register_controls(); // That is, settings. 447 $this->assertFalse( $wp_customize->autosaved() ); 448 $this->assertEquals( $data, $wp_customize->changeset_data() ); 449 450 // No change to data if not requesting autosave. 451 $wp_customize = new WP_Customize_Manager( array( 452 'changeset_uuid' => $uuid, 453 'autosaved' => true, 454 ) ); 455 $this->assertTrue( $wp_customize->autosaved() ); 456 $this->assertNotEquals( $data, $wp_customize->changeset_data() ); 457 $this->assertEquals( 458 array_merge( 459 wp_list_pluck( $data, 'value' ), 460 array( 'blogname' => 'Hola Mundo' ) 461 ), 462 wp_list_pluck( $wp_customize->changeset_data(), 'value' ) 463 ); 354 464 } 355 465 … … 1274 1384 1275 1385 /** 1386 * Test writing changesets when user supplies unchanged values. 1387 * 1388 * @ticket 39896 1389 * @covers WP_Customize_Manager::save_changeset_post() 1390 * @covers WP_Customize_Manager::grant_edit_post_capability_for_changeset() 1391 */ 1392 public function test_save_changeset_post_with_autosave() { 1393 wp_set_current_user( self::$admin_user_id ); 1394 $uuid = wp_generate_uuid4(); 1395 $changeset_post_id = wp_insert_post( array( 1396 'post_type' => 'customize_changeset', 1397 'post_content' => wp_json_encode( array( 1398 'blogname' => array( 1399 'value' => 'Auto-draft Title', 1400 ), 1401 ) ), 1402 'post_author' => self::$admin_user_id, 1403 'post_name' => $uuid, 1404 'post_status' => 'auto-draft', 1405 ) ); 1406 1407 $wp_customize = new WP_Customize_Manager( array( 1408 'changeset_uuid' => $uuid, 1409 ) ); 1410 $wp_customize->register_controls(); // And settings too. 1411 1412 // Autosave of an auto-draft overwrites original. 1413 $wp_customize->save_changeset_post( array( 1414 'data' => array( 1415 'blogname' => array( 1416 'value' => 'Autosaved Auto-draft Title', 1417 ), 1418 ), 1419 'autosave' => true, 1420 ) ); 1421 $this->assertFalse( wp_get_post_autosave( $changeset_post_id ) ); 1422 $this->assertContains( 'Autosaved Auto-draft Title', get_post( $changeset_post_id )->post_content ); 1423 1424 // Update status to draft for subsequent tests. 1425 $wp_customize->save_changeset_post( array( 1426 'data' => array( 1427 'blogname' => array( 1428 'value' => 'Draft Title', 1429 ), 1430 ), 1431 'status' => 'draft', 1432 'autosave' => false, 1433 ) ); 1434 $this->assertContains( 'Draft Title', get_post( $changeset_post_id )->post_content ); 1435 1436 // Fail: illegal_autosave_with_date_gmt. 1437 $r = $wp_customize->save_changeset_post( array( 1438 'autosave' => true, 1439 'date_gmt' => ( gmdate( 'Y' ) + 1 ) . '-12-01 00:00:00', 1440 ) ); 1441 $this->assertInstanceOf( 'WP_Error', $r ); 1442 $this->assertEquals( 'illegal_autosave_with_date_gmt', $r->get_error_code() ); 1443 1444 // Fail: illegal_autosave_with_status. 1445 $r = $wp_customize->save_changeset_post( array( 1446 'autosave' => true, 1447 'status' => 'pending', 1448 ) ); 1449 $this->assertEquals( 'illegal_autosave_with_status', $r->get_error_code() ); 1450 1451 // Fail: illegal_autosave_with_non_current_user. 1452 $r = $wp_customize->save_changeset_post( array( 1453 'autosave' => true, 1454 'user_id' => $this->factory()->user->create( array( 'role' => 'administrator' ) ), 1455 ) ); 1456 $this->assertEquals( 'illegal_autosave_with_non_current_user', $r->get_error_code() ); 1457 1458 // Try autosave. 1459 $this->assertFalse( wp_get_post_autosave( $changeset_post_id ) ); 1460 $r = $wp_customize->save_changeset_post( array( 1461 'data' => array( 1462 'blogname' => array( 1463 'value' => 'Autosave Title', 1464 ), 1465 ), 1466 'autosave' => true, 1467 ) ); 1468 $this->assertInternalType( 'array', $r ); 1469 1470 // Verify that autosave happened. 1471 $autosave_revision = wp_get_post_autosave( $changeset_post_id ); 1472 $this->assertInstanceOf( 'WP_Post', $autosave_revision ); 1473 $this->assertContains( 'Draft Title', get_post( $changeset_post_id )->post_content ); 1474 $this->assertContains( 'Autosave Title', $autosave_revision->post_content ); 1475 } 1476 1477 /** 1276 1478 * Test passing `null` for a setting ID to remove it from the changeset. 1277 1479 * … … 2352 2554 $this->assertNotEmpty( $data ); 2353 2555 2354 $this->assertEqualSets( array( 'theme', 'url', 'browser', 'panels', 'sections', 'nonce', 'autofocus', 'documentTitleTmpl', 'previewableDevices', 'changeset', 'timeouts' ), array_keys( $data ) );2556 $this->assertEqualSets( array( 'theme', 'url', 'browser', 'panels', 'sections', 'nonce', 'autofocus', 'documentTitleTmpl', 'previewableDevices', 'changeset', 'timeouts', 'initialClientTimestamp', 'initialServerDate', 'initialServerTimestamp' ), array_keys( $data ) ); 2355 2557 $this->assertEquals( $autofocus, $data['autofocus'] ); 2356 2558 $this->assertArrayHasKey( 'save', $data['nonce'] ); 2357 2559 $this->assertArrayHasKey( 'preview', $data['nonce'] ); 2560 2561 $this->assertEqualSets( 2562 array( 2563 'branching', 2564 'autosaved', 2565 'hasAutosaveRevision', 2566 'latestAutoDraftUuid', 2567 'status', 2568 'uuid', 2569 'currentUserCanPublish', 2570 'publishDate', 2571 ), 2572 array_keys( $data['changeset'] ) 2573 ); 2358 2574 } 2359 2575
Note: See TracChangeset
for help on using the changeset viewer.