コード例 #1
0
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportOrderPlaced()
 {
     $testCustomerId = 1;
     $testTotal = '1.00';
     $testBaseTotal = '1.00';
     $testItemCount = null;
     $testTotalQtyOrderedCount = 1;
     $testUpdated = '1970-01-01 00:00:00';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->dateTime->expects($this->once())->method('formatDate')->willReturn($testUpdated);
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getOrder'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->once())->method('getEvent')->willReturn($event);
     $order = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getOrder')->willReturn($order);
     $order->expects($this->once())->method('getCustomerId')->willReturn($testCustomerId);
     $order->expects($this->once())->method('getGrandTotal')->willReturn($testTotal);
     $order->expects($this->once())->method('getBaseGrandTotal')->willReturn($testBaseTotal);
     $order->expects($this->once())->method('getTotalItemCount')->willReturn($testItemCount);
     $order->expects($this->once())->method('getTotalQtyOrdered')->willReturn($testTotalQtyOrderedCount);
     $this->ordersModel->expects($this->once())->method('setData')->with(['customer_id' => $testCustomerId, 'total' => $testTotal, 'total_base' => $testBaseTotal, 'item_count' => $testTotalQtyOrderedCount, 'updated_at' => $testUpdated])->willReturnSelf();
     $this->ordersModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
コード例 #2
0
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportProductDeletedToNewRelic()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->newRelicWrapper->expects($this->once())->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
コード例 #3
0
ファイル: CronTest.php プロジェクト: pradeep-wagento/magento2
 /**
  * Test case when cron is enabled in config
  *
  * @return \Magento\NewRelicReporting\Model\Cron
  */
 public function testRunCronCronEnabledFromConfig()
 {
     $this->configMock->expects($this->once())->method('isCronEnabled')->willReturn(true);
     $this->reportModulesInfoMock->expects($this->once())->method('report')->willReturnSelf();
     $this->reportCountsMock->expects($this->once())->method('report')->willReturnSelf();
     $this->reportNewRelicCronMock->expects($this->once())->method('report')->willReturnSelf();
     $this->assertSame($this->model, $this->model->runCron());
 }
コード例 #4
0
 /**
  * Test case when module is enabled
  *
  * @return void
  */
 public function testReportReportModulesInfo()
 {
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->collectMock->expects($this->once())->method('getModuleData')->willReturn(['installed' => '1', 'uninstalled' => '1', 'enabled' => '1', 'disabled' => '1', 'changes' => [['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled']]]);
     $this->systemModelMock->expects($this->any())->method('setData')->willReturnSelf();
     $this->systemModelMock->expects($this->any())->method('save')->willReturnSelf();
     $this->assertSame($this->model, $this->model->report());
 }
コード例 #5
0
 /**
  * Test case when module is enabled in config and php extension is installed
  *
  * @return void
  */
 public function testCheckConfig()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->newRelicWrapper->expects($this->once())->method('isExtensionInstalled')->willReturn(false);
     $this->config->expects($this->once())->method('disableModule');
     $this->messageManager->expects($this->once())->method('addError');
     $this->model->execute($eventObserver);
 }
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentAdminsToNewRelic()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->backendAuthSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
     $this->newRelicWrapper->expects($this->exactly(3))->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportSystemCacheFlushToNewRelic()
 {
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
     $userMock->expects($this->once())->method('getId')->willReturn('2');
     $this->deploymentsFactory->expects($this->once())->method('create')->willReturn($this->deploymentsModel);
     $this->deploymentsModel->expects($this->once())->method('setDeployment')->willReturnSelf();
     $this->model->execute($eventObserver);
 }
コード例 #8
0
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportSystemCacheFlush()
 {
     $testType = 'systemCacheFlush';
     $testAction = 'JSON string';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->systemModel->expects($this->once())->method('setData')->with(['type' => $testType, 'action' => $testAction])->willReturnSelf();
     $this->systemModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
コード例 #9
0
 /**
  * Test case when module is enabled in config and product updating
  *
  * @dataProvider actionDataProvider
  * @return void
  */
 public function testReportProductUpdatedToNewRelic($isNewObject)
 {
     /** @var Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getProduct'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->once())->method('getEvent')->willReturn($event);
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $product->expects($this->any())->method('isObjectNew')->willReturn($isNewObject);
     $event->expects($this->once())->method('getProduct')->willReturn($product);
     $this->newRelicWrapper->expects($this->once())->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
コード例 #10
0
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportProductDeleted()
 {
     $testType = 'adminProductChange';
     $testAction = 'JSON string';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getProduct'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->once())->method('getEvent')->willReturn($event);
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getId'])->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getProduct')->willReturn($product);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->systemModel->expects($this->once())->method('setData')->with(['type' => $testType, 'action' => $testAction])->willReturnSelf();
     $this->systemModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
コード例 #11
0
 /**
  * Tests client request with exception
  *
  * @return void
  */
 public function testSendRequestException()
 {
     $accId = '';
     $this->zendClientFactoryMock->expects($this->once())->method('create')->willReturn($this->zendClientMock);
     $this->configMock->expects($this->once())->method('getNewRelicAccountId')->willReturn($accId);
     $this->setExpectedException('Magento\\Framework\\Exception\\LocalizedException');
     $this->model->sendRequest();
 }
コード例 #12
0
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportOrderPlacedToNewRelic()
 {
     $testTotal = '1.00';
     $testItemCount = null;
     $testTotalQtyOrderedCount = 1;
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getOrder'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->once())->method('getEvent')->willReturn($event);
     $order = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
     $event->expects($this->once())->method('getOrder')->willReturn($order);
     $order->expects($this->once())->method('getBaseGrandTotal')->willReturn($testTotal);
     $order->expects($this->once())->method('getTotalItemCount')->willReturn($testItemCount);
     $order->expects($this->once())->method('getTotalQtyOrdered')->willReturn($testTotalQtyOrderedCount);
     $this->newRelicWrapper->expects($this->exactly(3))->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
コード例 #13
0
 /**
  * Test case when module is enabled
  *
  * @return void
  */
 public function testReportCountsTest()
 {
     $this->configMock->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->productManagementMock->expects($this->exactly(2))->method('getCount')->willReturn(2);
     $this->configurableManagementMock->expects($this->once())->method('getCount')->willReturn(2);
     $this->categoryManagementMock->expects($this->once())->method('getCount')->willReturn(2);
     $this->countsModelMock->expects($this->any())->method('getCount')->willReturn(1);
     $this->countsModelMock->expects($this->any())->method('setEntityId')->willReturnSelf();
     $this->countsModelMock->expects($this->any())->method('setType')->willReturnSelf();
     $this->countsModelMock->expects($this->any())->method('setCount')->willReturnSelf();
     $this->countsModelMock->expects($this->any())->method('setUpdatedAt')->willReturnSelf();
     $this->countsModelMock->expects($this->any())->method('save')->willReturnSelf();
     $this->assertSame($this->model, $this->model->report());
 }
コード例 #14
0
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentAdmins()
 {
     $testAction = 'JSON string';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->backendAuthSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $userMock = $this->getMockBuilder('Magento\\User\\Model\\User')->disableOriginalConstructor()->getMock();
     $this->backendAuthSession->expects($this->once())->method('getUser')->willReturn($userMock);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->usersModel->expects($this->once())->method('setData')->with(['type' => 'admin_activity', 'action' => $testAction])->willReturnSelf();
     $this->usersModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
コード例 #15
0
 /**
  * Tests client request will fail
  */
 public function testSetDeploymentRequestFail()
 {
     $data = $this->getDataVariables();
     $this->zendClientMock->expects($this->once())->method('setUri')->with($data['uri'])->willReturnSelf();
     $this->zendClientMock->expects($this->once())->method('setMethod')->with($data['method'])->willReturnSelf();
     $this->zendClientMock->expects($this->once())->method('setHeaders')->with($data['headers'])->willReturnSelf();
     $this->zendClientMock->expects($this->once())->method('setParameterPost')->with($data['params'])->willReturnSelf();
     $this->configMock->expects($this->once())->method('getNewRelicApiUrl')->willReturn($data['uri']);
     $this->configMock->expects($this->once())->method('getNewRelicApiKey')->willReturn($data['api_key']);
     $this->configMock->expects($this->once())->method('getNewRelicAppName')->willReturn($data['app_name']);
     $this->configMock->expects($this->once())->method('getNewRelicAppId')->willReturn($data['app_id']);
     $this->zendClientMock->expects($this->once())->method('request')->willThrowException(new \Zend_Http_Client_Exception());
     $this->loggerMock->expects($this->once())->method('critical');
     $this->zendClientFactoryMock->expects($this->once())->method('create')->willReturn($this->zendClientMock);
     $this->assertInternalType('bool', $this->model->setDeployment($data['description'], $data['change'], $data['user']));
 }
コード例 #16
0
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentUsersToNewRelic()
 {
     $testCustomerId = 1;
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->customerSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($testCustomerId);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $this->customerRepository->expects($this->once())->method('getById')->willReturn($customerMock);
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
     $websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getWebsite')->willReturn($websiteMock);
     $this->newRelicWrapper->expects($this->exactly(4))->method('addCustomParameter')->willReturn(true);
     $this->model->execute($eventObserver);
 }
コード例 #17
0
 /**
  * Test case when module is enabled and request is failed
  *
  * @return void
  */
 public function testReportNewRelicCronRequestFailed()
 {
     $testModuleData = ['changes' => [['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'enabled'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'disabled'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'installed'], ['name' => 'name', 'setup_version' => '2.0.0', 'type' => 'uninstalled']], 'enabled' => 1, 'disabled' => 1, 'installed' => 1];
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->collect->expects($this->once())->method('getModuleData')->willReturn($testModuleData);
     $this->counter->expects($this->once())->method('getAllProductsCount');
     $this->counter->expects($this->once())->method('getConfigurableCount');
     $this->counter->expects($this->once())->method('getActiveCatalogSize');
     $this->counter->expects($this->once())->method('getCategoryCount');
     $this->counter->expects($this->once())->method('getWebsiteCount');
     $this->counter->expects($this->once())->method('getStoreViewsCount');
     $this->counter->expects($this->once())->method('getCustomerCount');
     $this->cronEventModel->expects($this->once())->method('addData')->willReturnSelf();
     $this->cronEventModel->expects($this->once())->method('sendRequest');
     $this->cronEventModel->expects($this->once())->method('sendRequest')->willThrowException(new \Exception());
     $this->logger->expects($this->once())->method('critical');
     $this->deploymentsModel->expects($this->any())->method('setDeployment');
     $this->assertSame($this->model, $this->model->report());
 }
コード例 #18
0
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentUsers()
 {
     $testCustomerId = 1;
     $testAction = 'JSON string';
     /** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
     $eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
     $this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
     $this->customerSession->expects($this->once())->method('isLoggedIn')->willReturn(true);
     $this->customerSession->expects($this->once())->method('getCustomerId')->willReturn($testCustomerId);
     $customerMock = $this->getMockBuilder('Magento\\Customer\\Api\\Data\\CustomerInterface')->getMock();
     $this->customerRepository->expects($this->once())->method('getById')->willReturn($customerMock);
     $storeMock = $this->getMockBuilder('Magento\\Store\\Model\\Store')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($storeMock);
     $websiteMock = $this->getMockBuilder('Magento\\Store\\Model\\Website')->disableOriginalConstructor()->getMock();
     $this->storeManager->expects($this->once())->method('getWebsite')->willReturn($websiteMock);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->usersModel->expects($this->once())->method('setData')->with(['type' => 'user_action', 'action' => $testAction])->willReturnSelf();
     $this->usersModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }