|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace IonBazan\ComposerDiff\Tests\Url; |
| 4 | + |
| 5 | +use Composer\Package\PackageInterface; |
| 6 | +use IonBazan\ComposerDiff\Url\DrupalGenerator; |
| 7 | + |
| 8 | +class DrupalGeneratorTest extends GeneratorTest |
| 9 | +{ |
| 10 | + public function releaseUrlProvider() |
| 11 | + { |
| 12 | + return array( |
| 13 | + 'contrib-legacy-version' => array( |
| 14 | + $this->getPackageWithSource('drupal/token', '1.0.0', 'https://git.drupalcode.org/project/token.git', '8.x-1.0'), |
| 15 | + 'https://www.drupal.org/project/token/releases/8.x-1.0', |
| 16 | + ), |
| 17 | + 'contrib-semver-version' => array( |
| 18 | + $this->getPackageWithSource('drupal/webform', '6.0.0', 'https://git.drupalcode.org/project/webform.git', '6.0.0'), |
| 19 | + 'https://www.drupal.org/project/webform/releases/6.0.0', |
| 20 | + ), |
| 21 | + 'semver-semver-dist' => array( |
| 22 | + $this->getPackageWithSourceAndDist('drupal/webform', '6.0.0', '6.0.0', 'https://git.drupalcode.org/project/webform.git'), |
| 23 | + 'https://www.drupal.org/project/webform/releases/6.0.0', |
| 24 | + ), |
| 25 | + 'core' => array( |
| 26 | + $this->getPackageWithSource('drupal/core', '9.0.0', 'https://github.com/drupal/core.git', '9.0.0'), |
| 27 | + 'https://www.drupal.org/project/drupal/releases/9.0.0', |
| 28 | + ), |
| 29 | + 'core-dev' => array( |
| 30 | + $this->getPackageWithSource('drupal/core', 'dev-9.0.x', 'https://github.com/drupal/core.git'), |
| 31 | + null, |
| 32 | + ), |
| 33 | + 'core-dev-alternate' => array( |
| 34 | + $this->getPackageWithSource('drupal/core', '9.0.x-dev', 'https://github.com/drupal/core.git'), |
| 35 | + null, |
| 36 | + ), |
| 37 | + 'contrib-dev' => array( |
| 38 | + $this->getPackageWithSource('drupal/webform', 'dev-9.0.x', 'https://github.com/drupal/core.git'), |
| 39 | + null, |
| 40 | + ), |
| 41 | + 'contrib-dev-alternate' => array( |
| 42 | + $this->getPackageWithSource('drupal/webform', 'dev-9.0.x', 'https://github.com/drupal/core.git'), |
| 43 | + null, |
| 44 | + ), |
| 45 | + ); |
| 46 | + } |
| 47 | + |
| 48 | + public function projectUrlProvider() |
| 49 | + { |
| 50 | + return array( |
| 51 | + 'contrib-legacy-version' => array( |
| 52 | + $this->getPackageWithSource('drupal/token', '8.x-1.0', 'https://git.drupalcode.org/project/token.git'), |
| 53 | + 'https://www.drupal.org/project/token', |
| 54 | + ), |
| 55 | + 'contrib-semver-version' => array( |
| 56 | + $this->getPackageWithSource('drupal/webform', '6.0.0', 'https://git.drupalcode.org/project/webform.git'), |
| 57 | + 'https://www.drupal.org/project/webform', |
| 58 | + ), |
| 59 | + 'core' => array( |
| 60 | + $this->getPackageWithSource('drupal/core', '9.0.0', 'https://github.com/drupal/core.git'), |
| 61 | + 'https://www.drupal.org/project/drupal', |
| 62 | + ), |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + public function compareUrlProvider() |
| 67 | + { |
| 68 | + return array( |
| 69 | + 'semver' => array( |
| 70 | + $this->getPackageWithSourceAndDist('drupal/webform', '6.0.0', '6.0.0', 'https://git.drupalcode.org/project/webform.git'), |
| 71 | + $this->getPackageWithSourceAndDist('drupal/webform', '6.0.1', '6.0.1', 'https://git.drupalcode.org/project/webform.git'), |
| 72 | + 'https://git.drupalcode.org/project/webform/compare/6.0.0...6.0.1', |
| 73 | + ), |
| 74 | + 'legacy-version' => array( |
| 75 | + $this->getPackageWithSourceAndDist('drupal/color_field', '2.4.0', '8.x-2.4', 'https://git.drupalcode.org/project/color_field.git'), |
| 76 | + $this->getPackageWithSourceAndDist('drupal/color_field', '2.5.0', '8.x-2.5', 'https://git.drupalcode.org/project/color_field.git'), |
| 77 | + 'https://git.drupalcode.org/project/color_field/compare/8.x-2.4...8.x-2.5', |
| 78 | + ), |
| 79 | + 'dev-version' => array( |
| 80 | + $this->getPackageWithSourceAndDist('drupal/color_field', '2.4.0', '8.x-2.4', 'https://git.drupalcode.org/project/color_field.git'), |
| 81 | + $this->getPackageWithSourceAndDist('drupal/color_field', 'dev-2.5.0', '8.x-2.5', 'https://git.drupalcode.org/project/color_field.git', 'd46283075d76ed244f7825b378eeb1cee246af73'), |
| 82 | + 'https://git.drupalcode.org/project/color_field/compare/8.x-2.4...d462830', |
| 83 | + ), |
| 84 | + ); |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * @param string $name |
| 89 | + * @param string $version |
| 90 | + * @param string|null $sourceUrl |
| 91 | + * @param string|null $sourceReference |
| 92 | + * |
| 93 | + * @return PackageInterface |
| 94 | + */ |
| 95 | + protected function getPackageWithSourceAndDist($name, $version, $distVersion, $sourceUrl, $sourceReference = null) |
| 96 | + { |
| 97 | + $package = $this->getPackage($name, $version, $sourceReference); |
| 98 | + $package->method('getSourceUrl')->willReturn($sourceUrl); |
| 99 | + $package->method('getDistReference')->willReturn($distVersion); |
| 100 | + $package->method('getSourceReference')->willReturn($sourceReference); |
| 101 | + $package->method('isDev')->willReturn(0 === strpos($version, 'dev-') || '-dev' === substr($version, -4)); |
| 102 | + |
| 103 | + return $package; |
| 104 | + } |
| 105 | + |
| 106 | + /** |
| 107 | + * {@inheritdoc} |
| 108 | + */ |
| 109 | + protected function getGenerator() |
| 110 | + { |
| 111 | + return new DrupalGenerator(); |
| 112 | + } |
| 113 | +} |
0 commit comments