123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\NewRelicReporting\Test\Unit\Model\Module;
- use Magento\NewRelicReporting\Model\Module\Collect;
- use Magento\Framework\Module\FullModuleList;
- use Magento\Framework\Module\ModuleListInterface;
- use Magento\Framework\Module\Manager;
- use Magento\NewRelicReporting\Model\Module;
- /**
- * Class CollectTest
- */
- class CollectTest extends \PHPUnit\Framework\TestCase
- {
- /**
- * @var \Magento\NewRelicReporting\Model\Module\Collect
- */
- protected $model;
- /**
- * @var ModuleListInterface|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $moduleListMock;
- /**
- * @var Manager|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $moduleManagerMock;
- /**
- * @var fullModuleList|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $fullModuleListMock;
- /**
- * @var \Magento\NewRelicReporting\Model\ModuleFactory|\PHPUnit_Framework_MockObject_MockObject
- */
- protected $moduleFactoryMock;
- /**
- * @var \Magento\NewRelicReporting\Model\ResourceModel\Module\CollectionFactory
- * |\PHPUnit_Framework_MockObject_MockObject
- */
- protected $moduleCollectionFactoryMock;
- protected function setUp()
- {
- $this->moduleListMock = $this->getMockBuilder(\Magento\Framework\Module\ModuleListInterface::class)
- ->setMethods(['getNames', 'has', 'getAll', 'getOne'])
- ->disableOriginalConstructor()
- ->getMock();
- $this->fullModuleListMock = $this->getMockBuilder(\Magento\Framework\Module\FullModuleList::class)
- ->setMethods(['getNames', 'getAll'])
- ->disableOriginalConstructor()
- ->getMock();
- $this->moduleManagerMock = $this->getMockBuilder(\Magento\Framework\Module\Manager::class)
- ->setMethods(['isOutputEnabled'])
- ->disableOriginalConstructor()
- ->getMock();
- $this->moduleFactoryMock = $this->createPartialMock(
- \Magento\NewRelicReporting\Model\ModuleFactory::class,
- ['create']
- );
- $this->moduleCollectionFactoryMock = $this->createPartialMock(
- \Magento\NewRelicReporting\Model\ResourceModel\Module\CollectionFactory::class,
- ['create']
- );
- $this->model = new Collect(
- $this->moduleListMock,
- $this->fullModuleListMock,
- $this->moduleManagerMock,
- $this->moduleFactoryMock,
- $this->moduleCollectionFactoryMock
- );
- }
- /**
- * Tests modules data returns array
- *
- * @return void
- */
- public function testGetModuleDataWithoutRefresh()
- {
- $moduleCollectionMock = $this->getMockBuilder(
- \Magento\NewRelicReporting\Model\ResourceModel\Module\Collection::class
- )
- ->disableOriginalConstructor()
- ->getMock();
- $itemMock = $this->createMock(\Magento\NewRelicReporting\Model\Module::class);
- $modulesMockArray = [
- 'Module_Name' => [
- 'name' => 'Name',
- 'setup_version' => '2.0.0',
- 'sequence' => []
- ]
- ];
- $testChangesMockArray = [
- ['entity' => '3',
- 'name' => 'Name',
- 'active' => 'true',
- 'state' => 'enabled',
- 'setup_version' => '2.0.0',
- 'updated_at' => '2015-09-02 18:38:17'],
- ['entity' => '4',
- 'name' => 'Name',
- 'active' => 'true',
- 'state' => 'disabled',
- 'setup_version' => '2.0.0',
- 'updated_at' => '2015-09-02 18:38:17'],
- ['entity' => '5',
- 'name' => 'Name',
- 'active' => 'true',
- 'state' => 'uninstalled',
- 'setup_version' => '2.0.0',
- 'updated_at' => '2015-09-02 18:38:17']
- ];
- $itemMockArray = [$itemMock];
- $enabledModulesMockArray = [];
- $this->moduleCollectionFactoryMock->expects($this->any())
- ->method('create')
- ->willReturn($moduleCollectionMock);
- $this->moduleFactoryMock->expects($this->any())
- ->method('create')
- ->willReturn($itemMock);
- $itemMock->expects($this->any())
- ->method('setData')
- ->willReturnSelf();
- $itemMock->expects($this->any())
- ->method('save')
- ->willReturnSelf();
- $moduleCollectionMock->expects($this->any())
- ->method('getItems')
- ->willReturn($itemMockArray);
- $moduleCollectionMock->expects($this->any())
- ->method('getData')
- ->willReturn($testChangesMockArray);
- $this->fullModuleListMock->expects($this->once())
- ->method('getAll')
- ->willReturn($modulesMockArray);
- $this->fullModuleListMock->expects($this->once())
- ->method('getNames')
- ->willReturn($enabledModulesMockArray);
- $this->moduleListMock->expects($this->once())
- ->method('getNames')
- ->willReturn($enabledModulesMockArray);
- $this->moduleManagerMock->expects($this->any())->method('isOutputEnabled')->will(
- $this->returnValue(false)
- );
- $this->assertInternalType(
- 'array',
- $this->model->getModuleData()
- );
- }
- /**
- * Tests modules data returns array and saving in DB
- *
- * @dataProvider itemDataProvider
- * @return void
- */
- public function testGetModuleDataRefresh($data)
- {
- $moduleCollectionMock = $this->getMockBuilder(
- \Magento\NewRelicReporting\Model\ResourceModel\Module\Collection::class
- )
- ->disableOriginalConstructor()
- ->getMock();
- /** @var \Magento\NewRelicReporting\Model\Module|\PHPUnit_Framework_MockObject_MockObject $itemMock */
- $itemMock = $this->createPartialMock(
- \Magento\NewRelicReporting\Model\Module::class,
- ['getName', 'getData', 'setData', 'getState', 'save']
- );
- $modulesMockArray = [
- 'Module_Name1' => [
- 'name' => 'Module_Name1',
- 'setup_version' => '2.0.0',
- 'sequence' => []
- ]
- ];
- $itemMock->setData($data);
- $testChangesMockArray = [
- 'entity_id' => '3',
- 'name' => 'Name',
- 'active' => 'true',
- 'state' => 'uninstalled',
- 'setup_version' => '2.0.0',
- 'some_param' => 'some_value',
- 'updated_at' => '2015-09-02 18:38:17'
- ];
- $itemMockArray = [$itemMock];
- $enabledModulesMockArray = ['Module_Name2'];
- $allModulesMockArray = ['Module_Name1','Module_Name2'];
- $this->moduleCollectionFactoryMock->expects($this->any())
- ->method('create')
- ->willReturn($moduleCollectionMock);
- $this->moduleFactoryMock->expects($this->any())
- ->method('create')
- ->willReturn($itemMock);
- $itemMock->expects($this->any())
- ->method('setData')
- ->willReturnSelf();
- $itemMock->expects($this->any())
- ->method('save')
- ->willReturnSelf();
- $itemMock->expects($this->any())
- ->method('getState')
- ->willReturn($data['state']);
- $itemMock->expects($this->any())
- ->method('getName')
- ->willReturn($data['name']);
- $moduleCollectionMock->expects($this->any())
- ->method('getItems')
- ->willReturn($itemMockArray);
- $itemMock->expects($this->any())
- ->method('getData')
- ->willReturn($testChangesMockArray);
- $this->fullModuleListMock->expects($this->once())
- ->method('getAll')
- ->willReturn($modulesMockArray);
- $this->fullModuleListMock->expects($this->any())
- ->method('getNames')
- ->willReturn($allModulesMockArray);
- $this->moduleListMock->expects($this->any())
- ->method('getNames')
- ->willReturn($enabledModulesMockArray);
- $this->moduleManagerMock->expects($this->any())->method('isOutputEnabled')->will(
- $this->returnValue(true)
- );
- $this->assertInternalType(
- 'array',
- $this->model->getModuleData()
- );
- }
- /**
- * Tests modules data returns array and saving in DB
- *
- * @dataProvider itemDataProvider
- * @return void
- */
- public function testGetModuleDataRefreshOrStatement($data)
- {
- $moduleCollectionMock = $this->getMockBuilder(
- \Magento\NewRelicReporting\Model\ResourceModel\Module\Collection::class
- )
- ->disableOriginalConstructor()
- ->getMock();
- /** @var \Magento\NewRelicReporting\Model\Module|\PHPUnit_Framework_MockObject_MockObject $itemMock */
- $itemMock = $this->createPartialMock(
- \Magento\NewRelicReporting\Model\Module::class,
- ['getName', 'getData', 'setData', 'getState', 'save']
- );
- $modulesMockArray = [
- 'Module_Name1' => [
- 'name' => 'Module_Name1',
- 'setup_version' => '2.0.0',
- 'sequence' => []
- ]
- ];
- $itemMock->setData($data);
- $testChangesMockArray = [
- 'entity_id' => '3',
- 'name' => 'Name',
- 'active' => 'false',
- 'state' => 'enabled',
- 'setup_version' => '2.0.0',
- 'some_param' => 'some_value',
- 'updated_at' => '2015-09-02 18:38:17'
- ];
- $itemMockArray = [$itemMock];
- $enabledModulesMockArray = ['Module_Name2'];
- $allModulesMockArray = ['Module_Name1','Module_Name2'];
- $this->moduleCollectionFactoryMock->expects($this->any())
- ->method('create')
- ->willReturn($moduleCollectionMock);
- $this->moduleFactoryMock->expects($this->any())
- ->method('create')
- ->willReturn($itemMock);
- $itemMock->expects($this->any())
- ->method('setData')
- ->willReturnSelf();
- $itemMock->expects($this->any())
- ->method('save')
- ->willReturnSelf();
- $itemMock->expects($this->any())
- ->method('getState')
- ->willReturn($data['state']);
- $itemMock->expects($this->any())
- ->method('getName')
- ->willReturn($data['name']);
- $moduleCollectionMock->expects($this->any())
- ->method('getItems')
- ->willReturn($itemMockArray);
- $itemMock->expects($this->any())
- ->method('getData')
- ->willReturn($testChangesMockArray);
- $this->fullModuleListMock->expects($this->once())
- ->method('getAll')
- ->willReturn($modulesMockArray);
- $this->fullModuleListMock->expects($this->any())
- ->method('getNames')
- ->willReturn($allModulesMockArray);
- $this->moduleListMock->expects($this->any())
- ->method('getNames')
- ->willReturn($enabledModulesMockArray);
- $this->moduleManagerMock->expects($this->any())->method('isOutputEnabled')->will(
- $this->returnValue(true)
- );
- $this->assertInternalType(
- 'array',
- $this->model->getModuleData()
- );
- }
- /**
- * @return array
- */
- public function itemDataProvider()
- {
- return [
- [
- [
- 'entity_id' => '1',
- 'name' => 'Module_Name1',
- 'active' => 'true',
- 'state' => 'enabled',
- 'setup_version' => '2.0.0'
- ]
- ],
- [
- [
- 'entity_id' => '2',
- 'name' => 'Module_Name2',
- 'active' => 'true',
- 'state' => 'disabled',
- 'setup_version' => '2.0.0'
- ]
- ],
- [
- [
- 'entity_id' => '2',
- 'name' => 'Module_Name2',
- 'active' => 'true',
- 'state' => 'uninstalled',
- 'setup_version' => '2.0.0'
- ]
- ]
- ];
- }
- }
|