Skip to content

Commit

Permalink
update tests (#189)
Browse files Browse the repository at this point in the history
* update tests
  • Loading branch information
solverat authored Nov 18, 2022
1 parent 95d0537 commit b91458d
Show file tree
Hide file tree
Showing 11 changed files with 123 additions and 110 deletions.
28 changes: 18 additions & 10 deletions .github/workflows/codeception.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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:
Expand Down Expand Up @@ -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: |
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/ecs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/php-stan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
11 changes: 9 additions & 2 deletions src/ToolboxBundle/DependencyInjection/ToolboxExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()]
Expand Down Expand Up @@ -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();
Expand All @@ -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(), [
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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') {
Expand All @@ -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';
Expand Down
75 changes: 42 additions & 33 deletions src/ToolboxBundle/Model/Document/Editable/ParallaxImage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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']
];
Expand All @@ -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,
];
}
}
Expand Down Expand Up @@ -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
];
}
Expand Down
Loading

0 comments on commit b91458d

Please sign in to comment.