Chris@18: assertSame($result, $version_info->isCompatible($current_version)); Chris@18: } Chris@18: Chris@18: /** Chris@18: * Provider for testIsCompatible. Chris@18: */ Chris@18: public function providerIsCompatible() { Chris@18: $tests = []; Chris@18: Chris@18: $tests['no-dependencies'] = [new Constraint('', '8.x'), '8.1.x', TRUE]; Chris@18: Chris@18: // Stable version. Chris@18: $stable = new Constraint('8.x-1.0', '8.x'); Chris@18: $tests['(=8.x-1.0)-1.0'] = [$stable, '1.0', TRUE]; Chris@18: $tests['(=8.x-1.0)-1.1'] = [$stable, '1.1', FALSE]; Chris@18: $tests['(=8.x-1.0)-0.9'] = [$stable, '0.9', FALSE]; Chris@18: Chris@18: // Alpha version. Chris@18: $alpha = new Constraint('8.x-1.1-alpha12', '8.x'); Chris@18: $tests['(8.x-1.1-alpha12)-alpha12'] = [$alpha, '1.1-alpha12', TRUE]; Chris@18: $tests['(8.x-1.1-alpha12)-alpha10'] = [$alpha, '1.1-alpha10', FALSE]; Chris@18: $tests['(8.x-1.1-alpha12)-beta1'] = [$alpha, '1.1-beta1', FALSE]; Chris@18: Chris@18: // Beta version. Chris@18: $beta = new Constraint('8.x-1.1-beta8', '8.x'); Chris@18: $tests['(8.x-1.1-beta8)-beta8'] = [$beta, '1.1-beta8', TRUE]; Chris@18: $tests['(8.x-1.1-beta8)-beta4'] = [$beta, '1.1-beta4', FALSE]; Chris@18: Chris@18: // RC version. Chris@18: $rc = new Constraint('8.x-1.1-rc11', '8.x'); Chris@18: $tests['(8.x-1.1-rc11)-rc11'] = [$rc, '1.1-rc11', TRUE]; Chris@18: $tests['(8.x-1.1-rc11)-rc2'] = [$rc, '1.1-rc2', FALSE]; Chris@18: Chris@18: // Test greater than. Chris@18: $greater = new Constraint('>8.x-1.x', '8.x'); Chris@18: $tests['(>8.x-1.x)-2.0'] = [$greater, '2.0', TRUE]; Chris@18: $tests['(>8.x-1.x)-1.1'] = [$greater, '1.1', FALSE]; Chris@18: $tests['(>8.x-1.x)-0.9'] = [$greater, '0.9', FALSE]; Chris@18: Chris@18: // Test greater than or equal. Chris@18: $greater_or_equal = new Constraint('>=8.x-1.0', '8.x'); Chris@18: $tests['(>=8.x-1.0)-1.1'] = [$greater_or_equal, '1.1', TRUE]; Chris@18: $tests['(>=8.x-1.0)-1.0'] = [$greater_or_equal, '1.0', TRUE]; Chris@18: $tests['(>=8.x-1.1)-1.0'] = [new Constraint('>=8.x-1.1', '8.x'), '1.0', FALSE]; Chris@18: Chris@18: // Test less than. Chris@18: $less = new Constraint('<8.x-1.1', '8.x'); Chris@18: $tests['(<8.x-1.1)-1.1'] = [$less, '1.1', FALSE]; Chris@18: $tests['(<8.x-1.1)-1.1'] = [$less, '1.0', TRUE]; Chris@18: $tests['(<8.x-1.0)-1.0'] = [new Constraint('<8.x-1.0', '8.x'), '1.1', FALSE]; Chris@18: Chris@18: // Test less than or equal. Chris@18: $less_or_equal = new Constraint('<= 8.x-1.x', '8.x'); Chris@18: $tests['(<= 8.x-1.x)-2.0'] = [$less_or_equal, '2.0', FALSE]; Chris@18: $tests['(<= 8.x-1.x)-1.9'] = [$less_or_equal, '1.9', TRUE]; Chris@18: $tests['(<= 8.x-1.x)-1.1'] = [$less_or_equal, '1.1', TRUE]; Chris@18: $tests['(<= 8.x-1.x)-0.9'] = [$less_or_equal, '0.9', TRUE]; Chris@18: Chris@18: // Test greater than and less than. Chris@18: $less_and_greater = new Constraint('<8.x-4.x,>8.x-1.x', '8.x'); Chris@18: $tests['(<8.x-4.x,>8.x-1.x)-4.0'] = [$less_and_greater, '4.0', FALSE]; Chris@18: $tests['(<8.x-4.x,>8.x-1.x)-3.9'] = [$less_and_greater, '3.9', TRUE]; Chris@18: $tests['(<8.x-4.x,>8.x-1.x)-2.1'] = [$less_and_greater, '2.1', TRUE]; Chris@18: $tests['(<8.x-4.x,>8.x-1.x)-1.9'] = [$less_and_greater, '1.9', FALSE]; Chris@18: Chris@18: // Test a nonsensical greater than and less than - no compatible versions. Chris@18: $less_and_greater = new Constraint('>8.x-4.x,<8.x-1.x', '8.x'); Chris@18: $tests['(<8.x-4.x,>8.x-1.x)-4.0'] = [$less_and_greater, '4.0', FALSE]; Chris@18: $tests['(<8.x-4.x,>8.x-1.x)-3.9'] = [$less_and_greater, '3.9', FALSE]; Chris@18: $tests['(<8.x-4.x,>8.x-1.x)-2.1'] = [$less_and_greater, '2.1', FALSE]; Chris@18: $tests['(<8.x-4.x,>8.x-1.x)-1.9'] = [$less_and_greater, '1.9', FALSE]; Chris@18: Chris@18: return $tests; Chris@18: } Chris@18: Chris@18: /** Chris@18: * @covers ::toArray Chris@18: * @group legacy Chris@18: * @expectedDeprecation Drupal\Component\Version\Constraint::toArray() only exists to provide a backwards compatibility layer. See https://www.drupal.org/node/2756875 Chris@18: */ Chris@18: public function testToArray() { Chris@18: $constraint = new Constraint('<8.x-4.x,>8.x-1.x', '8.x'); Chris@18: $this->assertSame([ Chris@18: ['op' => '<', 'version' => '4.x'], Chris@18: ['op' => '>', 'version' => '2.x'], Chris@18: ], $constraint->toArray()); Chris@18: } Chris@18: Chris@18: }