Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a unit test for wp_recursive_ksort #40149

Merged
merged 2 commits into from
Apr 7, 2022
Merged
Changes from 1 commit
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
87 changes: 87 additions & 0 deletions phpunit/functions-test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/**
* Test functions.php
*
* @package Gutenberg
*/

class WP_Functions_Test extends WP_UnitTestCase {
function test_wp_recursive_ksort() {
$theme_json = array(
"version" => 1,
"settings" => array(
"typography" => array(
"fontFamilies" => array(
"fontFamily" => "\"DM Sans\", sans-serif",
"slug" => "dm-sans",
"name" => "DM Sans",
),
),
"color" => array(
"palette" => array(
array(
"slug" => "foreground",
"color" => "#242321",
"name" => "Foreground",
),
array(
"slug" => "background",
"color" => "#FCFBF8",
"name" => "Background",
),
array(
"slug" => "primary",
"color" => "#71706E",
"name" => "Primary",
),
array(
"slug" => "tertiary",
"color" => "#CFCFCF",
"name" => "Tertiary",
),
),
),
),
);

$sorted_theme_json = wp_recursive_ksort( $theme_json );
$expected_theme_json = array(
"settings" => array(
"color" => array(
"palette" => array(
array(
"color" => "#242321",
"name" => "Foreground",
"slug" => "foreground",
),
array(
"color" => "#FCFBF8",
"name" => "Background",
"slug" => "background",
),
array(
"color" => "#71706E",
"name" => "Primary",
"slug" => "primary",
),
array(
"color" => "#CFCFCF",
"name" => "Tertiary",
"slug" => "tertiary",
),
),
),
"typography" => array(
"fontFamilies" => array(
"fontFamily" => "\"DM Sans\", sans-serif",
"name" => "DM Sans",
"slug" => "dm-sans",
),
),
),
"version" => 1,
);
$this->assertEquals( $sorted_theme_json, $expected_theme_json );
}
}