getActions example

/** * @internal */
class MetadataTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);

        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());

        $firstAction = $flowActions->getActions()->getActions()[0];
        $meta = $firstAction->getMeta();

        static::assertEquals('abc.cde.ccc', $meta->getName());
        static::assertEquals(['order', 'customer']$meta->getRequirements());
        static::assertEquals('https://example.xyz', $meta->getUrl());
        static::assertEquals('sw-pencil', $meta->getSwIcon());
        static::assertEquals('resource/pencil', $meta->getIcon());
        static::assertEquals(
            [
return $allow;
    }

    /** * @return array<array<string, array{name: string, eventName: string, url: string, appId: string, active: bool, errorCount: int}>> */
    private function getWebhooks(Manifest $manifest, ?Action $flowActions, string $appId, string $defaultLocale, bool $hasAppSecret): array
    {
        $actions = [];

        if ($flowActions) {
            $actions = $flowActions->getActions()?->getActions() ?? [];
        }

        $webhooks = array_map(function D$action) use ($appId) {
            $name = $action->getMeta()->getName();

            return [
                'name' => $name,
                'eventName' => $name,
                'url' => $action->getMeta()->getUrl(),
                'appId' => $appId,
                'active' => true,
                
/** * @internal */
class ActionTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);

        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());

        $firstAction = $flowActions->getActions()->getActions()[0];
        static::assertNotNull($firstAction->getMeta());
        static::assertNotNull($firstAction->getHeaders());
        static::assertNotNull($firstAction->getParameters());
        static::assertNotNull($firstAction->getConfig());

        static::assertEquals('abc.cde.ccc', $firstAction->getMeta()->getName());
        static::assertEquals(['order', 'customer']$firstAction->getMeta()->getRequirements());
        static::assertEquals(
            [
$appLoader = new AppLoader(
            __DIR__,
            __DIR__,
            new ConfigReader()
        );

        $appEntity = new AppEntity();
        $appEntity->setPath('../_fixtures/');

        $flowActions = $appLoader->getFlowActions($appEntity);
        static::assertNotNull($flowActions);
        static::assertNotNull($flowActions->getActions());
    }

    public function testGetFlowActionsWithFileNotExist(): void
    {
        $appLoader = new AppLoader(
            __DIR__,
            __DIR__,
            new ConfigReader()
        );

        $appEntity = new AppEntity();
        
$sequence->assign([
            'actionName' => null,
        ]);

        $this->ids['rule'] = array_filter($ruleIdsfn ($ruleId) => $ruleId !== $randomRuleId);

        return $sequence;
    }

    private function buildActionSequence(FlowSequenceEntity $parent, bool $trueCase = true): FlowSequenceEntity
    {
        $actions = $this->getActions();

        $sequence = FlowSequenceEntity::createFrom($parent);

        /** @var FlowActionDefinition $action */
        $action = $this->faker->randomElement($actions);
        $sequence->setId(Uuid::randomHex());

        $sequence->setParentId($parent->getId());
        $sequence->setActionName($action->getName());
        $sequence->setConfig($this->generateActionConfig($action->getName()));
        $sequence->setTrueCase($trueCase);
        


    /** * @param list<array<string, mixed>> $violationsData * * @return StoreLicenseViolationStruct[] */
    private function getViolations(array $violationsData): array
    {
        $violations = [];
        foreach ($violationsData as $violationData) {
            $violationData['actions'] = $this->getActions($violationData['actions'] ?? []);
            $violationData['type'] = (new StoreLicenseViolationTypeStruct())->assign($violationData['type']);
            $expired = new StoreLicenseViolationStruct();
            $expired->assign($violationData);
            $violations[] = $expired;
        }

        return $violations;
    }

    /** * @param list<array<string, mixed>> $actionsData * * @return StoreActionStruct[] */
/** * @internal */
class HeadersTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);

        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());

        $firstAction = $flowActions->getActions()->getActions()[0];
        $headers = $firstAction->getHeaders();

        static::assertCount(2, $headers->getParameters());
    }
}
use Shopware\Core\Framework\Feature;

/** * @internal */
class ConfigTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);
        static::assertNotNull($flowActions->getActions());

        static::assertCount(1, $flowActions->getActions()->getActions());
        static::assertCount(4, $flowActions->getActions()->getActions()[0]->getConfig()->getConfig());
    }
}
use Shopware\Core\Framework\Feature;

/** * @internal */
class InputFieldTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);
        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());
        $config = $flowActions->getActions()->getActions()[0]->getConfig()->getConfig();
        static::assertCount(4, $config);

        $firstInputField = $config[0];

        static::assertEquals('textField', $firstInputField->getName());
        static::assertEquals('text', $firstInputField->getType());
        static::assertEquals([
            'en-GB' => 'To',
            'de-DE' => 'To DE',
        ],
public function testFromXml(): void
    {
        $document = XmlUtils::loadFile(
            __DIR__ . '/../../../_fixtures/Resources/flow-action.xml',
            __DIR__ . '/../../../../../../../../src/Core/Framework/App/FlowAction/Schema/flow-action-1.0.xsd'
        );

        /** @var \DOMElement $actions */
        $actions = $document->getElementsByTagName('flow-actions')->item(0);

        $action = Actions::fromXml($actions);
        static::assertCount(1, $action->getActions());
        static::assertInstanceOf(Action::class$action->getActions()[0]);
    }
}
use Shopware\Core\Framework\Feature;

/** * @internal */
class ActionsTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);
        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());
    }
}
private readonly Connection $connection
    ) {
    }

    public function updateActions(Action $flowAction, string $appId, Context $context, string $defaultLocale): void
    {
        /** @var array<string, string> $existingFlowActions */
        $existingFlowActions = $this->connection->fetchAllKeyValue('SELECT name, LOWER(HEX(id)) FROM app_flow_action WHERE app_id = :appId', [
            'appId' => Uuid::fromHexToBytes($appId),
        ]);

        $flowActions = $flowAction->getActions() ? $flowAction->getActions()->getActions() : [];
        $upserts = [];

        foreach ($flowActions as $action) {
            if ($icon = $action->getMeta()->getIcon()) {
                $icon = $this->appLoader->loadFile($flowAction->getPath()$icon);
            }

            $payload = array_merge([
                'appId' => $appId,
                'iconRaw' => $icon,
            ]$action->toArray($defaultLocale));

            
public function testCreateFromXmlWithFlowAction(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/_fixtures/valid/major/flow.xml' : '/_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);

        if (Feature::isActive('v6.6.0.0')) {
            static::assertEquals(__DIR__ . '/_fixtures/valid/major', $flowActions->getPath());
        } else {
            static::assertEquals(__DIR__ . '/_fixtures/valid/minor', $flowActions->getPath());
        }

        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());
    }

    public function testCreateFromXmlMissingFlowAction(): void
    {
        static::expectException(XmlParsingException::class);
        static::expectExceptionMessage('[ERROR 1871] Element \'flow-actions\': Missing child element(s). Expected is ( flow-action ).');
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/_fixtures/invalid/FlowActionsWithoutFlowActionMajor/flow.xml' : '/_fixtures/invalid/FlowActionsWithoutFlowAction/flow-action.xml';
        Action::createFromXmlFile(__DIR__ . $flowActionsFile);
    }

    
/** * @internal */
class ParameterTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);

        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());

        $firstAction = $flowActions->getActions()->getActions()[0];
        $firstHeaderParameter = $firstAction->getHeaders()->getParameters()[0];
        $firstParameter = $firstAction->getParameters()->getParameters()[0];

        static::assertEquals('string', $firstHeaderParameter->getType());
        static::assertEquals('content-type', $firstHeaderParameter->getName());
        static::assertEquals('application/json', $firstHeaderParameter->getValue());

        static::assertEquals('string', $firstParameter->getType());
        
/** * @internal */
class ParametersTest extends TestCase
{
    public function testFromXml(): void
    {
        $flowActionsFile = Feature::isActive('v6.6.0.0') ? '/../_fixtures/valid/major/flow.xml' : '/../_fixtures/valid/minor/flow-action.xml';
        $flowActions = Action::createFromXmlFile(__DIR__ . $flowActionsFile);

        static::assertNotNull($flowActions->getActions());
        static::assertCount(1, $flowActions->getActions()->getActions());

        $firstAction = $flowActions->getActions()->getActions()[0];
        $parameters = $firstAction->getParameters();

        static::assertCount(3, $parameters->getParameters());
    }
}
Home | Imprint | This part of the site doesn't use cookies.