Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/FormsMigrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,10 @@ public function import(IUser $user, IImportSource $importSource, OutputInterface
$this->submissionMapper->insert($submission);

foreach ($submissionData['answers'] as $answerData) {
if (!array_key_exists($answerData['questionId'], $questionIdMap)) {
continue;
}

$answer = new Answer();
$answer->setSubmissionId($submission->getId());
$answer->setQuestionId($questionIdMap[$answerData['questionId']]);
Expand Down
25 changes: 25 additions & 0 deletions tests/Unit/FormsMigratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,31 @@ public function testImport(string $inputJson, int $expectedOpens) {
$this->formsMigrator->import($user, $importSource, $output);
}

public function testImportSkipsAnswersOfQuestionsNotExported(): void {
$inputJson = '[{"title":"Link","description":"","created":1646251830,"access":{"permitAllUsers":false,"showToAllUsers":false},"expires":0,"state":0,"isAnonymous":false,"submitMultiple":false,"allowEditSubmissions":false,"showExpiration":false,"lastUpdated":123456789,'
. '"questions":[{"id":14,"order":1,"type":"short","isRequired":false,"text":"Name?","description":"","extraSettings":{},"options":[]}],'
. '"submissions":[{"userId":"anyUser@localhost","timestamp":1651354059,"answers":[{"questionId":14,"text":"Ann"},{"questionId":13,"text":"Answer of a deleted question"}]}]}]';

$user = $this->createMock(IUser::class);
$user->method('getUID')->willReturn('someUser');
$importSource = $this->createMock(IImportSource::class);
$importSource->method('getMigratorVersion')->willReturn(1);
$importSource->method('getFileContents')->willReturn($inputJson);
$this->questionMapper->method('insert')->willReturnCallback(function ($question) {
$question->setId(100);
return $question;
});

$this->answerMapper->expects($this->once())
->method('insert')
->willReturnCallback(function ($answer) {
$this->assertSame(100, $answer->getQuestionId());
return $answer;
});

$this->formsMigrator->import($user, $importSource, $this->createMock(OutputInterface::class));
}

public function testImport_NoVersion() {
$user = $this->createMock(IUser::class);
$importSource = $this->createMock(IImportSource::class);
Expand Down
Loading