Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added integration test for Magento\Sales\Cron\CleanExpiredQuotes class. #24858

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Sales\Cron;

use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Quote\Model\QuoteRepository;
use Magento\TestFramework\Helper\Bootstrap;

/**
* Test for Magento\Sales\Cron\CleanExpiredQuotes class.
*
* @magentoAppIsolation enabled
* @magentoDbIsolation enabled
*/
class CleanExpiredQuotesTest extends \PHPUnit\Framework\TestCase
{
/**
* @var CleanExpiredQuotes
*/
private $cleanExpiredQuotes;

/**
* @var QuoteRepository
*/
private $quoteRepository;

/**
* @var SearchCriteriaBuilder
*/
private $searchCriteriaBuilder;

/**
* @inheritdoc
*/
protected function setUp()
{
$objectManager = Bootstrap::getObjectManager();
$this->cleanExpiredQuotes = $objectManager->get(CleanExpiredQuotes::class);
$this->quoteRepository = $objectManager->get(QuoteRepository::class);
$this->searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
}

/**
* Check if outdated quotes are deleted.
*
* @magentoConfigFixture default_store checkout/cart/delete_quote_after -365
* @magentoDataFixture Magento/Sales/_files/quotes.php
*/
public function testExecute()
{
$this->cleanExpiredQuotes->execute();
$searchCriteria = $this->searchCriteriaBuilder->create();
$totalCount = $this->quoteRepository->getList($searchCriteria)->getTotalCount();

$this->assertEquals(
1,
$totalCount
);
}
}
35 changes: 35 additions & 0 deletions dev/tests/integration/testsuite/Magento/Sales/_files/quotes.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Quote\Model\QuoteFactory;
use Magento\Quote\Model\QuoteRepository;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\ObjectManager;

require dirname(dirname(__DIR__)) . '/Store/_files/second_store.php';

/** @var $objectManager ObjectManager */
$objectManager = Bootstrap::getObjectManager();
/** @var QuoteFactory $quoteFactory */
$quoteFactory = $objectManager->get(QuoteFactory::class);
/** @var QuoteRepository $quoteRepository */
$quoteRepository = $objectManager->get(QuoteRepository::class);

$quotes = [
'quote for first store' => [
'store' => 1,
],
'quote for second store' => [
'store' => 2,
],
];

foreach ($quotes as $quoteData) {
$quote = $quoteFactory->create();
$quote->setStoreId($quoteData['store']);
$quoteRepository->save($quote);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

use Magento\Framework\Api\SearchCriteriaBuilder;
use Magento\Framework\Registry;
use Magento\Quote\Model\QuoteRepository;
use Magento\TestFramework\Helper\Bootstrap;
use Magento\TestFramework\ObjectManager;

/** @var ObjectManager $objectManager */
$objectManager = Bootstrap::getObjectManager();

/** @var Registry $registry */
$registry = $objectManager->get(Registry::class);
$registry->unregister('isSecureArea');
$registry->register('isSecureArea', true);

/** @var QuoteRepository $quoteRepository */
$quoteRepository = $objectManager->get(QuoteRepository::class);
/** @var SearchCriteriaBuilder $searchCriteriaBuilder */
$searchCriteriaBuilder = $objectManager->get(SearchCriteriaBuilder::class);
$searchCriteria = $searchCriteriaBuilder->create();
$items = $quoteRepository->getList($searchCriteria)
->getItems();
foreach ($items as $item) {
$quoteRepository->delete($item);
}

$registry->unregister('isSecureArea');
$registry->register('isSecureArea', false);

require dirname(dirname(__DIR__)) . '/Store/_files/second_store_rollback.php';