|
| 1 | +<?php |
| 2 | +declare(strict_types=1); |
| 3 | + |
| 4 | +/** |
| 5 | + * This source file is available under the terms of the |
| 6 | + * Pimcore Open Core License (POCL) |
| 7 | + * Full copyright and license information is available in |
| 8 | + * LICENSE.md which is distributed with this source code. |
| 9 | + * |
| 10 | + * @copyright Copyright (c) Pimcore GmbH (https://www.pimcore.com) |
| 11 | + * @license Pimcore Open Core License (POCL) |
| 12 | + */ |
| 13 | + |
| 14 | +namespace Pimcore\Bundle\StudioBackendBundle\Tests\Unit\Grid\Column\Resolver\DataObject; |
| 15 | + |
| 16 | +use Codeception\Test\Unit; |
| 17 | +use Pimcore\Bundle\StaticResolverBundle\Lib\ToolResolverInterface; |
| 18 | +use Pimcore\Bundle\StaticResolverBundle\Models\DataObject\LocalizedFieldResolverInterface; |
| 19 | +use Pimcore\Bundle\StudioBackendBundle\Grid\Column\CoreElementColumnResolverInterface; |
| 20 | +use Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\DataObject\AdvancedColumnResolver; |
| 21 | +use Pimcore\Bundle\StudioBackendBundle\Grid\Column\Resolver\ResolverTypeGuesserInterface; |
| 22 | +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\Column; |
| 23 | +use Pimcore\Bundle\StudioBackendBundle\Grid\Schema\ColumnData; |
| 24 | +use Pimcore\Bundle\StudioBackendBundle\Grid\Service\GridServiceInterface; |
| 25 | +use Pimcore\Bundle\StudioBackendBundle\Grid\Service\TransformerLoaderInterface; |
| 26 | +use Pimcore\Bundle\StudioBackendBundle\Grid\Util\AdvancedValue; |
| 27 | +use Pimcore\Model\DataObject\Concrete; |
| 28 | + |
| 29 | +/** |
| 30 | + * @internal |
| 31 | + */ |
| 32 | +final class AdvancedColumnResolverTest extends Unit |
| 33 | +{ |
| 34 | + public function testResolveForCoreElementResolvesClassificationStoreField(): void |
| 35 | + { |
| 36 | + $classificationStoreResolver = $this->makeEmpty(CoreElementColumnResolverInterface::class, [ |
| 37 | + 'resolveForCoreElement' => static function (Column $column): ColumnData { |
| 38 | + // The advanced resolver must forward the picked group/key as the sub column config |
| 39 | + self::assertSame('dataobject.classificationstore', $column->getType()); |
| 40 | + self::assertSame('csstore', $column->getKey()); |
| 41 | + self::assertSame(['groupId' => 5, 'keyId' => 7], $column->getConfig()); |
| 42 | + |
| 43 | + return new ColumnData( |
| 44 | + key: 'csstore.size', |
| 45 | + locale: null, |
| 46 | + value: 'XL', |
| 47 | + fieldType: 'input', |
| 48 | + ); |
| 49 | + }, |
| 50 | + ]); |
| 51 | + |
| 52 | + $resolver = new AdvancedColumnResolver( |
| 53 | + $this->makeEmpty(TransformerLoaderInterface::class, ['loadTransformers' => []]), |
| 54 | + $this->makeEmpty(GridServiceInterface::class, [ |
| 55 | + 'getColumnResolvers' => ['dataobject.classificationstore' => $classificationStoreResolver], |
| 56 | + ]), |
| 57 | + $this->makeEmpty(ResolverTypeGuesserInterface::class, [ |
| 58 | + 'guessType' => 'dataobject.classificationstore', |
| 59 | + 'isLocalizable' => false, |
| 60 | + ]), |
| 61 | + $this->makeEmpty(ToolResolverInterface::class), |
| 62 | + $this->makeEmpty(LocalizedFieldResolverInterface::class), |
| 63 | + ); |
| 64 | + |
| 65 | + $column = new Column( |
| 66 | + key: 'advanced', |
| 67 | + locale: null, |
| 68 | + type: 'dataobject.advanced', |
| 69 | + group: ['advanced'], |
| 70 | + config: [ |
| 71 | + 'advancedColumns' => [ |
| 72 | + [ |
| 73 | + 'key' => 'simpleField', |
| 74 | + 'config' => ['field' => 'csstore', 'groupId' => 5, 'keyId' => 7], |
| 75 | + ], |
| 76 | + ], |
| 77 | + 'transformers' => [], |
| 78 | + ], |
| 79 | + ); |
| 80 | + |
| 81 | + $element = $this->makeEmpty(Concrete::class, ['getClassId' => 'CAR']); |
| 82 | + |
| 83 | + $result = $resolver->resolveForCoreElement($column, $element); |
| 84 | + |
| 85 | + $values = $result->getValue(); |
| 86 | + $this->assertIsArray($values); |
| 87 | + $this->assertCount(1, $values); |
| 88 | + $this->assertInstanceOf(AdvancedValue::class, $values[0]); |
| 89 | + $this->assertSame('XL', $values[0]->getValue()); |
| 90 | + $this->assertSame('input', $values[0]->getType()); |
| 91 | + $this->assertSame('csstore', $values[0]->getFieldName()); |
| 92 | + $this->assertNull($values[0]->getRelation()); |
| 93 | + } |
| 94 | +} |
0 commit comments