|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright 2025 Adobe |
| 4 | + * All Rights Reserved. |
| 5 | + */ |
| 6 | +declare(strict_types=1); |
| 7 | + |
| 8 | +namespace Magento\Cms\Test\Fixture; |
| 9 | + |
| 10 | +use Magento\Cms\Api\Data\PageInterface; |
| 11 | +use Magento\Cms\Api\PageRepositoryInterface; |
| 12 | +use Magento\Framework\DataObject; |
| 13 | +use Magento\TestFramework\Fixture\Api\ServiceFactory; |
| 14 | +use Magento\TestFramework\Fixture\Data\ProcessorInterface; |
| 15 | +use Magento\TestFramework\Fixture\RevertibleDataFixtureInterface; |
| 16 | + |
| 17 | +class Page implements RevertibleDataFixtureInterface |
| 18 | +{ |
| 19 | + private const DEFAULT_DATA = [ |
| 20 | + PageInterface::IDENTIFIER => 'page%uniqid%', |
| 21 | + PageInterface::TITLE => 'Page%uniqid%', |
| 22 | + PageInterface::CONTENT => 'PageContent%uniqid%', |
| 23 | + PageInterface::CREATION_TIME => null, |
| 24 | + PageInterface::UPDATE_TIME => null, |
| 25 | + 'active' => true |
| 26 | + ]; |
| 27 | + |
| 28 | + /** |
| 29 | + * @param ProcessorInterface $dataProcessor |
| 30 | + * @param ServiceFactory $serviceFactory |
| 31 | + */ |
| 32 | + public function __construct( |
| 33 | + private readonly ProcessorInterface $dataProcessor, |
| 34 | + private readonly ServiceFactory $serviceFactory |
| 35 | + ) { |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * {@inheritdoc} |
| 40 | + * @param array $data Parameters. Same format as Block::DEFAULT_DATA. |
| 41 | + */ |
| 42 | + public function apply(array $data = []): ?DataObject |
| 43 | + { |
| 44 | + $data = $this->dataProcessor->process($this, array_merge(self::DEFAULT_DATA, $data)); |
| 45 | + $service = $this->serviceFactory->create(PageRepositoryInterface::class, 'save'); |
| 46 | + |
| 47 | + return $service->execute(['page' => $data]); |
| 48 | + } |
| 49 | + |
| 50 | + /** |
| 51 | + * @inheritdoc |
| 52 | + */ |
| 53 | + public function revert(DataObject $data): void |
| 54 | + { |
| 55 | + $service = $this->serviceFactory->create(PageRepositoryInterface::class, 'deleteById'); |
| 56 | + $service->execute(['pageId' => $data->getId()]); |
| 57 | + } |
| 58 | +} |
0 commit comments