mirror of
https://github.com/jbcr/core.git
synced 2026-03-26 01:42:10 +01:00
167 lines
7.1 KiB
Plaintext
167 lines
7.1 KiB
Plaintext
<?php
|
|
|
|
namespace Bolt\Tests\Controller\Backend;
|
|
|
|
use Bolt\Configuration\Config;
|
|
use Bolt\Configuration\Content\ContentType;
|
|
use Bolt\Entity\Field;
|
|
use Bolt\Entity\User;
|
|
use Bolt\Repository\ContentRepository;
|
|
use Bolt\Tests\DbAwareTestCase;
|
|
use Bolt\Twig\FieldExtension;
|
|
use Tightenco\Collect\Support\Collection;
|
|
|
|
class ContentEditControllerTest extends DbAwareTestCase
|
|
{
|
|
// This test fails with the following error. Something with the manifest missing is blocking it.
|
|
// I don't think it's correct that a _unit_ test relies on the frontend assets being present 🤔💭
|
|
|
|
/*
|
|
Run ./vendor/bin/phpunit
|
|
PHPUnit 8.5.28 #StandWithUkraine
|
|
|
|
..............................F................................ 63 / 190 ( 33%)
|
|
............................................................... 126 / 190 ( 66%)
|
|
............................................................... 189 / 190 ( 99%)
|
|
. 190 / 190 (100%)
|
|
|
|
Time: 3.76 seconds, Memory: 126.50 MB
|
|
|
|
There was 1 failure:
|
|
|
|
1) Bolt\Tests\Controller\Backend\ContentEditControllerTest::testCreateNewComplexNestedContent
|
|
Failed asserting that the Response is successful.
|
|
HTTP/1.1 500 Internal Server Error
|
|
Cache-Control: max-age=0, must-revalidate, private
|
|
Content-Type: text/html; charset=UTF-8
|
|
Date: Wed, 10 Aug 2022 14:43:48 GMT
|
|
Expires: Wed, 10 Aug 2022 14:43:48 GMT
|
|
Link: <http://localhost/api/docs.jsonld>; 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
|
|
|
|
<!-- An exception has been thrown during the rendering of a template ("Asset manifest file "/home/runner/work/core/core/public/assets/manifest.json" does not exist. Did you forget to build the assets with npm or yarn?"). (500 Internal Server Error) -->
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<meta name="robots" content="noindex,nofollow" />
|
|
*/
|
|
|
|
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');
|
|
}
|
|
}
|
|
}
|
|
}
|