diff --git a/tests/phpunit/tests/functions/isPhpVersionCompatible.php b/tests/phpunit/tests/functions/isPhpVersionCompatible.php
index abbd03e08d..f7063f45d5 100644
|
a
|
b
|
|
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | | * Tests the is_php_version_compatible function. |
| | 4 | * Tests the is_php_version_compatible() function. |
| 5 | 5 | * |
| 6 | 6 | * @group functions.php |
| 7 | 7 | * @covers ::is_php_version_compatible |
| 8 | 8 | */ |
| 9 | | class Tests_Functions_isPhpVersionCompatible extends WP_UnitTestCase { |
| | 9 | class Tests_Functions_IsPhpVersionCompatible extends WP_UnitTestCase { |
| 10 | 10 | /** |
| 11 | 11 | * Tests is_php_version_compatible(). |
| 12 | 12 | * |
| 13 | 13 | * @dataProvider data_is_php_version_compatible |
| 14 | 14 | * |
| 15 | | * @param mixed $test_value |
| 16 | | * @param bool $expected |
| 17 | | * |
| 18 | 15 | * @ticket 54257 |
| | 16 | * |
| | 17 | * @param mixed $required The minimum required PHP version. |
| | 18 | * @param bool $expected The expected result. |
| 19 | 19 | */ |
| 20 | | public function test_is_php_version_compatible( $test_value, $expected ) { |
| 21 | | $this->assertSame( is_php_version_compatible( $test_value ), $expected ); |
| | 20 | public function test_is_php_version_compatible( $required, $expected ) { |
| | 21 | $this->assertSame( $expected, is_php_version_compatible( $required ) ); |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
| 25 | | * Provides test scenarios for test_php_version_compatible. |
| | 25 | * Data provider. |
| 26 | 26 | * |
| 27 | 27 | * @return array |
| 28 | 28 | */ |
| 29 | | function data_is_php_version_compatible() { |
| | 29 | public function data_is_php_version_compatible() { |
| 30 | 30 | $php_version = phpversion(); |
| 31 | 31 | |
| 32 | | $more = explode( '.', $php_version ); |
| 33 | | $less = $more; |
| | 32 | $lower = explode( '.', $php_version ); |
| | 33 | $higher = $lower; |
| 34 | 34 | |
| 35 | | -- $less[ count( $less ) - 1 ]; |
| 36 | | ++ $more[ count( $less ) - 1 ]; |
| | 35 | --$lower[ count( $lower ) - 1 ]; |
| | 36 | ++$higher[ count( $higher ) - 1 ]; |
| 37 | 37 | |
| 38 | 38 | return array( |
| 39 | | 'greater' => array( |
| 40 | | 'test_value' => implode( '.', $more ), |
| 41 | | 'expected' => false, |
| | 39 | // Happy paths. |
| | 40 | 'a lower required version' => array( |
| | 41 | 'required' => implode( '.', $lower ), |
| | 42 | 'expected' => true, |
| | 43 | ), |
| | 44 | 'the same version' => array( |
| | 45 | 'required' => $php_version, |
| | 46 | 'expected' => true, |
| | 47 | ), |
| | 48 | 'a higher required version' => array( |
| | 49 | 'required' => implode( '.', $higher ), |
| | 50 | 'expected' => false, |
| | 51 | ), |
| | 52 | |
| | 53 | // Falsey values. |
| | 54 | 'false' => array( |
| | 55 | 'required' => false, |
| | 56 | 'expected' => true, |
| | 57 | ), |
| | 58 | 'null' => array( |
| | 59 | 'required' => null, |
| | 60 | 'expected' => true, |
| | 61 | ), |
| | 62 | '0 int' => array( |
| | 63 | 'required' => 0, |
| | 64 | 'expected' => true, |
| | 65 | ), |
| | 66 | '0.0 float' => array( |
| | 67 | 'required' => 0.0, |
| | 68 | 'expected' => true, |
| | 69 | ), |
| | 70 | '0 string' => array( |
| | 71 | 'required' => '0', |
| | 72 | 'expected' => true, |
| 42 | 73 | ), |
| 43 | | 'same' => array( |
| 44 | | 'test_value' => $php_version, |
| 45 | | 'expected' => true, |
| | 74 | 'empty string' => array( |
| | 75 | 'required' => '', |
| | 76 | 'expected' => true, |
| 46 | 77 | ), |
| 47 | | 'less' => array( |
| 48 | | 'test_value' => implode( '.', $less ), |
| 49 | | 'expected' => true, |
| | 78 | 'empty array' => array( |
| | 79 | 'required' => array(), |
| | 80 | 'expected' => true, |
| 50 | 81 | ), |
| 51 | 82 | ); |
| 52 | 83 | } |
diff --git a/tests/phpunit/tests/functions/isWpVersionCompatible.php b/tests/phpunit/tests/functions/isWpVersionCompatible.php
index dfec2a37cb..106822f708 100644
|
a
|
b
|
|
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | /** |
| 4 | | * Tests the is_php_version_compatible function. |
| | 4 | * Tests the is_wp_version_compatible() function. |
| 5 | 5 | * |
| 6 | 6 | * @group functions.php |
| 7 | 7 | * @covers ::is_wp_version_compatible |
| 8 | 8 | */ |
| 9 | | class Tests_Functions_isWpVersionCompatible extends WP_UnitTestCase { |
| | 9 | class Tests_Functions_IsWpVersionCompatible extends WP_UnitTestCase { |
| 10 | 10 | /** |
| 11 | | * Test is_wp_version_compatible(). |
| | 11 | * Tests is_wp_version_compatible(). |
| 12 | 12 | * |
| 13 | 13 | * @dataProvider data_is_wp_version_compatible |
| 14 | 14 | * |
| 15 | | * @param mixed $test_value |
| 16 | | * @param bool $expected |
| | 15 | * @ticket 54257 |
| | 16 | * |
| | 17 | * @param mixed $required The minimum required WordPress version. |
| | 18 | * @param bool $expected The expected result. |
| | 19 | */ |
| | 20 | public function test_is_wp_version_compatible( $required, $expected ) { |
| | 21 | $this->assertSame( $expected, is_wp_version_compatible( $required ) ); |
| | 22 | } |
| | 23 | |
| | 24 | /** |
| | 25 | * Data provider. |
| | 26 | * |
| | 27 | * @return array |
| | 28 | */ |
| | 29 | public function data_is_wp_version_compatible() { |
| | 30 | global $wp_version; |
| | 31 | |
| | 32 | $lower = explode( '.', $wp_version ); |
| | 33 | $higher = $lower; |
| | 34 | |
| | 35 | --$lower[0]; |
| | 36 | ++$higher[0]; |
| | 37 | |
| | 38 | return array( |
| | 39 | // Happy paths. |
| | 40 | 'the same version' => array( |
| | 41 | 'required' => $wp_version, |
| | 42 | 'expected' => true, |
| | 43 | ), |
| | 44 | 'a lower required version' => array( |
| | 45 | 'required' => implode( '.', $lower ), |
| | 46 | 'expected' => true, |
| | 47 | ), |
| | 48 | 'a higher required version' => array( |
| | 49 | 'required' => implode( '.', $higher ), |
| | 50 | 'expected' => false, |
| | 51 | ), |
| | 52 | |
| | 53 | // Falsey values. |
| | 54 | 'false' => array( |
| | 55 | 'required' => false, |
| | 56 | 'expected' => true, |
| | 57 | ), |
| | 58 | 'null' => array( |
| | 59 | 'required' => null, |
| | 60 | 'expected' => true, |
| | 61 | ), |
| | 62 | '0 int' => array( |
| | 63 | 'required' => 0, |
| | 64 | 'expected' => true, |
| | 65 | ), |
| | 66 | '0.0 float' => array( |
| | 67 | 'required' => 0.0, |
| | 68 | 'expected' => true, |
| | 69 | ), |
| | 70 | '0 string' => array( |
| | 71 | 'required' => '0', |
| | 72 | 'expected' => true, |
| | 73 | ), |
| | 74 | 'empty string' => array( |
| | 75 | 'required' => '', |
| | 76 | 'expected' => true, |
| | 77 | ), |
| | 78 | 'empty array' => array( |
| | 79 | 'required' => array(), |
| | 80 | 'expected' => true, |
| | 81 | ), |
| | 82 | ); |
| | 83 | } |
| | 84 | |
| | 85 | /** |
| | 86 | * Tests is_wp_version_compatible() with development versions. |
| | 87 | * |
| | 88 | * @dataProvider data_is_wp_version_compatible_with_development_versions |
| 17 | 89 | * |
| 18 | 90 | * @ticket 54257 |
| | 91 | * |
| | 92 | * @param string $required The minimum required WordPress version. |
| | 93 | * @param string $wp The value for the $wp_version global variable. |
| | 94 | * @param bool $expected The expected result. |
| 19 | 95 | */ |
| 20 | | public function test_is_wp_version_compatible( $test_value, $expected ) { |
| 21 | | $this->assertSame( is_wp_version_compatible( $test_value ), $expected ); |
| | 96 | public function test_is_wp_version_compatible_with_development_versions( $required, $wp, $expected ) { |
| | 97 | global $wp_version; |
| | 98 | |
| | 99 | $original_version = $wp_version; |
| | 100 | $wp_version = $wp; |
| | 101 | $actual = is_wp_version_compatible( $required ); |
| | 102 | |
| | 103 | // Reset the version before the assertion in case of failure. |
| | 104 | $wp_version = $original_version; |
| | 105 | |
| | 106 | $this->assertSame( $expected, $actual ); |
| 22 | 107 | } |
| 23 | 108 | |
| 24 | 109 | /** |
| 25 | | * Provides test scenarios test_is_wp_version_compatible. |
| | 110 | * Data provider. |
| 26 | 111 | * |
| 27 | 112 | * @return array |
| 28 | 113 | */ |
| 29 | | function data_is_wp_version_compatible() { |
| 30 | | $wp_version = get_bloginfo( 'version' ); |
| | 114 | public function data_is_wp_version_compatible_with_development_versions() { |
| | 115 | global $wp_version; |
| 31 | 116 | |
| 32 | | $more = explode( '.', $wp_version ); |
| 33 | | $less = $more; |
| | 117 | // For consistent results, remove possible suffixes. |
| | 118 | list( $version ) = explode( '-', $wp_version ); |
| 34 | 119 | |
| 35 | | -- $less[0]; |
| 36 | | ++ $more[0]; |
| | 120 | $lower = explode( '.', $version ); |
| | 121 | $higher = $lower; |
| | 122 | |
| | 123 | --$lower[0]; |
| | 124 | ++$higher[0]; |
| 37 | 125 | |
| 38 | 126 | return array( |
| 39 | | 'greater' => array( |
| 40 | | 'test_value' => implode( '.', $more ), |
| 41 | | 'expected' => false, |
| | 127 | 'a lower required version and an alpha wordpress version' => array( |
| | 128 | 'required' => implode( '.', $lower ), |
| | 129 | 'wp' => $version . '-alpha-12341-src', |
| | 130 | 'expected' => true, |
| | 131 | ), |
| | 132 | 'a lower required version and a beta wordpress version' => array( |
| | 133 | 'required' => implode( '.', $lower ), |
| | 134 | 'wp' => $version . '-beta1', |
| | 135 | 'expected' => true, |
| | 136 | ), |
| | 137 | 'the same required version and an alpha wordpress version' => array( |
| | 138 | 'required' => $version, |
| | 139 | 'wp' => $version . '-alpha-12341-src', |
| | 140 | 'expected' => true, |
| | 141 | ), |
| | 142 | 'the same required version and a beta wordpress version' => array( |
| | 143 | 'required' => $version, |
| | 144 | 'wp' => $version . '-beta1', |
| | 145 | 'expected' => true, |
| 42 | 146 | ), |
| 43 | | 'same' => array( |
| 44 | | 'test_value' => $wp_version, |
| 45 | | 'expected' => true, |
| | 147 | 'a higher required version and an alpha wordpress version' => array( |
| | 148 | 'required' => implode( '.', $higher ), |
| | 149 | 'wp' => $version . '-alpha-12341-src', |
| | 150 | 'expected' => false, |
| 46 | 151 | ), |
| 47 | | 'less' => array( |
| 48 | | 'test_value' => implode( '.', $less ), |
| 49 | | 'expected' => true, |
| | 152 | 'a higher required version and a beta wordpress version' => array( |
| | 153 | 'required' => implode( '.', $higher ), |
| | 154 | 'wp' => $version . '-beta1', |
| | 155 | 'expected' => false, |
| 50 | 156 | ), |
| 51 | 157 | ); |
| 52 | 158 | } |