-
Notifications
You must be signed in to change notification settings - Fork 158
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
349 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\Sylius\CmsPlugin\Twig\Runtime; | ||
|
||
use PhpSpec\ObjectBehavior; | ||
use Sylius\CmsPlugin\Twig\Runtime\TranslationFormReduceRuntime; | ||
use Symfony\Component\Form\FormView; | ||
|
||
class TranslationFormReduceRuntimeSpec extends ObjectBehavior | ||
{ | ||
public function it_is_initializable(): void | ||
{ | ||
$this->shouldHaveType(TranslationFormReduceRuntime::class); | ||
} | ||
|
||
public function it_reduces_form_to_specified_fields( | ||
FormView $form, | ||
FormView $localeForm, | ||
FormView $slugForm, | ||
FormView $titleForm | ||
): void { | ||
$form->children = [ | ||
'en_US' => $localeForm | ||
]; | ||
|
||
$localeForm->children = [ | ||
'slug' => $slugForm, | ||
'title' => $titleForm, | ||
'metaDescription' => new FormView(), | ||
]; | ||
|
||
$result = $this->reduceTranslationForm($form, ['slug', 'title']); | ||
$result->shouldHaveKey('en_US'); | ||
$result['en_US']->shouldHaveKey('slug'); | ||
$result['en_US']->shouldHaveKey('title'); | ||
$result['en_US']->shouldNotHaveKey('metaDescription'); | ||
} | ||
|
||
public function it_throws_exception_if_field_is_not_found(FormView $form, FormView $localeForm): void | ||
{ | ||
$form->children = [ | ||
'en_US' => $localeForm, | ||
]; | ||
|
||
$localeForm->children = [ | ||
'metaDescription' => new FormView(), | ||
]; | ||
|
||
$this->shouldThrow(\InvalidArgumentException::class)->during('reduceTranslationForm', [$form, ['slug', 'title']]); | ||
} | ||
|
||
public function it_handles_multiple_locales( | ||
FormView $form, | ||
FormView $enLocale, | ||
FormView $deLocale, | ||
FormView $slugForm, | ||
FormView $titleForm | ||
): void { | ||
$form->children = [ | ||
'en_US' => $enLocale, | ||
'de_DE' => $deLocale, | ||
]; | ||
|
||
$enLocale->children = [ | ||
'slug' => $slugForm, | ||
'title' => $titleForm, | ||
]; | ||
|
||
$deLocale->children = [ | ||
'slug' => $slugForm, | ||
'title' => $titleForm, | ||
]; | ||
|
||
$result = $this->reduceTranslationForm($form, ['slug', 'title']); | ||
$result->shouldHaveCount(2); | ||
$result['en_US']->shouldHaveKey('slug'); | ||
$result['en_US']->shouldHaveKey('title'); | ||
$result['de_DE']->shouldHaveKey('slug'); | ||
$result['de_DE']->shouldHaveKey('title'); | ||
} | ||
|
||
public function it_throws_exception_if_field_is_not_present_in_multiple_locales( | ||
FormView $form, | ||
FormView $enLocale, | ||
FormView $deLocale, | ||
FormView $slugForm | ||
): void { | ||
$form->children = [ | ||
'en_US' => $enLocale, | ||
'de_DE' => $deLocale, | ||
]; | ||
|
||
$enLocale->children = [ | ||
'slug' => $slugForm, | ||
]; | ||
|
||
$deLocale->children = [ | ||
'slug' => $slugForm, | ||
// 'title' is missing in de_DE | ||
]; | ||
|
||
$this->shouldThrow(\InvalidArgumentException::class)->during('reduceTranslationForm', [$form, ['slug', 'title']]); | ||
} | ||
|
||
public function it_handles_empty_field_array( | ||
FormView $form, | ||
FormView $localeForm, | ||
FormView $slugForm, | ||
FormView $titleForm | ||
): void { | ||
$form->children = [ | ||
'en_US' => $localeForm, | ||
]; | ||
|
||
$localeForm->children = [ | ||
'slug' => $slugForm, | ||
'title' => $titleForm, | ||
]; | ||
|
||
$result = $this->reduceTranslationForm($form, []); | ||
$result->shouldHaveCount(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Sylius\CmsPlugin\Migrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
final class Version20240910113936 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return 'This migration removes teaser fields from the Page entity and adds them to the PageTranslation entity'; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE sylius_cms_page DROP FOREIGN KEY FK_2C2740B2F56F16CF'); | ||
$this->addSql('DROP INDEX IDX_2C2740B2F56F16CF ON sylius_cms_page'); | ||
$this->addSql('ALTER TABLE sylius_cms_page DROP teaser_image_id, DROP teaser_title, DROP teaser_content'); | ||
$this->addSql('ALTER TABLE sylius_cms_page_translation ADD teaser_image_id INT DEFAULT NULL, ADD teaser_title VARCHAR(255) DEFAULT NULL, ADD teaser_content LONGTEXT DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE sylius_cms_page_translation ADD CONSTRAINT FK_6D0D401BF56F16CF FOREIGN KEY (teaser_image_id) REFERENCES sylius_cms_media (id) ON DELETE SET NULL'); | ||
$this->addSql('CREATE INDEX IDX_6D0D401BF56F16CF ON sylius_cms_page_translation (teaser_image_id)'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
$this->addSql('ALTER TABLE sylius_cms_page ADD teaser_image_id INT DEFAULT NULL, ADD teaser_title VARCHAR(255) DEFAULT NULL, ADD teaser_content LONGTEXT DEFAULT NULL'); | ||
$this->addSql('ALTER TABLE sylius_cms_page ADD CONSTRAINT FK_2C2740B2F56F16CF FOREIGN KEY (teaser_image_id) REFERENCES sylius_cms_media (id) ON DELETE SET NULL'); | ||
$this->addSql('CREATE INDEX IDX_2C2740B2F56F16CF ON sylius_cms_page (teaser_image_id)'); | ||
$this->addSql('ALTER TABLE sylius_cms_page_translation DROP FOREIGN KEY FK_6D0D401BF56F16CF'); | ||
$this->addSql('DROP INDEX IDX_6D0D401BF56F16CF ON sylius_cms_page_translation'); | ||
$this->addSql('ALTER TABLE sylius_cms_page_translation DROP teaser_image_id, DROP teaser_title, DROP teaser_content'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.