New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add more tests #1537
Add more tests #1537
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,10 @@ protected function configureRoutes(RouteCollectionInterface $collection): void | |
$collection->add('composePreview', '{block_id}/compose_preview', [ | ||
'block_id' => null, | ||
]); | ||
|
||
if (!$this->isChild()) { | ||
$collection->remove('create'); | ||
} | ||
} | ||
|
||
protected function configureFormFields(FormMapper $form): void | ||
|
@@ -171,12 +175,6 @@ protected function configureFormFields(FormMapper $form): void | |
]); | ||
} | ||
|
||
if (false !== $isComposer) { | ||
$form->add('enabled', HiddenType::class, ['data' => true]); | ||
} else { | ||
$form->add('enabled'); | ||
} | ||
|
||
if ($isStandardBlock) { | ||
$form->add('position', IntegerType::class); | ||
} | ||
|
@@ -187,6 +185,12 @@ protected function configureFormFields(FormMapper $form): void | |
|
||
$this->configureBlockFields($form, $block); | ||
|
||
if (false !== $isComposer) { | ||
$form->add('enabled', HiddenType::class, ['data' => true]); | ||
} else { | ||
$form->add('enabled'); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. double added enabled (was added by the configureBlockFields above), it was also added in another block, and sonata complains about double property enabled. |
||
|
||
$form->end(); | ||
} else { | ||
$form | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -86,8 +86,7 @@ public function createAction(Request $request): Response | |
{ | ||
$this->admin->checkAccess('create'); | ||
|
||
$sharedBlockAdminClass = $this->getParameter('sonata.page.admin.shared_block.class'); | ||
if (!$this->admin->isChild() && \get_class($this->admin) !== $sharedBlockAdminClass) { | ||
if (!$this->admin->isChild()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was a weird hack to avoid creating a block outside child or shared admin, was better solved with the other solution |
||
throw new PageNotFoundException('You cannot create a block without a page'); | ||
} | ||
|
||
|
@@ -162,6 +161,7 @@ public function composePreviewAction(Request $request): Response | |
'container' => $container, | ||
'child' => $block, | ||
'blockServices' => $blockServices, | ||
'blockAdmin' => $this->admin, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix missing variable previously changed on my other PR. |
||
]); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,7 @@ | |
'controller' => 'sonata.page.controller.admin.block', | ||
'manager_type' => 'orm', | ||
'show_in_dashboard' => false, | ||
'default' => true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are 2 admins for same class, I made blockadmin the default one. |
||
'group' => 'sonata_page', | ||
'translation_domain' => 'SonataPageBundle', | ||
'label' => 'block', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,7 @@ | |
{% set metadata = service.blockMetadata %} | ||
{% endif %} | ||
<h4 class="page-composer__container__child__name"> | ||
{{ child.name|default(service.name)|trans({}, service.blockMetadata.domain|default('SonataPageBundle')) }} | ||
{{ child.name|default(metadata.title)|trans({}, metadata.domain|default('SonataPageBundle')) }} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. completely broken too. |
||
</h4> | ||
{% if not metadata.image %} | ||
<i class="{{ metadata.option('class') }}" ></i> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the Sonata Project package. | ||
* | ||
* (c) Thomas Rabaix <thomas.rabaix@sonata-project.org> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Sonata\PageBundle\Tests\Functional\Admin; | ||
|
||
use Doctrine\ORM\EntityManagerInterface; | ||
use Sonata\PageBundle\Tests\App\AppKernel; | ||
use Sonata\PageBundle\Tests\App\Entity\SonataPageBlock; | ||
use Sonata\PageBundle\Tests\App\Entity\SonataPagePage; | ||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; | ||
use Symfony\Component\HttpKernel\KernelInterface; | ||
|
||
final class BlockAdminTest extends WebTestCase | ||
{ | ||
/** | ||
* @dataProvider provideCrudUrlsCases | ||
* | ||
* @param array<string, mixed> $parameters | ||
*/ | ||
public function testCrudUrls(string $url, array $parameters = []): void | ||
{ | ||
$client = self::createClient(); | ||
|
||
$this->prepareData(); | ||
|
||
$client->request('GET', $url, $parameters); | ||
|
||
self::assertResponseIsSuccessful(); | ||
} | ||
|
||
/** | ||
* @return iterable<array<string|array<string, mixed>>> | ||
* | ||
* @phpstan-return iterable<array{0: string, 1?: array<string, mixed>}> | ||
*/ | ||
public static function provideCrudUrlsCases(): iterable | ||
{ | ||
yield 'List Block' => ['/admin/tests/app/sonatapageblock/list']; | ||
yield 'Edit Block' => ['/admin/tests/app/sonatapageblock/1/edit']; | ||
yield 'Remove Block' => ['/admin/tests/app/sonatapageblock/1/delete']; | ||
yield 'Compose preview Block' => ['/admin/tests/app/sonatapageblock/2/compose_preview']; | ||
} | ||
|
||
/** | ||
* @return class-string<KernelInterface> | ||
*/ | ||
protected static function getKernelClass(): string | ||
{ | ||
return AppKernel::class; | ||
} | ||
|
||
/** | ||
* @psalm-suppress UndefinedPropertyFetch | ||
*/ | ||
private function prepareData(): void | ||
{ | ||
// TODO: Simplify this when dropping support for Symfony 4. | ||
// @phpstan-ignore-next-line | ||
$container = method_exists($this, 'getContainer') ? self::getContainer() : self::$container; | ||
$manager = $container->get('doctrine.orm.entity_manager'); | ||
\assert($manager instanceof EntityManagerInterface); | ||
|
||
$page = new SonataPagePage(); | ||
$page->setName('name'); | ||
$page->setTemplateCode('default'); | ||
|
||
$parentBlock = new SonataPageBlock(); | ||
$parentBlock->setType('sonata.page.block.container'); | ||
$parentBlock->setPage($page); | ||
|
||
$block = new SonataPageBlock(); | ||
$block->setType('sonata.block.service.text'); | ||
$block->setParent($parentBlock); | ||
|
||
$manager->persist($page); | ||
$manager->persist($parentBlock); | ||
$manager->persist($block); | ||
|
||
$manager->flush(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems like a BlockAdmin can't be created unless is child of page or is a sharedBlock (another admin)