Changeset 30784
- Timestamp:
- 12/08/2014 01:43:31 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tests/phpunit/tests/multisite/site.php
r30719 r30784 318 318 } 319 319 320 /** 321 * If `update_blog_details()` is called with any kind of empty arguments, it 322 * should return false. 323 */ 324 function test_update_blog_details_with_empty_args() { 325 $result = update_blog_details( 1, array() ); 326 $this->assertFalse( $result ); 327 } 328 329 /** 330 * If the ID passed is not that of a current site, we should expect false. 331 */ 332 function test_update_blog_details_invalid_blog_id() { 333 $result = update_blog_details( 999, array( 'domain' => 'example.com' ) ); 334 $this->assertFalse( $result ); 335 } 336 320 337 function test_update_blog_details() { 321 global $test_action_counter; 322 323 $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); 324 $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 325 $this->assertInternalType( 'int', $blog_id ); 326 327 $result = update_blog_details( $blog_id, array('domain' => 'example.com', 'path' => 'my_path/') ); 338 $blog_id = $this->factory->blog->create( array( 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 339 340 $result = update_blog_details( $blog_id, array( 'domain' => 'example.com', 'path' => 'my_path/' ) ); 341 328 342 $this->assertTrue( $result ); 329 343 330 344 $blog = get_blog_details( $blog_id ); 345 331 346 $this->assertEquals( 'example.com', $blog->domain ); 332 347 $this->assertEquals( 'my_path/', $blog->path ); 333 348 $this->assertEquals( '0', $blog->spam ); 334 335 $result = update_blog_details( $blog_id, array('domain' => 'example2.com','spam' => 1) ); 336 $this->assertTrue( $result ); 337 $blog = get_blog_details( $blog_id ); 338 $this->assertEquals( 'example2.com', $blog->domain ); 339 $this->assertEquals( 'my_path/', $blog->path ); 349 } 350 351 function test_update_blog_details_make_ham_blog_action() { 352 global $test_action_counter; 353 $test_action_counter = 0; 354 355 $blog_id = $this->factory->blog->create( array( 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 356 update_blog_details( $blog_id, array( 'spam' => 1 ) ); 357 358 add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 ); 359 update_blog_details( $blog_id, array( 'spam' => 0 ) ); 360 $blog = get_blog_details( $blog_id ); 361 362 $this->assertEquals( '0', $blog->spam ); 363 $this->assertEquals( 1, $test_action_counter ); 364 365 // The action should not fire if the status of 'spam' stays the same. 366 update_blog_details( $blog_id, array( 'spam' => 0 ) ); 367 $blog = get_blog_details( $blog_id ); 368 369 $this->assertEquals( '0', $blog->spam ); 370 $this->assertEquals( 1, $test_action_counter ); 371 372 remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10 ); 373 } 374 375 function test_update_blog_details_make_spam_blog_action() { 376 global $test_action_counter; 377 $test_action_counter = 0; 378 379 $blog_id = $this->factory->blog->create( array( 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 380 381 add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 ); 382 update_blog_details( $blog_id, array( 'spam' => 1 ) ); 383 $blog = get_blog_details( $blog_id ); 384 340 385 $this->assertEquals( '1', $blog->spam ); 341 342 $result = update_blog_details( $blog_id ); 343 $this->assertFalse( $result );344 $blog = get_blog_details( $blog_id);345 $ this->assertEquals( 'example2.com', $blog->domain);346 $this->assertEquals( 'my_path/', $blog->path ); 386 $this->assertEquals( 1, $test_action_counter ); 387 388 // The action should not fire if the status of 'spam' stays the same. 389 update_blog_details( $blog_id, array( 'spam' => 1 ) ); 390 $blog = get_blog_details( $blog_id ); 391 347 392 $this->assertEquals( '1', $blog->spam ); 348 393 $this->assertEquals( 1, $test_action_counter ); 394 395 remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10 ); 396 } 397 398 function test_update_blog_details_archive_blog_action() { 399 global $test_action_counter; 349 400 $test_action_counter = 0; 350 401 351 add_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 352 $result = update_blog_details( $blog_id, array( 'spam' => 0 ) ); 353 $this->assertTrue( $result ); 354 $blog = get_blog_details( $blog_id ); 355 $this->assertEquals( '0', $blog->spam ); 356 $this->assertEquals( 1, $test_action_counter ); 357 358 // Same again 359 $result = update_blog_details( $blog_id, array( 'spam' => 0 ) ); 360 $this->assertTrue( $result ); 361 $blog = get_blog_details( $blog_id ); 362 $this->assertEquals( '0', $blog->spam ); 363 $this->assertEquals( 1, $test_action_counter ); 364 remove_action( 'make_ham_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 365 366 add_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 367 $result = update_blog_details( $blog_id, array( 'spam' => 1 ) ); 368 $this->assertTrue( $result ); 369 $blog = get_blog_details( $blog_id ); 370 $this->assertEquals( '1', $blog->spam ); 371 $this->assertEquals( 2, $test_action_counter ); 372 373 // Same again 374 $result = update_blog_details( $blog_id, array( 'spam' => 1 ) ); 375 $this->assertTrue( $result ); 376 $blog = get_blog_details( $blog_id ); 377 $this->assertEquals( '1', $blog->spam ); 378 $this->assertEquals( 2, $test_action_counter ); 379 remove_action( 'make_spam_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 380 381 add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 382 $result = update_blog_details( $blog_id, array( 'archived' => 1 ) ); 383 $this->assertTrue( $result ); 384 $blog = get_blog_details( $blog_id ); 402 $blog_id = $this->factory->blog->create( array( 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 403 404 add_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 ); 405 update_blog_details( $blog_id, array( 'archived' => 1 ) ); 406 $blog = get_blog_details( $blog_id ); 407 385 408 $this->assertEquals( '1', $blog->archived ); 386 $this->assertEquals( 3, $test_action_counter );387 388 // Same again389 $result =update_blog_details( $blog_id, array( 'archived' => 1 ) );390 $ this->assertTrue( $result);391 $blog = get_blog_details( $blog_id ); 409 $this->assertEquals( 1, $test_action_counter ); 410 411 // The action should not fire if the status of 'archived' stays the same. 412 update_blog_details( $blog_id, array( 'archived' => 1 ) ); 413 $blog = get_blog_details( $blog_id ); 414 392 415 $this->assertEquals( '1', $blog->archived ); 393 $this->assertEquals( 3, $test_action_counter ); 394 remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 395 396 add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 397 $result = update_blog_details( $blog_id, array( 'archived' => 0 ) ); 398 $this->assertTrue( $result ); 399 $blog = get_blog_details( $blog_id ); 416 $this->assertEquals( 1, $test_action_counter ); 417 418 remove_action( 'archive_blog', array( $this, '_action_counter_cb' ), 10 ); 419 } 420 421 function test_update_blog_details_unarchive_blog_action() { 422 global $test_action_counter; 423 $test_action_counter = 0; 424 425 $blog_id = $this->factory->blog->create( array( 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 426 update_blog_details( $blog_id, array( 'archived' => 1 ) ); 427 428 add_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 ); 429 update_blog_details( $blog_id, array( 'archived' => 0 ) ); 430 $blog = get_blog_details( $blog_id ); 431 400 432 $this->assertEquals( '0', $blog->archived ); 401 $this->assertEquals( 4, $test_action_counter ); 402 403 // Same again 404 $result = update_blog_details( $blog_id, array( 'archived' => 0 ) ); 405 $this->assertTrue( $result ); 433 $this->assertEquals( 1, $test_action_counter ); 434 435 // The action should not fire if the status of 'archived' stays the same. 436 update_blog_details( $blog_id, array( 'archived' => 0 ) ); 406 437 $blog = get_blog_details( $blog_id ); 407 438 $this->assertEquals( '0', $blog->archived ); 408 $this->assertEquals( 4, $test_action_counter ); 409 remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 410 411 add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 412 $result = update_blog_details( $blog_id, array( 'deleted' => 1 ) ); 413 $this->assertTrue( $result ); 414 $blog = get_blog_details( $blog_id ); 439 $this->assertEquals( 1, $test_action_counter ); 440 441 remove_action( 'unarchive_blog', array( $this, '_action_counter_cb' ), 10 ); 442 } 443 444 function test_update_blog_details_make_delete_blog_action() { 445 global $test_action_counter; 446 $test_action_counter = 0; 447 448 $blog_id = $this->factory->blog->create( array( 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 449 450 add_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 ); 451 update_blog_details( $blog_id, array( 'deleted' => 1 ) ); 452 $blog = get_blog_details( $blog_id ); 453 415 454 $this->assertEquals( '1', $blog->deleted ); 416 $this->assertEquals( 5, $test_action_counter );417 418 // Same again419 $result =update_blog_details( $blog_id, array( 'deleted' => 1 ) );420 $ this->assertTrue( $result);421 $blog = get_blog_details( $blog_id ); 455 $this->assertEquals( 1, $test_action_counter ); 456 457 // The action should not fire if the status of 'deleted' stays the same. 458 update_blog_details( $blog_id, array( 'deleted' => 1 ) ); 459 $blog = get_blog_details( $blog_id ); 460 422 461 $this->assertEquals( '1', $blog->deleted ); 423 $this->assertEquals( 5, $test_action_counter ); 424 remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 425 426 add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 427 $result = update_blog_details( $blog_id, array( 'deleted' => 0 ) ); 428 $this->assertTrue( $result ); 429 $blog = get_blog_details( $blog_id ); 462 $this->assertEquals( 1, $test_action_counter ); 463 464 remove_action( 'make_delete_blog', array( $this, '_action_counter_cb' ), 10 ); 465 } 466 467 function test_update_blog_details_make_undelete_blog_action() { 468 global $test_action_counter; 469 $test_action_counter = 0; 470 471 $blog_id = $this->factory->blog->create( array( 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 472 update_blog_details( $blog_id, array( 'deleted' => 1 ) ); 473 474 add_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 ); 475 update_blog_details( $blog_id, array( 'deleted' => 0 ) ); 476 $blog = get_blog_details( $blog_id ); 477 430 478 $this->assertEquals( '0', $blog->deleted ); 431 $this->assertEquals( 6, $test_action_counter );432 433 // Same again434 $result =update_blog_details( $blog_id, array( 'deleted' => 0 ) );435 $ this->assertTrue( $result);436 $blog = get_blog_details( $blog_id ); 479 $this->assertEquals( 1, $test_action_counter ); 480 481 // The action should not fire if the status of 'deleted' stays the same. 482 update_blog_details( $blog_id, array( 'deleted' => 0 ) ); 483 $blog = get_blog_details( $blog_id ); 484 437 485 $this->assertEquals( '0', $blog->deleted ); 438 $this->assertEquals( 6, $test_action_counter ); 439 remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 440 441 add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 442 $result = update_blog_details( $blog_id, array( 'mature' => 1 ) ); 443 $this->assertTrue( $result ); 444 $blog = get_blog_details( $blog_id ); 486 $this->assertEquals( 1, $test_action_counter ); 487 488 remove_action( 'make_undelete_blog', array( $this, '_action_counter_cb' ), 10 ); 489 } 490 491 function test_update_blog_details_mature_blog_action() { 492 global $test_action_counter; 493 $test_action_counter = 0; 494 495 $blog_id = $this->factory->blog->create( array( 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 496 497 add_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 ); 498 update_blog_details( $blog_id, array( 'mature' => 1 ) ); 499 $blog = get_blog_details( $blog_id ); 500 445 501 $this->assertEquals( '1', $blog->mature ); 446 $this->assertEquals( 7, $test_action_counter );447 448 // Same again449 $result =update_blog_details( $blog_id, array( 'mature' => 1 ) );450 $ this->assertTrue( $result);451 $blog = get_blog_details( $blog_id ); 502 $this->assertEquals( 1, $test_action_counter ); 503 504 // The action should not fire if the status of 'mature' stays the same. 505 update_blog_details( $blog_id, array( 'mature' => 1 ) ); 506 $blog = get_blog_details( $blog_id ); 507 452 508 $this->assertEquals( '1', $blog->mature ); 453 $this->assertEquals( 7, $test_action_counter ); 454 remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 455 456 add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 457 $result = update_blog_details( $blog_id, array( 'mature' => 0 ) ); 458 $this->assertTrue( $result ); 509 $this->assertEquals( 1, $test_action_counter ); 510 511 remove_action( 'mature_blog', array( $this, '_action_counter_cb' ), 10 ); 512 } 513 514 function test_update_blog_details_unmature_blog_action() { 515 global $test_action_counter; 516 $test_action_counter = 0; 517 518 $blog_id = $this->factory->blog->create( array( 'path' => '/test_blogpath', 'title' => 'Test Title' ) ); 519 update_blog_details( $blog_id, array( 'mature' => 1 ) ); 520 521 add_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 ); 522 update_blog_details( $blog_id, array( 'mature' => 0 ) ); 523 459 524 $blog = get_blog_details( $blog_id ); 460 525 $this->assertEquals( '0', $blog->mature ); 461 $this->assertEquals( 8, $test_action_counter );462 463 // Same again464 $result =update_blog_details( $blog_id, array( 'mature' => 0 ) );465 $ this->assertTrue( $result);466 $blog = get_blog_details( $blog_id ); 526 $this->assertEquals( 1, $test_action_counter ); 527 528 // The action should not fire if the status of 'mature' stays the same. 529 update_blog_details( $blog_id, array( 'mature' => 0 ) ); 530 $blog = get_blog_details( $blog_id ); 531 467 532 $this->assertEquals( '0', $blog->mature ); 468 $this->assertEquals( 8, $test_action_counter ); 469 remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10, 1 ); 470 } 471 472 function _action_counter_cb( $blog_id ) { 533 $this->assertEquals( 1, $test_action_counter ); 534 535 remove_action( 'unmature_blog', array( $this, '_action_counter_cb' ), 10 ); 536 } 537 538 /** 539 * Provide a counter to determine that hooks are firing when intended. 540 */ 541 function _action_counter_cb() { 473 542 global $test_action_counter; 474 543 $test_action_counter++;
Note: See TracChangeset
for help on using the changeset viewer.