Files
wordpress/tests/phpunit/tests/basic.php
Sergey Biryukov 5880ac84cc Tests: Separate the tests in basic.php for clarity.
There were two kinds of tests in this file:

* Tests for content of some files in the root directory:
 * `license.txt`
 * `SECURITY.md`
 * `package.json`
* Tests for some utility functions of the test framework itself:
 * `strip_ws()`
 * `test_mask_input_value()`

The latter are now moved to their own file, `utils.php`.

Follow-up to [22/tests], [81/tests], [103/tests], [25240], [26940], [28064], [28480], [28493], [28523], [28631], [42381], [47403], [53683].

See #39265, #55652.

git-svn-id: https://develop.svn.wordpress.org/trunk@53686 602fd350-edb4-49c9-b593-d223f7449a82
2022-07-07 23:55:13 +00:00

69 lines
2.0 KiB
PHP

<?php
/**
* Test the content in some root directory files.
*
* @group basic
*/
class Tests_Basic extends WP_UnitTestCase {
/**
* @coversNothing
*/
public function test_license() {
// This test is designed to only run on trunk.
$this->skipOnAutomatedBranches();
$license = file_get_contents( ABSPATH . 'license.txt' );
preg_match( '#Copyright 2011-(\d+) by the contributors#', $license, $matches );
$license_year = trim( $matches[1] );
$this_year = gmdate( 'Y' );
$this->assertSame( $this_year, $license_year, "license.txt's year needs to be updated to $this_year." );
}
/**
* @coversNothing
*/
public function test_security_md() {
// This test is designed to only run on trunk.
$this->skipOnAutomatedBranches();
$security = file_get_contents( dirname( ABSPATH ) . '/SECURITY.md' );
preg_match_all( '#\d.\d.x#', $security, $matches );
$supported_versions = $matches[0];
$current_version = substr( $GLOBALS['wp_version'], 0, 3 );
$latest_stable = number_format( (float) $current_version - 0.1, 1 ) . '.x';
$this->assertContains( $latest_stable, $supported_versions, "SECURITY.md's version needs to be updated to $latest_stable." );
}
/**
* @coversNothing
*/
public function test_package_json() {
$package_json = file_get_contents( dirname( ABSPATH ) . '/package.json' );
$package_json = json_decode( $package_json, true );
list( $version ) = explode( '-', $GLOBALS['wp_version'] );
// package.json uses x.y.z, so fill cleaned $wp_version for .0 releases.
if ( 1 === substr_count( $version, '.' ) ) {
$version .= '.0';
}
$this->assertSame( $version, $package_json['version'], "package.json's version needs to be updated to $version." );
return $package_json;
}
/**
* @depends test_package_json
*
* @coversNothing
*/
public function test_package_json_node_engine( $package_json ) {
$this->assertArrayHasKey( 'engines', $package_json );
$this->assertArrayHasKey( 'node', $package_json['engines'] );
}
}