; rel="http://www.w3.org/ns/hydra/core#apiDocumentation" X-Debug-Exception: An%20exception%20has%20been%20thrown%20during%20the%20rendering%20of%20a%20template%20%28%22Asset%20manifest%20file%20%22%2Fhome%2Frunner%2Fwork%2Fcore%2Fcore%2Fpublic%2Fassets%2Fmanifest.json%22%20does%20not%20exist.%20Did%20you%20forget%20to%20build%20the%20assets%20with%20npm%20or%20yarn%3F%22%29. X-Debug-Exception-File: %2Fhome%2Frunner%2Fwork%2Fcore%2Fcore%2Ftemplates%2F_partials%2Ffavicon.html.twig:1 X-Robots-Tag: noindex */ public function testCreateNewComplexNestedContent(): void { // (2) use self::$container to access the service container $container = self::$container; $admin = $this->getEm()->getRepository(User::class)->findOneByUsername('admin'); $this->client->loginUser($admin); /** @var ContentRepository $contentRepositoryBefore */ $contentRepositoryBefore = $container->get(ContentRepository::class); $contentCount = $contentRepositoryBefore->count([]); // test controller $this->client->followRedirects(true); $contentTypeName = 'complexnestedtype'; $crawler = $this->client->request('GET', "/bolt/new/$contentTypeName"); self::assertResponseIsSuccessful(); // Note: the form has almost no actual content, because we need javascript for that $form = $crawler->filter('#editcontent')->form(); $values = $form->getValues(); // get csrf token from form -- lots of things are not in the form as they need javascript to run, // but the _csrf_token is present in the 'plain' html in the form // Note: ugly code because data was dumped using debugger $postContent = array ( '_csrf_token' => $values["_csrf_token"], '_edit_locale' => 'en', 'fields' => array ( 'first_field' => '["one"]', ), 'collections' => array ( 'second_field' => array ( 'first_collection_field' => array ( '622e624a526f0' => array ( 'first_set_field' => '["option-one"]', ), ), 'order' => array ( 0 => '622e624a526f0', ), ), ), 'keys-collections' => array ( 'second_field' => array ( 'first_collection_field' => array ( '622e624a526f0' => array ( 'first_set_field' => '0', ), ), ), ), 'save' => '', 'status' => '["published"]', 'publishedAt' => '', 'depublishedAt' => '', ); // 'fake' page interaction by POSTing directly $this->client->request('POST', "/bolt/new/$contentTypeName", $postContent); self::assertResponseIsSuccessful(); $contentCountAfter = $contentRepositoryBefore->count([]); self::assertEquals(1, $contentCountAfter - $contentCount, 'There should be one new content item'); /** @var ContentRepository $contentRepository */ $contentRepository = $container->get(ContentRepository::class); // get the latest content item created $records = $contentRepository->findBy([], ['id' => 'DESC'], 1); $record = $records[0]; self::assertNotNull($record); // check the fields? /** @var FieldExtension $fieldExtension */ $fieldExtension = $container->get(FieldExtension::class); /** @var Field $firstField */ $firstField = $record->getField('first_field'); $firstFieldOptions = $fieldExtension->selectOptions($firstField); // when required=true self::assertEquals(5, $firstFieldOptions->count(), 'expected 5 select options for first_field (required=true)'); // when required=false // self::assertEquals(6, $firstFieldOptions->count(), 'expected 6 select options for first_field (required=false)'); // check the select field /** @var Field\CollectionField $popupsField */ $popupsField = $record->getField('second_field'); $nestedFields = $popupsField->getValue(); /** @var Field\SetField $setField */ $setField = $nestedFields[0]; $nestedSetFields = $setField->getValue(); /** @var Field $nestedSetField */ foreach ($nestedSetFields as $nestedSetField) { if ($nestedSetField->getName() === 'first_set_field') { /** @var Collection $options */ $options = $fieldExtension->selectOptions($nestedSetField); self::assertEquals(2, $options->count(), 'expected 2 select options'); } } } }