123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\SalesRule\Test\Unit\Model\ResourceModel;
- use Magento\SalesRule\Model\ResourceModel\ReadHandler;
- use Magento\SalesRule\Model\ResourceModel\Rule;
- use Magento\Framework\EntityManager\MetadataPool;
- use Magento\SalesRule\Api\Data\RuleInterface;
- /**
- * Class ReadHandlerTest
- */
- class ReadHandlerTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var ReadHandler
- */
- protected $model;
- /**
- * @var Rule|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $ruleResource;
- /**
- * @var MetadataPool|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $metadataPool;
- /**
- * @var \Magento\Framework\TestFramework\Unit\Helper\ObjectManager
- */
- protected $objectManager;
- /**
- * Setup the test
- */
- protected function setUp()
- {
- $this->objectManager = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
- $className = \Magento\SalesRule\Model\ResourceModel\Rule::class;
- $this->ruleResource = $this->createMock($className);
- $className = \Magento\Framework\EntityManager\MetadataPool::class;
- $this->metadataPool = $this->createMock($className);
- $this->model = $this->objectManager->getObject(
- ReadHandler::class,
- [
- 'ruleResource' => $this->ruleResource,
- 'metadataPool' => $this->metadataPool,
- ]
- );
- }
- /**
- * test Execute
- */
- public function testExecute()
- {
- $entityData = [
- 'row_id' => 2,
- 'rule_id' => 1
- ];
- $customers = [1, 2];
- $websites = [3, 4, 5];
- $className = \Magento\Framework\EntityManager\EntityMetadata::class;
- $metadata = $this->createMock($className);
- $metadata->expects($this->once())
- ->method('getLinkField')
- ->willReturn('rule_id');
- $this->metadataPool->expects($this->once())
- ->method('getMetadata')
- ->willReturn($metadata);
- $this->ruleResource->expects($this->once())
- ->method('getCustomerGroupIds')
- ->willReturn($customers);
- $this->ruleResource->expects($this->once())
- ->method('getWebsiteIds')
- ->willReturn($websites);
- $result = $this->model->execute(RuleInterface::class, $entityData);
- $expected = [
- 'row_id' => 2,
- 'rule_id' => 1,
- 'customer_group_ids' => [1, 2],
- 'website_ids' => [3, 4, 5],
- ];
- $this->assertEquals($expected, $result);
- }
- }
|