getContainer(); $this->userManager = $container->get(IUserManager::class); $this->migrator = $container->get(CalendarMigrator::class); $this->output = $this->createMock(OutputInterface::class); } public function dataAssets(): array { return array_map( function (string $filename) { /** @var VCalendar $vCalendar */ $vCalendar = VObjectReader::read( fopen(self::ASSETS_DIR . $filename, 'r'), VObjectReader::OPTION_FORGIVING, ); [$initialCalendarUri, $ext] = explode('.', $filename, 2); return [UUIDUtil::getUUID(), $filename, $initialCalendarUri, $vCalendar]; }, array_diff( scandir(self::ASSETS_DIR), // Exclude current and parent directories ['.', '..'], ), ); } private function getProperties(VCalendar $vCalendar): array { return array_map( fn (VObjectProperty $property) => $property->serialize(), array_values(array_filter( $vCalendar->children(), fn ($child) => $child instanceof VObjectProperty, )), ); } private function getComponents(VCalendar $vCalendar): array { return array_map( // Elements of the serialized blob are sorted fn (VObjectComponent $component) => $component->serialize(), $vCalendar->getComponents(), ); } private function getSanitizedComponents(VCalendar $vCalendar): array { return array_map( // Elements of the serialized blob are sorted fn (VObjectComponent $component) => $this->invokePrivate($this->migrator, 'sanitizeComponent', [$component])->serialize(), $vCalendar->getComponents(), ); } /** * @dataProvider dataAssets */ public function testImportExportAsset(string $userId, string $filename, string $initialCalendarUri, VCalendar $importCalendar): void { $user = $this->userManager->createUser($userId, 'topsecretpassword'); $problems = $importCalendar->validate(); $this->assertEmpty($problems); $this->invokePrivate($this->migrator, 'importCalendar', [$user, $filename, $initialCalendarUri, $importCalendar, $this->output]); $calendarExports = $this->invokePrivate($this->migrator, 'getCalendarExports', [$user, $this->output]); $this->assertCount(1, $calendarExports); /** @var VCalendar $exportCalendar */ ['vCalendar' => $exportCalendar] = reset($calendarExports); $this->assertEqualsCanonicalizing( $this->getProperties($importCalendar), $this->getProperties($exportCalendar), ); $this->assertEqualsCanonicalizing( // Components are expected to be sanitized on import $this->getSanitizedComponents($importCalendar), $this->getComponents($exportCalendar), ); } }