Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 116 additions & 0 deletions tests/phpunit/tests/rest-api/restAreValuesEqual.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?php

/**
* Tests for rest_are_values_equal().
*
* @group restapi
*
* @covers ::rest_are_values_equal
*/
class Tests_REST_API_RestAreValuesEqual extends WP_UnitTestCase {

/**
* @ticket 65819
*
* @dataProvider data_equal_values
*
* @param mixed $value1 First value.
* @param mixed $value2 Second value.
*/
public function test_returns_true_for_equal_values( $value1, $value2 ) {
$this->assertTrue( rest_are_values_equal( $value1, $value2 ) );
}

/**
* Data provider.
*
* @return array[]
*/
public static function data_equal_values() {
return array(
'same strings' => array( 'hello', 'hello' ),
'same integers' => array( 7, 7 ),
'integer and float' => array( 1, 1.0 ),
'float and integer' => array( 1.0, 1 ),
'same booleans' => array( true, true ),
'both null' => array( null, null ),
'same lists' => array( array( 1, 2 ), array( 1, 2 ) ),
'objects with null property' => array(
array(
'a' => null,
'b' => 1,
),
array(
'a' => null,
'b' => 1,
),
),
'same objects different key order' => array(
array(
'a' => 1,
'b' => 2,
),
array(
'b' => 2,
'a' => 1,
),
),
'nested coercion and key order' => array(
array(
'items' => array(
1,
array(
'x' => 2,
'y' => 3.0,
),
),
),
array(
'items' => array(
1.0,
array(
'y' => 3,
'x' => 2.0,
),
),
),
),
);
}

/**
* @ticket 65819
*
* @dataProvider data_unequal_values
*
* @param mixed $value1 First value.
* @param mixed $value2 Second value.
*/
public function test_returns_false_for_unequal_values( $value1, $value2 ) {
$this->assertFalse( rest_are_values_equal( $value1, $value2 ) );
}

/**
* Data provider.
*
* @return array[]
*/
public static function data_unequal_values() {
return array(
'different strings' => array( 'hello', 'world' ),
'string and integer' => array( '1', 1 ),
'integer and float' => array( 1, 2.0 ),
'float and integer' => array( 2.0, 1 ),
'different list order' => array( array( 1, 2 ), array( 2, 1 ) ),
'different counts' => array( array( 1 ), array( 1, 2 ) ),
'missing object key' => array(
array( 'a' => 1 ),
array( 'b' => 1 ),
),
'nested mismatch' => array(
array( 'items' => array( 1, 2 ) ),
array( 'items' => array( 1, 3 ) ),
),
);
}
}
Loading