block_rollback.php 1.0 KB

123456789101112131415161718192021222324252627282930
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. use Magento\Cms\Api\BlockRepositoryInterface;
  8. use Magento\Cms\Api\Data\BlockInterface;
  9. use Magento\Framework\Api\SearchCriteriaBuilder;
  10. use Magento\TestFramework\Helper\Bootstrap;
  11. $objectManager = Bootstrap::getObjectManager();
  12. /** @var BlockRepositoryInterface $blockRepository */
  13. $blockRepository = $objectManager->get(BlockRepositoryInterface::class);
  14. /** @var SearchCriteriaBuilder $searchCriteriaBuilder */
  15. $searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
  16. $searchCriteria = $searchCriteriaBuilder->addFilter(BlockInterface::IDENTIFIER, 'fixture_block')
  17. ->create();
  18. $result = $blockRepository->getList($searchCriteria);
  19. /**
  20. * Tests which are wrapped with MySQL transaction clear all data by transaction rollback.
  21. * In that case there is "if" which checks that "fixture_block" still exists in database.
  22. */
  23. foreach ($result->getItems() as $item) {
  24. $blockRepository->delete($item);
  25. }