From b91458dd6c5ba06d3a4e40538ed669dc456a975e Mon Sep 17 00:00:00 2001 From: Stefan Hagspiel Date: Sat, 19 Nov 2022 00:41:36 +0100 Subject: [PATCH] update tests (#189) * update tests --- .github/workflows/codeception.yml | 28 ++++--- .github/workflows/ecs.yml | 8 +- .github/workflows/php-stan.yml | 8 +- composer.json | 4 +- .../Compiler/AreaBrickRegistryPass.php | 2 +- .../DependencyInjection/ToolboxExtension.php | 11 ++- .../ParallaxContainer/ParallaxContainer.php | 42 +++-------- .../Model/Document/Editable/ParallaxImage.php | 75 +++++++++++-------- .../partial/behind-front-elements.html.twig | 22 +++--- .../partial/behind-front-elements.html.twig | 22 +++--- tests/_etc/config/app/config.yml | 11 ++- 11 files changed, 123 insertions(+), 110 deletions(-) diff --git a/.github/workflows/codeception.yml b/.github/workflows/codeception.yml index 0acc8451..e929c946 100644 --- a/.github/workflows/codeception.yml +++ b/.github/workflows/codeception.yml @@ -18,7 +18,7 @@ jobs: PIMCORE_CODECEPTION_VERSION: "2.0" APP_ENV: test - PIMCORE_TEST_DB_DSN: "mysql://root:root@127.0.0.1:3306/dachcom_bundle_test" + PIMCORE_TEST_DB_DSN: "mysql://test:test@127.0.0.1:3306/dachcom_bundle_test" PIMCORE_TEST_URL: "http://localhost" PIMCORE_CLASS_DIRECTORY: "${{ github.workspace }}/lib/test-bundle/tests/_output/var/classes/DataObject" @@ -39,13 +39,11 @@ jobs: strategy: matrix: php: [ 8.0 ] - symfony: [ ^5.3 ] - pimcore: [ ~10.1.0, ~10.2.0 ] + symfony: [ ^5.4 ] + pimcore: [ ~10.5.0 ] include: - - pimcore: ~10.1.0 - template_tag: v10.1.0 - - pimcore: ~10.2.0 - template_tag: v10.1.4 + - pimcore: ~10.5.0 + template_tag: v10.2.0 steps: - uses: actions/checkout@v2 with: @@ -84,9 +82,19 @@ jobs: run: php -v - name: Setup MySql - run: | - sudo systemctl start mysql - mysql -uroot -proot -h127.0.0.1 -e "CREATE DATABASE dachcom_bundle_test CHARSET=utf8mb4;" + uses: shogo82148/actions-setup-mysql@v1 + with: + mysql-version: '8.0' + user: test + password: test + root-password: root + auto-start: true + my-cnf: | + max_allowed_packet=32505856 + max_connections=1000 + + - name: Initial Database + run: mysql -utest -ptest -h127.0.0.1 -e 'CREATE DATABASE dachcom_bundle_test CHARSET=utf8mb4;' - name: Setup Chromium run: | diff --git a/.github/workflows/ecs.yml b/.github/workflows/ecs.yml index 5287a708..bf01477b 100644 --- a/.github/workflows/ecs.yml +++ b/.github/workflows/ecs.yml @@ -38,11 +38,11 @@ jobs: strategy: matrix: php: [ 8.0 ] - symfony: [ ^5.3 ] - pimcore: [ ~10.1.0 ] + symfony: [ ^5.4 ] + pimcore: [ ~10.5.0 ] include: - - pimcore: ~10.1.0 - template_tag: v10.1.0 + - pimcore: ~10.5.0 + template_tag: v10.2.0 steps: - uses: actions/checkout@v2 with: diff --git a/.github/workflows/php-stan.yml b/.github/workflows/php-stan.yml index 1fff8cb3..c1095143 100644 --- a/.github/workflows/php-stan.yml +++ b/.github/workflows/php-stan.yml @@ -38,11 +38,11 @@ jobs: strategy: matrix: php: [ 8.0 ] - symfony: [ ^5.3 ] - pimcore: [ ~10.1.0 ] + symfony: [ ^5.4 ] + pimcore: [ ~10.5.0 ] include: - - pimcore: ~10.1.0 - template_tag: v10.1.0 + - pimcore: ~10.5.0 + template_tag: v10.2.0 steps: - uses: actions/checkout@v2 with: diff --git a/composer.json b/composer.json index 63063e9e..cd13ca3b 100755 --- a/composer.json +++ b/composer.json @@ -37,8 +37,8 @@ "codeception/codeception": "^4.1", "codeception/module-webdriver": "^1.4", "codeception/module-symfony": "^1.6", - "phpstan/phpstan": "^0.12", - "phpstan/phpstan-symfony": "^0.12", + "phpstan/phpstan": "^1.0", + "phpstan/phpstan-symfony": "^1.0", "symplify/easy-coding-standard": "^9.0" } } diff --git a/src/ToolboxBundle/DependencyInjection/Compiler/AreaBrickRegistryPass.php b/src/ToolboxBundle/DependencyInjection/Compiler/AreaBrickRegistryPass.php index 5239bcb9..18597314 100644 --- a/src/ToolboxBundle/DependencyInjection/Compiler/AreaBrickRegistryPass.php +++ b/src/ToolboxBundle/DependencyInjection/Compiler/AreaBrickRegistryPass.php @@ -146,7 +146,7 @@ public function process(ContainerBuilder $container): void } } - if (count($notEditDialogAwareBricks) > 0 && $container->hasParameter('toolbox.area_brick.dialog_aware_bricks')) { + if (count($notEditDialogAwareBricks) > 0) { $requestedEditDialogAwareBricks = $container->getParameter('toolbox.area_brick.dialog_aware_bricks'); foreach ($requestedEditDialogAwareBricks as $requestedEditDialogAwareBrickId) { if (in_array($requestedEditDialogAwareBrickId, $notEditDialogAwareBricks, true)) { diff --git a/src/ToolboxBundle/DependencyInjection/ToolboxExtension.php b/src/ToolboxBundle/DependencyInjection/ToolboxExtension.php index 4b9ea277..7f69e756 100644 --- a/src/ToolboxBundle/DependencyInjection/ToolboxExtension.php +++ b/src/ToolboxBundle/DependencyInjection/ToolboxExtension.php @@ -137,23 +137,30 @@ private function allocateGoogleMapsApiKey(ContainerBuilder $container): void $googleBrowserApiKey = null; $googleSimpleApiKey = null; - $pimcoreCoreConfig = $container->hasParameter('pimcore.config') ? $container->getParameter('pimcore.config') : []; - $pimcoreGoogleServiceConfig = isset($pimcoreCoreConfig['services'], $pimcoreCoreConfig['services']['google']) ? $pimcoreCoreConfig['services']['google'] : []; + $pimcoreCoreConfig = $container->getParameter('pimcore.config'); + /** @phpstan-ignore-next-line */ + $pimcoreGoogleServiceConfig = $pimcoreCoreConfig['services']['google'] ?? []; // browser api key + /** @phpstan-ignore-next-line */ if ($container->hasParameter('pimcore_system_config.services.google.browserapikey')) { $googleBrowserApiKey = $container->getParameter('pimcore_system_config.services.google.browserapikey'); + /** @phpstan-ignore-next-line */ } elseif ($container->hasParameter('toolbox_google_service_browser_api_key')) { $googleBrowserApiKey = $container->getParameter('toolbox_google_service_browser_api_key'); + /** @phpstan-ignore-next-line */ } elseif (isset($pimcoreGoogleServiceConfig['browser_api_key'])) { $googleBrowserApiKey = $pimcoreGoogleServiceConfig['browser_api_key']; } //simple api key + /** @phpstan-ignore-next-line */ if ($container->hasParameter('pimcore_system_config.services.google.simpleapikey')) { $googleSimpleApiKey = $container->getParameter('pimcore_system_config.services.google.simpleapikey'); + /** @phpstan-ignore-next-line */ } elseif ($container->hasParameter('toolbox_google_service_simple_api_key')) { $googleSimpleApiKey = $container->getParameter('toolbox_google_service_simple_api_key'); + /** @phpstan-ignore-next-line */ } elseif (isset($pimcoreGoogleServiceConfig['simple_api_key'])) { $googleSimpleApiKey = $pimcoreGoogleServiceConfig['simple_api_key']; } diff --git a/src/ToolboxBundle/Document/Areabrick/ParallaxContainer/ParallaxContainer.php b/src/ToolboxBundle/Document/Areabrick/ParallaxContainer/ParallaxContainer.php index 6f8c9b32..4b3c2213 100644 --- a/src/ToolboxBundle/Document/Areabrick/ParallaxContainer/ParallaxContainer.php +++ b/src/ToolboxBundle/Document/Areabrick/ParallaxContainer/ParallaxContainer.php @@ -2,6 +2,7 @@ namespace ToolboxBundle\Document\Areabrick\ParallaxContainer; +use Pimcore\Model\Element\ElementInterface; use Pimcore\Translation\Translator; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Templating\EngineInterface; @@ -28,26 +29,25 @@ public function action(Editable\Area\Info $info): ?Response /** @var Editable\Relation $parallaxBackgroundElement */ $parallaxBackgroundElement = $this->getDocumentEditable($info->getDocument(), 'relation', 'background_image'); - $parallaxBackground = $parallaxBackgroundElement->getElement(); $parallaxBackgroundColor = $this->getDocumentEditable($info->getDocument(), 'select', 'background_color')->getData(); $parallaxTemplate = $this->getDocumentEditable($info->getDocument(), 'select', 'template')->getData(); $parallaxBehind = $this->getDocumentEditable($info->getDocument(), 'parallaximage', 'image_behind'); $parallaxFront = $this->getDocumentEditable($info->getDocument(), 'parallaximage', 'image_front'); - $backgroundMode = isset($config['background_mode']) ? $config['background_mode'] : 'wrap'; - $backgroundImageMode = isset($config['background_image_mode']) ? $config['background_image_mode'] : 'data'; + $backgroundMode = $config['background_mode'] ?? 'wrap'; + $backgroundImageMode = $config['background_image_mode'] ?? 'data'; - $backgroundTags = $this->getBackgroundTags($parallaxBackground, $parallaxBackgroundColor, $config, 'section'); + $backgroundTags = $this->getBackgroundTags($parallaxBackgroundElement->getElement(), $parallaxBackgroundColor, $config, 'section'); $backgroundColorClass = $this->getBackgroundColorClass($parallaxBackgroundColor, $config, 'section'); - $behindElements = !empty($parallaxBehind) + $behindElements = !$parallaxFront->isEmpty() ? $this->templating->render( $this->getTemplatePath('partial/behind-front-elements'), ['elements' => $parallaxBehind, 'backgroundImageMode' => $backgroundImageMode, 'document' => $info->getDocument()] ) : null; - $frontElements = !empty($parallaxFront) + $frontElements = !$parallaxFront->isEmpty() ? $this->templating->render( $this->getTemplatePath('partial/behind-front-elements'), ['elements' => $parallaxFront, 'backgroundImageMode' => $backgroundImageMode, 'document' => $info->getDocument()] @@ -84,14 +84,12 @@ private function _buildSectionContent(Editable\Area\Info $info) $loopIndex = 1; while ($sectionBlock->loop()) { - $sectionConfig = ''; /** @var Editable\Relation $parallaxBackgroundElement */ $parallaxBackgroundElement = $this->getDocumentEditable($info->getDocument(), 'relation', 'background_image'); - $parallaxBackground = $parallaxBackgroundElement->getElement(); $parallaxBackgroundColor = $this->getDocumentEditable($info->getDocument(), 'select', 'background_color')->getData(); - $backgroundTags = $this->getBackgroundTags($parallaxBackground, $parallaxBackgroundColor, $config, 'section'); + $backgroundTags = $this->getBackgroundTags($parallaxBackgroundElement->getElement(), $parallaxBackgroundColor, $config, 'section'); $backgroundColorClass = $this->getBackgroundColorClass($parallaxBackgroundColor, $config, 'section'); $template = $this->getDocumentEditable($info->getDocument(), 'select', 'template')->getData(); @@ -106,7 +104,7 @@ private function _buildSectionContent(Editable\Area\Info $info) $areaBlock = sprintf($wrapContent, $areaBlock); } - if ($info->getEditable()->getEditmode() === true) { + if ($info->getEditable()?->getEditmode() === true) { if ($containerWrapper === 'none' && str_contains($areaBlock, 'toolbox-columns')) { $message = $this->translator->trans('You\'re using columns without a valid container wrapper.', [], 'admin'); $messageWrap = $this->templating->render('@Toolbox/helper/field-alert.' . $this->getTemplateSuffix(), [ @@ -137,16 +135,9 @@ private function _buildSectionContent(Editable\Area\Info $info) } /** - * @param Asset $backgroundImage - * @param string $backgroundColor - * @param array $config - * @param string $type - * - * @return string - * * @throws \Exception */ - private function getBackgroundTags($backgroundImage, $backgroundColor, $config = [], $type = 'parallax') + private function getBackgroundTags(?ElementInterface $backgroundImage, ?string $backgroundColor, array $config = [], string $type = 'parallax'): string { $backgroundImageMode = $config['background_image_mode'] ?? 'data'; $backgroundColorMode = $config['background_color_mode'] ?? 'data'; @@ -193,14 +184,7 @@ private function getBackgroundTags($backgroundImage, $backgroundColor, $config = return $str; } - /** - * @param string $backgroundColor - * @param array $config - * @param string $type - * - * @return string - */ - private function getBackgroundColorClass($backgroundColor, $config = [], $type = 'parallax') + private function getBackgroundColorClass(?string $backgroundColor, array $config = [], string $type = 'parallax'): string { $mode = $config['background_color_mode'] ?? 'data'; if ($backgroundColor === 'no-background-color' || empty($backgroundColor) || $mode !== 'class') { @@ -220,17 +204,11 @@ public function getTemplate(): string return sprintf('@Toolbox/areas/%s/view.%s', $this->getTemplateDirectoryName(), $this->getTemplateSuffix()); } - /** - * @return string - */ public function getName(): string { return 'Parallax Container'; } - /** - * @return string - */ public function getDescription(): string { return 'Toolbox Parallax Container'; diff --git a/src/ToolboxBundle/Model/Document/Editable/ParallaxImage.php b/src/ToolboxBundle/Model/Document/Editable/ParallaxImage.php index fa6fa9e9..69fb8a50 100644 --- a/src/ToolboxBundle/Model/Document/Editable/ParallaxImage.php +++ b/src/ToolboxBundle/Model/Document/Editable/ParallaxImage.php @@ -10,6 +10,18 @@ class ParallaxImage extends Model\Document\Editable\Relations { + protected array $parallaxProperties = []; + + public function getParallaxProperties(): array + { + return $this->parallaxProperties; + } + + public function getParallaxPropertyByIndex(int $index) + { + return $this->parallaxProperties[$index] ?? []; + } + public function getType(): string { return 'parallaximage'; @@ -22,8 +34,8 @@ public function setElements(): self foreach ($this->elementIds as $elementId) { $el = Element\Service::getElementById($elementId['type'], $elementId['id']); if ($el instanceof Element\ElementInterface) { - $this->elements[] = [ - 'obj' => $el, + $this->elements[] = $el; + $this->parallaxProperties[] = [ 'parallaxPosition' => $elementId['parallaxPosition'], 'parallaxSize' => $elementId['parallaxSize'] ]; @@ -40,43 +52,42 @@ public function getDataEditmode(): array $return = []; if (is_array($this->elements) && count($this->elements) > 0) { - foreach ($this->elements as $element) { - $obj = $element['obj']; - if ($obj instanceof DataObject\Concrete) { + foreach ($this->elements as $index => $element) { + if ($element instanceof DataObject\Concrete) { $return[] = [ - $obj->getId(), - $obj->getRealFullPath(), + $element->getId(), + $element->getRealFullPath(), 'object', - $obj->getClassName(), - $element['parallaxPosition'], - $element['parallaxSize'] + $element->getClassName(), + $this->parallaxProperties[$index]['parallaxPosition'] ?? null, + $this->parallaxProperties[$index]['parallaxSize'] ?? null, ]; - } elseif ($obj instanceof DataObject\AbstractObject) { + } elseif ($element instanceof DataObject\AbstractObject) { $return[] = [ - $obj->getId(), - $obj->getRealFullPath(), + $element->getId(), + $element->getRealFullPath(), 'object', 'folder', - $element['parallaxPosition'], - $element['parallaxSize'] + $this->parallaxProperties[$index]['parallaxPosition'] ?? null, + $this->parallaxProperties[$index]['parallaxSize'] ?? null, ]; - } elseif ($obj instanceof Asset) { + } elseif ($element instanceof Asset) { $return[] = [ - $obj->getId(), - $obj->getRealFullPath(), + $element->getId(), + $element->getRealFullPath(), 'asset', - $obj->getType(), - $element['parallaxPosition'], - $element['parallaxSize'] + $element->getType(), + $this->parallaxProperties[$index]['parallaxPosition'] ?? null, + $this->parallaxProperties[$index]['parallaxSize'] ?? null, ]; - } elseif ($obj instanceof Document) { + } elseif ($element instanceof Document) { $return[] = [ - $obj->getId(), - $obj->getRealFullPath(), + $element->getId(), + $element->getRealFullPath(), 'document', - $obj->getType(), - $element['parallaxPosition'], - $element['parallaxSize'] + $element->getType(), + $this->parallaxProperties[$index]['parallaxPosition'] ?? null, + $this->parallaxProperties[$index]['parallaxSize'] ?? null, ]; } } @@ -106,13 +117,11 @@ public function resolveDependencies(): array if (is_array($this->elements) && count($this->elements) > 0) { foreach ($this->elements as $element) { - $obj = $element['obj']; - if ($obj instanceof Element\ElementInterface) { - $elementType = Element\Service::getElementType($obj); - $key = $elementType . '_' . $obj->getId(); - + if ($element instanceof Element\ElementInterface) { + $elementType = Element\Service::getElementType($element); + $key = $elementType . '_' . $element->getId(); $dependencies[$key] = [ - 'id' => $obj->getId(), + 'id' => $element->getId(), 'type' => $elementType ]; } diff --git a/src/ToolboxBundle/Resources/views/toolbox/bootstrap3/parallax-container/partial/behind-front-elements.html.twig b/src/ToolboxBundle/Resources/views/toolbox/bootstrap3/parallax-container/partial/behind-front-elements.html.twig index 588a580d..cbcc3c66 100644 --- a/src/ToolboxBundle/Resources/views/toolbox/bootstrap3/parallax-container/partial/behind-front-elements.html.twig +++ b/src/ToolboxBundle/Resources/views/toolbox/bootstrap3/parallax-container/partial/behind-front-elements.html.twig @@ -1,23 +1,25 @@ -{% for element in elements.elements %} +{% for index, element in elements.elements %} - {% set imageUrl = element.obj is instanceof('\Pimcore\Model\Asset') - ? element.obj.thumbnail(toolbox_get_image_thumbnail('parallax_container_element')) + {% set parallaxProperties = elements.getParallaxPropertyByIndex(index) %} + + {% set imageUrl = element is instanceof('\Pimcore\Model\Asset') + ? element.thumbnail(toolbox_get_image_thumbnail('parallax_container_element')) : '' %} {% set parallaxImageTag = backgroundImageMode == 'style' ? 'style="background-image:url('~imageUrl~');"' : 'data-background-image="'~imageUrl~'"' %} - {% set orgWidth = element['obj'].width %} - {% set width = element['obj'].thumbnail(toolbox_get_image_thumbnail('parallax_container_element')).width() %} - {% set orgHeight = element['obj'].height() %} - {% set height = element['obj'].thumbnail(toolbox_get_image_thumbnail('parallax_container_element')).height() %} + {% set orgWidth = element.width %} + {% set width = element.thumbnail(toolbox_get_image_thumbnail('parallax_container_element')).width %} + {% set orgHeight = element.height %} + {% set height = element.thumbnail(toolbox_get_image_thumbnail('parallax_container_element')).height %} -
+ data-element-position="{{ parallaxProperties.parallaxPosition ?? '' }}" + data-element-size="{{ parallaxProperties.parallaxSize ?? '' }}">
{% endfor %} \ No newline at end of file diff --git a/src/ToolboxBundle/Resources/views/toolbox/bootstrap4/parallax-container/partial/behind-front-elements.html.twig b/src/ToolboxBundle/Resources/views/toolbox/bootstrap4/parallax-container/partial/behind-front-elements.html.twig index 12fcc823..89a266fc 100644 --- a/src/ToolboxBundle/Resources/views/toolbox/bootstrap4/parallax-container/partial/behind-front-elements.html.twig +++ b/src/ToolboxBundle/Resources/views/toolbox/bootstrap4/parallax-container/partial/behind-front-elements.html.twig @@ -1,23 +1,25 @@ -{% for element in elements.elements %} +{% for index, element in elements.elements %} - {% set imageUrl = element.obj is not null - ? element.obj.thumbnail(toolbox_get_image_thumbnail('parallax_container_element')) + {% set parallaxProperties = elements.getParallaxPropertyByIndex(index) %} + + {% set imageUrl = element is not null + ? element.thumbnail(toolbox_get_image_thumbnail('parallax_container_element')) : '' %} {% set parallaxImageTag = backgroundImageMode == 'style' ? 'style="background-image:url('~imageUrl~');"' : 'data-background-image="'~imageUrl~'"' %} - {% set orgWidth = element['obj'].width %} - {% set width = element['obj'].thumbnail(toolbox_get_image_thumbnail('parallax_container_element')).width %} - {% set orgHeight = element['obj'].height %} - {% set height = element['obj'].thumbnail(toolbox_get_image_thumbnail('parallax_container_element')).height %} + {% set orgWidth = element.width %} + {% set width = element.thumbnail(toolbox_get_image_thumbnail('parallax_container_element')).width %} + {% set orgHeight = element.height %} + {% set height = element.thumbnail(toolbox_get_image_thumbnail('parallax_container_element')).height %} -
+ data-element-position="{{ parallaxProperties.parallaxPosition ?? '' }}" + data-element-size="{{ parallaxProperties.parallaxSize ?? '' }}">
{% endfor %} \ No newline at end of file diff --git a/tests/_etc/config/app/config.yml b/tests/_etc/config/app/config.yml index 54742905..7dfc0111 100755 --- a/tests/_etc/config/app/config.yml +++ b/tests/_etc/config/app/config.yml @@ -18,11 +18,18 @@ doctrine: enum: string bit: boolean +pimcore_admin: + admin_csp_header: + enabled: false + +pimcore: + targeting: + enabled: false + framework: - # @see https://github.com/pimcore/pimcore/issues/11042 session: - storage_id: session.storage.native + storage_factory_id: session.storage.factory.native profiler: enabled: true