Skip to content

Commit

Permalink
Add method for finding relative WP major version
Browse files Browse the repository at this point in the history
  • Loading branch information
ernilambar committed Dec 4, 2024
1 parent 1ab4ff3 commit b72a97b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
19 changes: 19 additions & 0 deletions includes/Traits/Version_Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,25 @@ protected function get_php_recommended_version(): string {
return $recommended_version;
}

/**
* Returns relative WordPress major version.
*
* @since 1.4.0
*
* @param string $version WordPress major version.
* @param int $steps Steps to find relative version. Defaults to 1 for next major version.
* @return string Relative WordPress major version.
*/
protected function get_wordpress_relative_major_version( string $version, int $steps = 1 ): string {
if ( 0 === $steps ) {
return $version;

Check warning on line 106 in includes/Traits/Version_Utils.php

View check run for this annotation

Codecov / codecov/patch

includes/Traits/Version_Utils.php#L106

Added line #L106 was not covered by tests
}

$new_version = floatval( $version ) + ( 0.1 * $steps );

return (string) number_format( $new_version, 1 );
}

/**
* Returns specific information.
*
Expand Down
23 changes: 23 additions & 0 deletions tests/phpunit/tests/Traits/Version_Utils_Tests.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,32 @@ public function test_wordpress_recommended_php_version() {
$this->assertSame( '7.4', $version );
}

/**
* @dataProvider data_wordpress_version_items
*/
public function test_wordpress_relative_major_version( $version, $steps, $new_version ) {
$result = $this->get_wordpress_relative_major_version( $version, $steps );
$this->assertSame( $new_version, $result );
}

public function tear_down() {
delete_transient( $this->info_transient_key );
delete_site_transient( $this->php_check_transient_key );
parent::tear_down();
}

public function data_wordpress_version_items() {
return array(
array( '6.7', 1, '6.8' ),
array( '6.7', -1, '6.6' ),
array( '6.7', 2, '6.9' ),
array( '6.7', -2, '6.5' ),
array( '5.9', 1, '6.0' ),
array( '6.0', -1, '5.9' ),
array( '5.9', 2, '6.1' ),
array( '6.0', -2, '5.8' ),
array( '5.8', 2, '6.0' ),
array( '6.1', -2, '5.9' ),
);
}
}

0 comments on commit b72a97b

Please sign in to comment.