wordpress-develop/tests/phpunit/tests/diff/wpTextDiffRendererTable.php
Tonya Mork 9de414277e Code Modernization: Use wp_trigger_error() in WP_Text_Diff_Renderer_Table magic methods.
Replaces `trigger_error()` with `wp_trigger_error()` in each of the `WP_Text_Diff_Renderer_Table` magic methods.

[56354] added the dynamic properties deprecation messages to the `__get()`, `__set()`, `__isset()`, `__unset()` magic methods. Since that commit, `wp_trigger_error()` was introduced (see [56530]) as a wrapper for `trigger_error()`.

Follow-up to [56354], [56530].

See #58898, #57686.

git-svn-id: https://develop.svn.wordpress.org/trunk@56544 602fd350-edb4-49c9-b593-d223f7449a82
2023-09-07 20:46:53 +00:00

166 lines
4.9 KiB
PHP

<?php
/**
* Tests for WP_Text_Diff_Renderer_Table.
*
* @group diff
*/
class Tests_Diff_WpTextDiffRendererTable extends WP_UnitTestCase {
/**
* @var WP_Text_Diff_Renderer_Table
*/
private $diff_renderer_table;
public static function set_up_before_class() {
parent::set_up_before_class();
require_once ABSPATH . 'wp-includes/Text/Diff/Renderer.php';
require_once ABSPATH . 'wp-includes/class-wp-text-diff-renderer-table.php';
}
public function set_up() {
parent::set_up();
$this->diff_renderer_table = new WP_Text_Diff_Renderer_Table();
}
/**
* @dataProvider data_compat_fields
* @ticket 58898
*
* @covers WP_Text_Diff_Renderer_Table::__get()
*
* @param string $property_name Property name to get.
* @param mixed $expected Expected value.
*/
public function test_should_get_compat_fields( $property_name, $expected ) {
$this->assertSame( $expected, $this->diff_renderer_table->$property_name );
}
/**
* @ticket 58898
*
* @covers WP_Text_Diff_Renderer_Table::__get()
*/
public function test_should_throw_deprecation_when_getting_dynamic_property() {
$this->expectDeprecation();
$this->expectDeprecationMessage(
'WP_Text_Diff_Renderer_Table::__get(): ' .
'The property `undeclared_property` is not declared. Getting a dynamic property is ' .
'deprecated since version 6.4.0! Instead, declare the property on the class.'
);
$this->assertNull( $this->diff_renderer_table->undeclared_property, 'Getting a dynamic property should return null from WP_Text_Diff_Renderer_Table::__get()' );
}
/**
* @dataProvider data_compat_fields
* @ticket 58898
*
* @covers WP_Text_Diff_Renderer_Table::__set()
*
* @param string $property_name Property name to set.
*/
public function test_should_set_compat_fields( $property_name ) {
$value = uniqid();
$this->diff_renderer_table->$property_name = $value;
$this->assertSame( $value, $this->diff_renderer_table->$property_name );
}
/**
* @ticket 58898
*
* @covers WP_Text_Diff_Renderer_Table::__set()
*/
public function test_should_throw_deprecation_when_setting_dynamic_property() {
$this->expectDeprecation();
$this->expectDeprecationMessage(
'WP_Text_Diff_Renderer_Table::__set(): ' .
'The property `undeclared_property` is not declared. Setting a dynamic property is ' .
'deprecated since version 6.4.0! Instead, declare the property on the class.'
);
$this->diff_renderer_table->undeclared_property = 'some value';
}
/**
* @dataProvider data_compat_fields
* @ticket 58898
*
* @covers WP_Text_Diff_Renderer_Table::__isset()
*
* @param string $property_name Property name to check.
* @param mixed $expected Expected value.
*/
public function test_should_isset_compat_fields( $property_name, $expected ) {
$actual = isset( $this->diff_renderer_table->$property_name );
if ( is_null( $expected ) ) {
$this->assertFalse( $actual );
} else {
$this->assertTrue( $actual );
}
}
/**
* @ticket 58898
*
* @covers WP_Text_Diff_Renderer_Table::__isset()
*/
public function test_should_throw_deprecation_when_isset_of_dynamic_property() {
$this->expectDeprecation();
$this->expectDeprecationMessage(
'WP_Text_Diff_Renderer_Table::__isset(): ' .
'The property `undeclared_property` is not declared. Checking `isset()` on a dynamic property ' .
'is deprecated since version 6.4.0! Instead, declare the property on the class.'
);
$this->assertFalse( isset( $this->diff_renderer_table->undeclared_property ), 'Checking a dynamic property should return false from WP_Text_Diff_Renderer_Table::__isset()' );
}
/**
* @dataProvider data_compat_fields
* @ticket 58898
*
* @covers WP_Text_Diff_Renderer_Table::__unset()
*
* @param string $property_name Property name to unset.
*/
public function test_should_unset_compat_fields( $property_name ) {
unset( $this->diff_renderer_table->$property_name );
$this->assertFalse( isset( $this->diff_renderer_table->$property_name ) );
}
/**
* @ticket 58898
*
* @covers WP_Text_Diff_Renderer_Table::__unset()
*/
public function test_should_throw_deprecation_when_unset_of_dynamic_property() {
$this->expectDeprecation();
$this->expectDeprecationMessage(
'WP_Text_Diff_Renderer_Table::__unset(): ' .
'A property `undeclared_property` is not declared. Unsetting a dynamic property is ' .
'deprecated since version 6.4.0! Instead, declare the property on the class.'
);
unset( $this->diff_renderer_table->undeclared_property );
}
/**
* Data provider.
*
* @return array
*/
public function data_compat_fields() {
return array(
'_show_split_view' => array(
'property_name' => '_show_split_view',
'expected' => true,
),
'inline_diff_renderer' => array(
'property_name' => 'inline_diff_renderer',
'expected' => 'WP_Text_Diff_Renderer_inline',
),
'_diff_threshold' => array(
'property_name' => '_diff_threshold',
'expected' => 0.6,
),
);
}
}