CompareVersionTest.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
  5. *
  6. * @author 2018 Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace Test\App;
  25. use InvalidArgumentException;
  26. use OC\App\CompareVersion;
  27. use Test\TestCase;
  28. class CompareVersionTest extends TestCase {
  29. /** @var CompareVersion */
  30. private $compare;
  31. protected function setUp(): void {
  32. parent::setUp();
  33. $this->compare = new CompareVersion();
  34. }
  35. public function comparisonData() {
  36. return [
  37. // Compatible versions
  38. ['13.0.0.3', '13.0.0', '>=', true],
  39. ['13.0.0.3', '13.0.0', '<=', true],
  40. ['13.0.0', '13.0.0', '>=', true],
  41. ['13.0.0', '13.0', '<=', true],
  42. ['13.0.0', '13', '>=', true],
  43. ['13.0.1', '13', '>=', true],
  44. ['13.0.1', '13', '<=', true],
  45. ['13.0.1.9', '13', '<=', true],
  46. ['13.0.1-beta.1', '13', '<=', true],
  47. ['7.4.14', '7.4', '<=', true],
  48. ['7.4.14-ubuntu', '7.4', '<=', true],
  49. ['7.4.14-ubuntu', '7.4.15', '<=', true],
  50. ['7.4.16-ubuntu', '7.4.15', '<=', false],
  51. // Incompatible major versions
  52. ['13.0.0.3', '13.0.0', '<', false],
  53. ['12.0.0', '13.0.0', '>=', false],
  54. ['12.0.0', '13.0', '>=', false],
  55. ['12.0.0', '13', '>=', false],
  56. ['7.4.15-ubuntu', '7.4.15', '>=', true],
  57. // Incompatible minor and patch versions
  58. ['13.0.0', '13.0.1', '>=', false],
  59. ['13.0.0', '13.1', '>=', false],
  60. // Compatible minor and patch versions
  61. ['13.0.1', '13.0.0', '>=', true],
  62. ['13.2.0', '13.1', '>=', true],
  63. ];
  64. }
  65. /**
  66. * @dataProvider comparisonData
  67. */
  68. public function testComparison(string $actualVersion, string $requiredVersion,
  69. string $comparator, bool $expected) {
  70. $isCompatible = $this->compare->isCompatible($actualVersion, $requiredVersion,
  71. $comparator);
  72. $this->assertEquals($expected, $isCompatible);
  73. }
  74. public function testInvalidServerVersion() {
  75. $actualVersion = '13';
  76. $this->expectException(InvalidArgumentException::class);
  77. $this->compare->isCompatible($actualVersion, '13.0.0');
  78. }
  79. public function testInvalidRequiredVersion() {
  80. $actualVersion = '13.0.0';
  81. $this->expectException(InvalidArgumentException::class);
  82. $this->compare->isCompatible($actualVersion, '13.0.0.9');
  83. }
  84. }