mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
Integration tests
Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
parent
568393292a
commit
1a34c7f240
5 changed files with 41670 additions and 0 deletions
|
|
@ -0,0 +1,148 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2022 Christopher Ng <chrng8@gmail.com>
|
||||
*
|
||||
* @author Christopher Ng <chrng8@gmail.com>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\DAV\Tests\integration\UserMigration;
|
||||
|
||||
use function Safe\scandir;
|
||||
use OCA\DAV\AppInfo\Application;
|
||||
use OCA\DAV\UserMigration\ContactsMigrator;
|
||||
use OCP\AppFramework\App;
|
||||
use OCP\IUserManager;
|
||||
use Sabre\VObject\Component\VCard;
|
||||
use Sabre\VObject\Parser\Parser as VObjectParser;
|
||||
use Sabre\VObject\Property as VObjectProperty;
|
||||
use Sabre\VObject\Splitter\VCard as VCardSplitter;
|
||||
use Sabre\VObject\UUIDUtil;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Test\TestCase;
|
||||
|
||||
/**
|
||||
* @group DB
|
||||
*/
|
||||
class ContactsMigratorTest extends TestCase {
|
||||
|
||||
private IUserManager $userManager;
|
||||
|
||||
private ContactsMigrator $migrator;
|
||||
|
||||
private OutputInterface $output;
|
||||
|
||||
private const ASSETS_DIR = __DIR__ . '/assets/address_books/';
|
||||
|
||||
protected function setUp(): void {
|
||||
$app = new App(Application::APP_ID);
|
||||
$container = $app->getContainer();
|
||||
|
||||
$this->userManager = $container->get(IUserManager::class);
|
||||
$this->migrator = $container->get(ContactsMigrator::class);
|
||||
$this->output = $this->createMock(OutputInterface::class);
|
||||
}
|
||||
|
||||
public function dataAssets(): array {
|
||||
return array_map(
|
||||
function (string $filename) {
|
||||
$vCardSplitter = new VCardSplitter(
|
||||
fopen(self::ASSETS_DIR . $filename, 'r'),
|
||||
VObjectParser::OPTION_FORGIVING,
|
||||
);
|
||||
|
||||
/** @var VCard[] $vCards */
|
||||
$vCards = [];
|
||||
while ($vCard = $vCardSplitter->getNext()) {
|
||||
$vCards[] = $vCard;
|
||||
}
|
||||
|
||||
[$initialAddressBookUri, $ext] = explode('.', $filename, 2);
|
||||
$metadata = ['displayName' => ucwords(str_replace('-', ' ', $initialAddressBookUri))];
|
||||
return [UUIDUtil::getUUID(), $filename, $initialAddressBookUri, $metadata, $vCards];
|
||||
},
|
||||
array_diff(
|
||||
scandir(self::ASSETS_DIR),
|
||||
// Exclude current and parent directories
|
||||
['.', '..'],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
private function getPropertiesChangedOnImport(VCard $vCard): array {
|
||||
return array_map(
|
||||
fn (VObjectProperty $property) => $property->serialize(),
|
||||
array_values(array_filter(
|
||||
$vCard->children(),
|
||||
fn (mixed $child) => $child instanceof VObjectProperty && $child->name === 'PRODID',
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
private function getProperties(VCard $vCard): array {
|
||||
return array_map(
|
||||
fn (VObjectProperty $property) => $property->serialize(),
|
||||
array_values(array_filter(
|
||||
$vCard->children(),
|
||||
fn (mixed $child) => $child instanceof VObjectProperty && $child->name !== 'PRODID',
|
||||
)),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider dataAssets
|
||||
*
|
||||
* @param array{displayName: string, description?: string} $metadata
|
||||
* @param VCard[] $importCards
|
||||
*/
|
||||
public function testImportExportAsset(string $userId, string $filename, string $initialAddressBookUri, array $metadata, array $importCards): void {
|
||||
$user = $this->userManager->createUser($userId, 'topsecretpassword');
|
||||
|
||||
foreach ($importCards as $importCard) {
|
||||
$problems = $importCard->validate();
|
||||
$this->assertEmpty($problems);
|
||||
}
|
||||
|
||||
$this->invokePrivate($this->migrator, 'importAddressBook', [$user, $filename, $initialAddressBookUri, $metadata, $importCards, $this->output]);
|
||||
|
||||
$addressBookExports = $this->invokePrivate($this->migrator, 'getAddressBookExports', [$user, $this->output]);
|
||||
$this->assertCount(1, $addressBookExports);
|
||||
|
||||
/** @var VCard[] $exportCards */
|
||||
['vCards' => $exportCards] = reset($addressBookExports);
|
||||
|
||||
$this->assertEquals(count($importCards), count($exportCards));
|
||||
|
||||
for ($i = 0; $i < count($importCards); ++$i) {
|
||||
$this->assertNotEqualsCanonicalizing(
|
||||
$this->getPropertiesChangedOnImport($importCards[$i]),
|
||||
$this->getPropertiesChangedOnImport($exportCards[$i]),
|
||||
);
|
||||
}
|
||||
|
||||
for ($i = 0; $i < count($importCards); ++$i) {
|
||||
$this->assertEqualsCanonicalizing(
|
||||
$this->getProperties($importCards[$i]),
|
||||
$this->getProperties($exportCards[$i]),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load diff
File diff suppressed because it is too large
Load diff
|
|
@ -0,0 +1,72 @@
|
|||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
PRODID:-//Nextcloud Contacts v4.2.0
|
||||
UID:ce1b2650-3473-4e63-9584-9c6230d91d81
|
||||
FN:Jane Smith
|
||||
ADR;TYPE=HOME:;;;;;;
|
||||
EMAIL;TYPE=HOME:jane@example.org
|
||||
TEL;TYPE=HOME,VOICE:+1 315-739-0311
|
||||
REV;VALUE=DATE-AND-OR-TIME:20220329T033308Z
|
||||
END:VCARD
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
PRODID:-//Nextcloud Contacts v4.2.0
|
||||
UID:0f0765d9-4bd7-4162-a45c-821b81112abc
|
||||
FN:Christie Sheila Woods
|
||||
ADR;TYPE=HOME:;;;;;;
|
||||
EMAIL;TYPE=HOME:christiesheilawoods@domain.com
|
||||
TEL;TYPE=HOME,VOICE:
|
||||
REV;VALUE=DATE-AND-OR-TIME:20220329T033510Z
|
||||
END:VCARD
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
PRODID:-//Nextcloud Contacts v4.2.0
|
||||
UID:7121d31d-e49e-4c27-880e-541f47d254e3
|
||||
FN:Reginald Richards
|
||||
ADR;TYPE=HOME:;;;;;;
|
||||
EMAIL;TYPE=HOME:reginaldgarryrichards@example.org
|
||||
TEL;TYPE=HOME,VOICE:
|
||||
NICKNAME:Regi
|
||||
REV;VALUE=DATE-AND-OR-TIME:20220329T033815Z
|
||||
END:VCARD
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
PRODID:-//Nextcloud Contacts v4.2.0
|
||||
UID:d7913c7c-7993-4e56-a4bb-799a69755867
|
||||
FN:Virginia Brennan
|
||||
ADR;TYPE=HOME:;;;;;;
|
||||
EMAIL;TYPE=HOME:virginia@example.org
|
||||
TEL;TYPE=HOME,VOICE:
|
||||
REV;VALUE=DATE-AND-OR-TIME:20220329T033553Z
|
||||
END:VCARD
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
PRODID:-//Nextcloud Contacts v4.2.0
|
||||
UID:088e751d-563a-4176-8bde-b33fcc23d580
|
||||
FN:Derrick Anders
|
||||
ADR;TYPE=HOME:;;;;;;
|
||||
EMAIL;TYPE=HOME:derrick@domain.org
|
||||
TEL;TYPE=HOME,VOICE:+1 505-580-1714
|
||||
REV;VALUE=DATE-AND-OR-TIME:20220329T033746Z
|
||||
END:VCARD
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
PRODID:-//Nextcloud Contacts v4.2.0
|
||||
UID:6d134fff-0984-48cb-9e66-eaca014a88cc
|
||||
FN:Julia Cara Burke
|
||||
ADR;TYPE=HOME:;;;;;;
|
||||
EMAIL;TYPE=HOME:julia@example.org
|
||||
TEL;TYPE=HOME,VOICE:
|
||||
ORG:Mysterious Institute
|
||||
REV;VALUE=DATE-AND-OR-TIME:20220329T033702Z
|
||||
END:VCARD
|
||||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
PRODID:-//Nextcloud Contacts v4.2.0
|
||||
UID:c0b7cd31-8bac-45b8-83dd-882f1c318878
|
||||
FN:Terrence Alex Field
|
||||
ADR;TYPE=HOME:;;;;;;
|
||||
EMAIL;TYPE=HOME:terrence@example.com
|
||||
TEL;TYPE=HOME,VOICE:
|
||||
REV;VALUE=DATE-AND-OR-TIME:20220329T033805Z
|
||||
END:VCARD
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
BEGIN:VCARD
|
||||
VERSION:4.0
|
||||
PRODID:-//Nextcloud Contacts v4.2.0
|
||||
UID:564d3e07-94ee-483d-a2f9-f0a58e6f4b34
|
||||
FN:Andrew Gallegos
|
||||
ADR;TYPE=HOME:;;;;;;
|
||||
EMAIL;TYPE=HOME:andrew@example.org
|
||||
TEL;TYPE=HOME,VOICE:
|
||||
REV;VALUE=DATE-AND-OR-TIME:20220329T035205Z
|
||||
END:VCARD
|
||||
Loading…
Reference in a new issue