BlogInfo.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * @group formatting
  4. */
  5. class Tests_Formatting_BlogInfo extends WP_UnitTestCase {
  6. /**
  7. * @dataProvider locales
  8. * @ticket 28303
  9. */
  10. function test_get_bloginfo_language( $test_locale, $expected ) {
  11. global $locale;
  12. $old_locale = $locale;
  13. $locale = $test_locale;
  14. $this->assertSame( $expected, get_bloginfo( 'language' ) );
  15. $locale = $old_locale;
  16. }
  17. function locales() {
  18. return array(
  19. // Locale, language code.
  20. array( 'en_US', 'en-US' ),
  21. array( 'ar', 'ar' ),
  22. array( 'de_DE', 'de-DE' ),
  23. array( 'de_DE_formal', 'de-DE-formal' ),
  24. array( 'oci', 'oci' ),
  25. array( 'pt_PT_ao1990', 'pt-PT-ao1990' ),
  26. array( 'ja_JP', 'ja-JP' ),
  27. );
  28. }
  29. /**
  30. * @ticket 27942
  31. */
  32. function test_bloginfo_sanitize_option() {
  33. $old_values = array(
  34. 'blogname' => get_option( 'blogname' ),
  35. 'blogdescription' => get_option( 'blogdescription' ),
  36. );
  37. $values = array(
  38. 'foo' => 'foo',
  39. '<em>foo</em>' => '&lt;em&gt;foo&lt;/em&gt;',
  40. '<script>foo</script>' => '&lt;script&gt;foo&lt;/script&gt;',
  41. '&lt;foo&gt;' => '&lt;foo&gt;',
  42. '<foo' => '&lt;foo',
  43. );
  44. foreach ( $values as $value => $expected ) {
  45. $sanitized_value = sanitize_option( 'blogname', $value );
  46. update_option( 'blogname', $sanitized_value );
  47. $this->assertSame( $expected, $sanitized_value );
  48. $this->assertSame( $expected, get_bloginfo( 'name' ) );
  49. $this->assertSame( $expected, get_bloginfo( 'name', 'display' ) );
  50. $sanitized_value = sanitize_option( 'blogdescription', $value );
  51. update_option( 'blogdescription', $sanitized_value );
  52. $this->assertSame( $expected, $sanitized_value );
  53. $this->assertSame( $expected, get_bloginfo( 'description' ) );
  54. $this->assertSame( $expected, get_bloginfo( 'description', 'display' ) );
  55. }
  56. // Restore old values.
  57. foreach ( $old_values as $option_name => $value ) {
  58. update_option( $option_name, $value );
  59. }
  60. }
  61. }