CompareVersionTest.php 2.8 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. // Incompatible major versions
  51. ['13.0.0.3', '13.0.0', '<', false],
  52. ['12.0.0', '13.0.0', '>=', false],
  53. ['12.0.0', '13.0', '>=', false],
  54. ['12.0.0', '13', '>=', false],
  55. ['7.4.15-ubuntu', '7.4.15', '>=', true],
  56. // Incompatible minor and patch versions
  57. ['13.0.0', '13.0.1', '>=', false],
  58. ['13.0.0', '13.1', '>=', false],
  59. // Compatible minor and patch versions
  60. ['13.0.1', '13.0.0', '>=', true],
  61. ['13.2.0', '13.1', '>=', true],
  62. ];
  63. }
  64. /**
  65. * @dataProvider comparisonData
  66. */
  67. public function testComparison(string $actualVersion, string $requiredVersion,
  68. string $comparator, bool $expected) {
  69. $isCompatible = $this->compare->isCompatible($actualVersion, $requiredVersion,
  70. $comparator);
  71. $this->assertEquals($expected, $isCompatible);
  72. }
  73. public function testInvalidServerVersion() {
  74. $actualVersion = '13';
  75. $this->expectException(InvalidArgumentException::class);
  76. $this->compare->isCompatible($actualVersion, '13.0.0');
  77. }
  78. public function testInvalidRequiredVersion() {
  79. $actualVersion = '13.0.0';
  80. $this->expectException(InvalidArgumentException::class);
  81. $this->compare->isCompatible($actualVersion, '13.0.0.9');
  82. }
  83. }