summaryrefslogtreecommitdiffstatshomepage
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/phpunit/tests/basic.php71
1 files changed, 71 insertions, 0 deletions
diff --git a/tests/phpunit/tests/basic.php b/tests/phpunit/tests/basic.php
index 954751d99e..0f8c001600 100644
--- a/tests/phpunit/tests/basic.php
+++ b/tests/phpunit/tests/basic.php
@@ -8,6 +8,8 @@
class Tests_Basic extends WP_UnitTestCase {
/**
+ * Test copyright year in license.txt.
+ *
* @coversNothing
*/
public function test_license() {
@@ -23,6 +25,8 @@ class Tests_Basic extends WP_UnitTestCase {
}
/**
+ * Test latest stable version is included in SECURITY.md.
+ *
* @coversNothing
*/
public function test_security_md() {
@@ -39,6 +43,8 @@ class Tests_Basic extends WP_UnitTestCase {
}
/**
+ * Test the version number in package.json is correct.
+ *
* @coversNothing
*/
public function test_package_json() {
@@ -57,6 +63,8 @@ class Tests_Basic extends WP_UnitTestCase {
}
/**
+ * Test engines.node is included in package.json.
+ *
* @depends test_package_json
*
* @coversNothing
@@ -65,4 +73,67 @@ class Tests_Basic extends WP_UnitTestCase {
$this->assertArrayHasKey( 'engines', $package_json );
$this->assertArrayHasKey( 'node', $package_json['engines'] );
}
+
+ /**
+ * Test the version numbers in package-lock.json are correct.
+ *
+ * In pull requests, the package-lock.json file is updated automatically
+ * to match the version in package.json. This test is intended to ensure
+ * the version numbers are correct in production branches.
+ *
+ * @coversNothing
+ *
+ * @dataProvider data_package_lock_json
+ */
+ public function test_package_lock_json( $path ) {
+ $package_lock_json = file_get_contents( dirname( ABSPATH ) . '/package-lock.json' );
+ $package_lock_json = json_decode( $package_lock_json, true );
+ list( $version ) = explode( '-', $GLOBALS['wp_version'] );
+
+ // package-lock.json uses x.y.z, so fill cleaned $wp_version for .0 releases.
+ if ( 1 === substr_count( $version, '.' ) ) {
+ $version .= '.0';
+ }
+
+ $json_paths = explode( '.', $path );
+ $package_lock_version = $package_lock_json;
+ foreach ( $json_paths as $json_path ) {
+ if ( ! isset( $package_lock_version[ $json_path ] ) ) {
+ $this->fail( "package-lock.json does not contain the path '$path'." );
+ }
+ $package_lock_version = $package_lock_version[ $json_path ];
+ }
+
+ $this->assertSame( $version, $package_lock_version, "package-lock.json's $path needs to be updated to $version." );
+ }
+
+ /**
+ * Data provider for test_package_lock_json.
+ *
+ * @return array[] Data provider.
+ */
+ public function data_package_lock_json() {
+ return array(
+ 'top level' => array( 'version' ),
+ 'package' => array( 'packages..version' ),
+ );
+ }
+
+ /**
+ * Test the version number in composer.json is correct.
+ *
+ * @coversNothing
+ */
+ public function test_composer_json() {
+ $composer_json = file_get_contents( dirname( ABSPATH ) . '/composer.json' );
+ $composer_json = json_decode( $composer_json, true );
+ list( $version ) = explode( '-', $GLOBALS['wp_version'] );
+
+ // composer.json uses x.y.z, so fill cleaned $wp_version for .0 releases.
+ if ( 1 === substr_count( $version, '.' ) ) {
+ $version .= '.0';
+ }
+
+ $this->assertSame( $version, $composer_json['version'], "composer.json's version needs to be updated to $version." );
+ }
}