CompareVersionTest.php 2.6 KB

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