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