annotate core/tests/Drupal/Tests/Component/Version/ConstraintTest.php @ 5:12f9dff5fda9 tip

Update to Drupal core 8.7.1
author Chris Cannam
date Thu, 09 May 2019 15:34:47 +0100
parents
children
rev   line source
Chris@5 1 <?php
Chris@5 2
Chris@5 3 namespace Drupal\Tests\Component\Version;
Chris@5 4
Chris@5 5 use Drupal\Component\Version\Constraint;
Chris@5 6 use PHPUnit\Framework\TestCase;
Chris@5 7
Chris@5 8 /**
Chris@5 9 * @coversDefaultClass \Drupal\Component\Version\Constraint
Chris@5 10 * @group Version
Chris@5 11 */
Chris@5 12 class ConstraintTest extends TestCase {
Chris@5 13
Chris@5 14 /**
Chris@5 15 * @covers ::isCompatible
Chris@5 16 * @dataProvider providerIsCompatible
Chris@5 17 */
Chris@5 18 public function testIsCompatible(Constraint $version_info, $current_version, $result) {
Chris@5 19 $this->assertSame($result, $version_info->isCompatible($current_version));
Chris@5 20 }
Chris@5 21
Chris@5 22 /**
Chris@5 23 * Provider for testIsCompatible.
Chris@5 24 */
Chris@5 25 public function providerIsCompatible() {
Chris@5 26 $tests = [];
Chris@5 27
Chris@5 28 $tests['no-dependencies'] = [new Constraint('', '8.x'), '8.1.x', TRUE];
Chris@5 29
Chris@5 30 // Stable version.
Chris@5 31 $stable = new Constraint('8.x-1.0', '8.x');
Chris@5 32 $tests['(=8.x-1.0)-1.0'] = [$stable, '1.0', TRUE];
Chris@5 33 $tests['(=8.x-1.0)-1.1'] = [$stable, '1.1', FALSE];
Chris@5 34 $tests['(=8.x-1.0)-0.9'] = [$stable, '0.9', FALSE];
Chris@5 35
Chris@5 36 // Alpha version.
Chris@5 37 $alpha = new Constraint('8.x-1.1-alpha12', '8.x');
Chris@5 38 $tests['(8.x-1.1-alpha12)-alpha12'] = [$alpha, '1.1-alpha12', TRUE];
Chris@5 39 $tests['(8.x-1.1-alpha12)-alpha10'] = [$alpha, '1.1-alpha10', FALSE];
Chris@5 40 $tests['(8.x-1.1-alpha12)-beta1'] = [$alpha, '1.1-beta1', FALSE];
Chris@5 41
Chris@5 42 // Beta version.
Chris@5 43 $beta = new Constraint('8.x-1.1-beta8', '8.x');
Chris@5 44 $tests['(8.x-1.1-beta8)-beta8'] = [$beta, '1.1-beta8', TRUE];
Chris@5 45 $tests['(8.x-1.1-beta8)-beta4'] = [$beta, '1.1-beta4', FALSE];
Chris@5 46
Chris@5 47 // RC version.
Chris@5 48 $rc = new Constraint('8.x-1.1-rc11', '8.x');
Chris@5 49 $tests['(8.x-1.1-rc11)-rc11'] = [$rc, '1.1-rc11', TRUE];
Chris@5 50 $tests['(8.x-1.1-rc11)-rc2'] = [$rc, '1.1-rc2', FALSE];
Chris@5 51
Chris@5 52 // Test greater than.
Chris@5 53 $greater = new Constraint('>8.x-1.x', '8.x');
Chris@5 54 $tests['(>8.x-1.x)-2.0'] = [$greater, '2.0', TRUE];
Chris@5 55 $tests['(>8.x-1.x)-1.1'] = [$greater, '1.1', FALSE];
Chris@5 56 $tests['(>8.x-1.x)-0.9'] = [$greater, '0.9', FALSE];
Chris@5 57
Chris@5 58 // Test greater than or equal.
Chris@5 59 $greater_or_equal = new Constraint('>=8.x-1.0', '8.x');
Chris@5 60 $tests['(>=8.x-1.0)-1.1'] = [$greater_or_equal, '1.1', TRUE];
Chris@5 61 $tests['(>=8.x-1.0)-1.0'] = [$greater_or_equal, '1.0', TRUE];
Chris@5 62 $tests['(>=8.x-1.1)-1.0'] = [new Constraint('>=8.x-1.1', '8.x'), '1.0', FALSE];
Chris@5 63
Chris@5 64 // Test less than.
Chris@5 65 $less = new Constraint('<8.x-1.1', '8.x');
Chris@5 66 $tests['(<8.x-1.1)-1.1'] = [$less, '1.1', FALSE];
Chris@5 67 $tests['(<8.x-1.1)-1.1'] = [$less, '1.0', TRUE];
Chris@5 68 $tests['(<8.x-1.0)-1.0'] = [new Constraint('<8.x-1.0', '8.x'), '1.1', FALSE];
Chris@5 69
Chris@5 70 // Test less than or equal.
Chris@5 71 $less_or_equal = new Constraint('<= 8.x-1.x', '8.x');
Chris@5 72 $tests['(<= 8.x-1.x)-2.0'] = [$less_or_equal, '2.0', FALSE];
Chris@5 73 $tests['(<= 8.x-1.x)-1.9'] = [$less_or_equal, '1.9', TRUE];
Chris@5 74 $tests['(<= 8.x-1.x)-1.1'] = [$less_or_equal, '1.1', TRUE];
Chris@5 75 $tests['(<= 8.x-1.x)-0.9'] = [$less_or_equal, '0.9', TRUE];
Chris@5 76
Chris@5 77 // Test greater than and less than.
Chris@5 78 $less_and_greater = new Constraint('<8.x-4.x,>8.x-1.x', '8.x');
Chris@5 79 $tests['(<8.x-4.x,>8.x-1.x)-4.0'] = [$less_and_greater, '4.0', FALSE];
Chris@5 80 $tests['(<8.x-4.x,>8.x-1.x)-3.9'] = [$less_and_greater, '3.9', TRUE];
Chris@5 81 $tests['(<8.x-4.x,>8.x-1.x)-2.1'] = [$less_and_greater, '2.1', TRUE];
Chris@5 82 $tests['(<8.x-4.x,>8.x-1.x)-1.9'] = [$less_and_greater, '1.9', FALSE];
Chris@5 83
Chris@5 84 // Test a nonsensical greater than and less than - no compatible versions.
Chris@5 85 $less_and_greater = new Constraint('>8.x-4.x,<8.x-1.x', '8.x');
Chris@5 86 $tests['(<8.x-4.x,>8.x-1.x)-4.0'] = [$less_and_greater, '4.0', FALSE];
Chris@5 87 $tests['(<8.x-4.x,>8.x-1.x)-3.9'] = [$less_and_greater, '3.9', FALSE];
Chris@5 88 $tests['(<8.x-4.x,>8.x-1.x)-2.1'] = [$less_and_greater, '2.1', FALSE];
Chris@5 89 $tests['(<8.x-4.x,>8.x-1.x)-1.9'] = [$less_and_greater, '1.9', FALSE];
Chris@5 90
Chris@5 91 return $tests;
Chris@5 92 }
Chris@5 93
Chris@5 94 /**
Chris@5 95 * @covers ::toArray
Chris@5 96 * @group legacy
Chris@5 97 * @expectedDeprecation Drupal\Component\Version\Constraint::toArray() only exists to provide a backwards compatibility layer. See https://www.drupal.org/node/2756875
Chris@5 98 */
Chris@5 99 public function testToArray() {
Chris@5 100 $constraint = new Constraint('<8.x-4.x,>8.x-1.x', '8.x');
Chris@5 101 $this->assertSame([
Chris@5 102 ['op' => '<', 'version' => '4.x'],
Chris@5 103 ['op' => '>', 'version' => '2.x'],
Chris@5 104 ], $constraint->toArray());
Chris@5 105 }
Chris@5 106
Chris@5 107 }