Files
wordpress-develop/tests/phpunit/tests/functions/canonicalCharset.php
T
Tonya Mork 40ac5de838 Coding Standards: Add visibility to methods in tests/phpunit/tests/.
Adds a `public` visibility to test fixtures, tests, data providers, and callbacks methods.

Adds a `private` visibility to helper methods within test classes.

Renames callbacks and helpers that previously started with a `_` prefix. Why? For consistency and to leverage using the method visibility. Further naming standardizations is beyond the scope of this commit.

Props costdev, jrf, hellofromTonya.
Fixes #54177.

git-svn-id: https://develop.svn.wordpress.org/trunk@52010 602fd350-edb4-49c9-b593-d223f7449a82
2021-11-04 15:22:47 +00:00

93 lines
2.5 KiB
PHP

<?php
/**
* Validate that badly named charsets always return the correct format for UTF-8 and ISO-8859-1.
*
* @since 4.8.0
*
* @group functions.php
* @covers ::_canonical_charset
*/
class Tests_Functions_CanonicalCharset extends WP_UnitTestCase {
public function test_utf_8_lower() {
$this->assertSame( 'UTF-8', _canonical_charset( 'utf-8' ) );
}
public function test_utf_8_upper() {
$this->assertSame( 'UTF-8', _canonical_charset( 'UTF-8' ) );
}
public function test_utf_8_mixxed() {
$this->assertSame( 'UTF-8', _canonical_charset( 'Utf-8' ) );
}
public function test_utf_8() {
$this->assertSame( 'UTF-8', _canonical_charset( 'UTF8' ) );
}
public function test_iso_lower() {
$this->assertSame( 'ISO-8859-1', _canonical_charset( 'iso-8859-1' ) );
}
public function test_iso_upper() {
$this->assertSame( 'ISO-8859-1', _canonical_charset( 'ISO-8859-1' ) );
}
public function test_iso_mixxed() {
$this->assertSame( 'ISO-8859-1', _canonical_charset( 'Iso8859-1' ) );
}
public function test_iso() {
$this->assertSame( 'ISO-8859-1', _canonical_charset( 'ISO8859-1' ) );
}
public function test_random() {
$this->assertSame( 'random', _canonical_charset( 'random' ) );
}
public function test_empty() {
$this->assertSame( '', _canonical_charset( '' ) );
}
/**
* @ticket 23688
*
* @covers ::get_option
*/
public function test_update_option_blog_charset() {
$orig_blog_charset = get_option( 'blog_charset' );
update_option( 'blog_charset', 'utf8' );
$this->assertSame( 'UTF-8', get_option( 'blog_charset' ) );
update_option( 'blog_charset', 'utf-8' );
$this->assertSame( 'UTF-8', get_option( 'blog_charset' ) );
update_option( 'blog_charset', 'UTF8' );
$this->assertSame( 'UTF-8', get_option( 'blog_charset' ) );
update_option( 'blog_charset', 'UTF-8' );
$this->assertSame( 'UTF-8', get_option( 'blog_charset' ) );
update_option( 'blog_charset', 'ISO-8859-1' );
$this->assertSame( 'ISO-8859-1', get_option( 'blog_charset' ) );
update_option( 'blog_charset', 'ISO8859-1' );
$this->assertSame( 'ISO-8859-1', get_option( 'blog_charset' ) );
update_option( 'blog_charset', 'iso8859-1' );
$this->assertSame( 'ISO-8859-1', get_option( 'blog_charset' ) );
update_option( 'blog_charset', 'iso-8859-1' );
$this->assertSame( 'ISO-8859-1', get_option( 'blog_charset' ) );
// Arbitrary strings are passed through.
update_option( 'blog_charset', 'foobarbaz' );
$this->assertSame( 'foobarbaz', get_option( 'blog_charset' ) );
update_option( 'blog_charset', $orig_blog_charset );
}
}