SetVcardDatabaseUIDTest.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2018 John Molakvoæ <skjnldsv@protonmail.com>
  4. *
  5. * @author John Molakvoæ <skjnldsv@protonmail.com>
  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\Repair;
  24. use OCP\IConfig;
  25. use OCP\ILogger;
  26. use OCP\Migration\IOutput;
  27. use OC\Repair\NC15\SetVcardDatabaseUID;
  28. use Test\TestCase;
  29. /**
  30. * @group DB
  31. */
  32. class SetVcardDatabaseUIDTest extends TestCase {
  33. /** @var SetVcardDatabaseUID */
  34. private $repair;
  35. /** @var IConfig */
  36. private $config;
  37. /** @var Ilogger */
  38. private $logger;
  39. protected function setUp() {
  40. parent::setUp();
  41. $this->config = $this->createMock(IConfig::class);
  42. $this->logger = $this->createMock(Ilogger::class);
  43. $this->repair = new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), $this->config, $this->logger);
  44. }
  45. protected function tearDown() {
  46. return parent::tearDown();
  47. }
  48. public function dataTestVcards() {
  49. return [
  50. // classic vcard
  51. ['BEGIN:VCARD'.PHP_EOL.
  52. 'VERSION:3.0'.PHP_EOL.
  53. 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL.
  54. 'UID:Test'.PHP_EOL.
  55. 'FN:Test'.PHP_EOL.
  56. 'N:Test;;;;'.PHP_EOL.
  57. 'END:VCARD', 'Test'],
  58. // UID as url
  59. ['BEGIN:VCARD'.PHP_EOL.
  60. 'VERSION:3.0'.PHP_EOL.
  61. 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL.
  62. 'UID:https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'.PHP_EOL.
  63. 'FN:Test'.PHP_EOL.
  64. 'N:Test;;;;'.PHP_EOL.
  65. 'END:VCARD', 'https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'],
  66. // No uid
  67. ['BEGIN:VCARD'.PHP_EOL.
  68. 'VERSION:3.0'.PHP_EOL.
  69. 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL.
  70. 'FN:Test'.PHP_EOL.
  71. 'N:Test;;;;'.PHP_EOL.
  72. 'END:VCARD', false]
  73. ];
  74. }
  75. /**
  76. * @dataProvider dataTestVcards
  77. *
  78. * @param string $from
  79. * @param string|boolean $expected
  80. */
  81. public function testExtractUIDFromVcard($from, $expected) {
  82. $output = $this->createMock(IOutput::class);
  83. $uid = $this->invokePrivate($this->repair, 'getUid', ['carddata' => $from, 'output' => $output]);
  84. $this->assertEquals($expected, $uid);
  85. }
  86. public function shouldRunDataProvider() {
  87. return [
  88. ['11.0.0.0', true],
  89. ['15.0.0.3', false],
  90. ['13.0.5.2', true],
  91. ['12.0.0.0', true],
  92. ['16.0.0.1', false],
  93. ['15.0.0.2', true],
  94. ['13.0.0.0', true],
  95. ['13.0.0.1', true]
  96. ];
  97. }
  98. /**
  99. * @dataProvider shouldRunDataProvider
  100. *
  101. * @param string $from
  102. * @param boolean $expected
  103. */
  104. public function testShouldRun($from, $expected) {
  105. $this->config->expects($this->any())
  106. ->method('getSystemValue')
  107. ->with('version', '0.0.0.0')
  108. ->willReturn($from);
  109. $this->assertEquals($expected, $this->invokePrivate($this->repair, 'shouldRun'));
  110. }
  111. }