123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Reports\Test\Unit\Model\ResourceModel;
- use Magento\Reports\Model\ResourceModel\Event;
- class EventTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\Reports\Model\ResourceModel\Event
- */
- protected $event;
- /**
- * @var \Magento\Framework\Model\ResourceModel\Db\Context|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $contextMock;
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $scopeConfigMock;
- /**
- * @var \Magento\Store\Model\StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $storeManagerMock;
- /**
- * @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $connectionMock;
- /**
- * @var \Magento\Framework\App\ResourceConnection|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $resourceMock;
- /**
- * @var \Magento\Store\Model\Store|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $storeMock;
- /**
- * {@inheritDoc}
- */
- protected function setUp()
- {
- $this->contextMock = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\Context::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->scopeConfigMock = $this->getMockBuilder(\Magento\Framework\App\Config\ScopeConfigInterface::class)
- ->getMock();
- $this->storeManagerMock = $this->getMockBuilder(\Magento\Store\Model\StoreManagerInterface::class)
- ->getMock();
- $this->storeMock = $this->getMockBuilder(\Magento\Store\Model\Store::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->storeManagerMock
- ->expects($this->any())
- ->method('getStore')
- ->willReturn($this->storeMock);
- $this->connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
- ->getMock();
- $this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->resourceMock
- ->expects($this->any())
- ->method('getConnection')
- ->willReturn($this->connectionMock);
- $this->contextMock
- ->expects($this->any())
- ->method('getResources')
- ->willReturn($this->resourceMock);
- $this->event = new Event(
- $this->contextMock,
- $this->scopeConfigMock,
- $this->storeManagerMock
- );
- }
- /**
- * @return void
- */
- public function testUpdateCustomerTypeWithoutType()
- {
- $eventMock = $this->getMockBuilder(\Magento\Reports\Model\Event::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->connectionMock
- ->expects($this->never())
- ->method('update');
- $this->event->updateCustomerType($eventMock, 1, 1);
- }
- /**
- * @return void
- */
- public function testUpdateCustomerTypeWithType()
- {
- $eventMock = $this->getMockBuilder(\Magento\Reports\Model\Event::class)
- ->disableOriginalConstructor()
- ->getMock();
- $this->connectionMock
- ->expects($this->once())
- ->method('update');
- $this->event->updateCustomerType($eventMock, 1, 1, ['type']);
- }
- /**
- * @return void
- */
- public function testApplyLogToCollection()
- {
- $derivedSelect = 'SELECT * FROM table';
- $idFieldName = 'IdFieldName';
- $collectionSelectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
- ->disableOriginalConstructor()
- ->setMethods(['joinInner', 'order'])
- ->getMock();
- $collectionSelectMock
- ->expects($this->once())
- ->method('joinInner')
- ->with(
- ['evt' => new \Zend_Db_Expr("({$derivedSelect})")],
- "{$idFieldName} = evt.object_id",
- []
- )
- ->willReturnSelf();
- $collectionSelectMock
- ->expects($this->once())
- ->method('order')
- ->willReturnSelf();
- $collectionMock = $this->getMockBuilder(\Magento\Framework\Data\Collection\AbstractDb::class)
- ->disableOriginalConstructor()
- ->getMock();
- $collectionMock
- ->expects($this->once())
- ->method('getResource')
- ->willReturnSelf();
- $collectionMock
- ->expects($this->once())
- ->method('getIdFieldName')
- ->willReturn($idFieldName);
- $collectionMock
- ->expects($this->any())
- ->method('getSelect')
- ->willReturn($collectionSelectMock);
- $selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
- ->disableOriginalConstructor()
- ->setMethods(['from', 'where', 'group', 'joinInner', '__toString'])
- ->getMock();
- $selectMock
- ->expects($this->once())
- ->method('from')
- ->willReturnSelf();
- $selectMock
- ->expects($this->any())
- ->method('where')
- ->willReturnSelf();
- $selectMock
- ->expects($this->once())
- ->method('group')
- ->willReturnSelf();
- $selectMock
- ->expects($this->any())
- ->method('__toString')
- ->willReturn($derivedSelect);
- $this->connectionMock
- ->expects($this->once())
- ->method('select')
- ->willReturn($selectMock);
- $this->storeMock
- ->expects($this->any())
- ->method('getId')
- ->willReturn(1);
- $this->event->applyLogToCollection($collectionMock, 1, 1, 1);
- }
- /**
- * @return void
- */
- public function testClean()
- {
- $eventMock = $this->getMockBuilder(\Magento\Reports\Model\Event::class)
- ->disableOriginalConstructor()
- ->getMock();
- $selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
- ->disableOriginalConstructor()
- ->setMethods(['select', 'from', 'joinLeft', 'where', 'limit', 'fetchCol'])
- ->getMock();
- $this->connectionMock
- ->expects($this->at(1))
- ->method('fetchCol')
- ->willReturn(1);
- $this->connectionMock
- ->expects($this->any())
- ->method('delete');
- $this->connectionMock
- ->expects($this->any())
- ->method('select')
- ->willReturn($selectMock);
- $selectMock
- ->expects($this->any())
- ->method('from')
- ->willReturnSelf();
- $selectMock
- ->expects($this->any())
- ->method('joinLeft')
- ->willReturnSelf();
- $selectMock
- ->expects($this->any())
- ->method('where')
- ->willReturnSelf();
- $selectMock
- ->expects($this->any())
- ->method('limit')
- ->willReturnSelf();
- $this->event->clean($eventMock);
- }
- }
|