diff --git a/src/FormManager.php b/src/FormManager.php index 456061d..ec35415 100644 --- a/src/FormManager.php +++ b/src/FormManager.php @@ -379,6 +379,12 @@ private function prepare(): void $this->formModel = $formModel; + // Set current session reference from request or generate a new one + $this->initSessionReference(); + + // Set storage identifier for storage implementations to work with + $this->storageIdentifier = $this->storageIdentifierGenerator->generate($this); + $this->loadFormFieldModels(); if (0 === \count($this->formFieldModels)) { @@ -409,12 +415,6 @@ private function prepare(): void } } - // Set current session reference from request or generate a new one - $this->initSessionReference(); - - // Set storage identifier for storage implementations to work with - $this->storageIdentifier = $this->storageIdentifierGenerator->generate($this); - $this->prepared = true; $this->preparing = false; } diff --git a/tests/FormManagerTest.php b/tests/FormManagerTest.php new file mode 100644 index 0000000..f44a068 --- /dev/null +++ b/tests/FormManagerTest.php @@ -0,0 +1,58 @@ +mockClassWithProperties(FormModel::class, ['id' => 42]); + $formModelAdapter = $this->mockAdapter(['findByPk']); + $formModelAdapter + ->expects($this->once()) + ->method('findByPk') + ->with(42) + ->willReturn($formModel) + ; + $formFieldModelAdapter = $this->mockAdapter(['findPublishedByPid']); + $formFieldModelAdapter + ->expects($this->once()) + ->method('findPublishedByPid') + ->with(42) + ->willReturn([]) + ; + + $framework = $this->mockContaoFramework([ + Config::class => $this->mockAdapter(['isComplete']), + System::class => $this->mockAdapter(['importStatic']), + FormModel::class => $formModelAdapter, + FormFieldModel::class => $formFieldModelAdapter, + ]); + + $formManager = new FormManager( + 42, + new Request(), + $framework, + $this->createMock(StorageInterface::class), + $this->createMock(StorageIdentifierGeneratorInterface::class), + $this->createMock(SessionReferenceGeneratorInterface::class), + new UrlParser() + ); + + $this->assertSame([], $formManager->getDataOfAllSteps()->all()); + } +}