Exemple #1
0
 public function testBeforeSave()
 {
     $this->pageMock->expects($this->any())->method('getData')->willReturnMap([['identifier', null, 'test'], ['custom_theme_from', null, null], ['custom_theme_to', null, '10/02/2016']]);
     $this->dateTimeMock->expects($this->once())->method('formatDate')->with('10/02/2016')->willReturn('10 Feb 2016');
     $this->pageMock->expects($this->any())->method('setData')->withConsecutive(['custom_theme_from', null], ['custom_theme_to', '10 Feb 2016']);
     $this->model->beforeSave($this->pageMock);
 }
 /**
  * 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);
 }
Exemple #3
0
 public function testBeforeSave()
 {
     $timeStamp = '0000';
     $this->dateTimeMock->expects($this->exactly(2))->method('formatDate')->will($this->returnValue($timeStamp));
     $this->integrationModel->beforeSave();
     $this->assertEquals($timeStamp, $this->integrationModel->getCreatedAt());
     $this->assertEquals($timeStamp, $this->integrationModel->getUpdatedAt());
 }
Exemple #4
0
 public function testGetDiscountCollection()
 {
     $ruleCollection = $this->getMock('Magento\\SalesRule\\Model\\Resource\\Rule\\Collection', ['addWebsiteGroupDateFilter', 'addFieldToFilter', 'setOrder', 'load'], [], '', false);
     $this->dateTime->expects($this->once())->method('now');
     $this->collectionFactory->expects($this->once())->method('create')->will($this->returnValue($ruleCollection));
     $ruleCollection->expects($this->once())->method('addWebsiteGroupDateFilter')->will($this->returnSelf());
     $ruleCollection->expects($this->once())->method('addFieldToFilter')->will($this->returnSelf());
     $ruleCollection->expects($this->once())->method('setOrder')->will($this->returnSelf());
     $ruleCollection->expects($this->once())->method('load')->will($this->returnSelf());
     $this->assertEquals($ruleCollection, $this->discounts->getDiscountCollection(1, 1));
 }
Exemple #5
0
 public function testGetValueDefaultModeSaving()
 {
     $this->appState->expects($this->once())->method('getMode')->will($this->returnValue(\Magento\Framework\App\State::MODE_DEFAULT));
     $storageException = new \UnexpectedValueException('Does not exist in the storage');
     $this->versionStorage->expects($this->once())->method('load')->will($this->throwException($storageException));
     $this->dateTime->expects($this->once())->method('toTimestamp')->will($this->returnValue('123'));
     $this->versionStorage->expects($this->once())->method('save')->with('123');
     $this->assertEquals('123', $this->object->getValue());
     $this->object->getValue();
     // Ensure caching in memory
 }
 /**
  * Setup
  *
  * @return void
  */
 public function setUp()
 {
     $this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
     $this->collect = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Module\\Collect')->disableOriginalConstructor()->setMethods(['getModuleData'])->getMock();
     $this->systemFactory = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\SystemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
     $this->systemModel = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\System')->disableOriginalConstructor()->getMock();
     $this->jsonEncoder = $this->getMockBuilder('Magento\\Framework\\Json\\EncoderInterface')->getMock();
     $this->dateTime = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->disableOriginalConstructor()->setMethods(['formatDate'])->getMock();
     $this->systemFactory->expects($this->any())->method('create')->willReturn($this->systemModel);
     $this->jsonEncoder->expects($this->any())->method('encode')->willReturn('json_string');
     $this->dateTime->expects($this->any())->method('formatDate')->willReturn('1970-01-01 00:00:00');
     $this->model = new ReportModulesInfo($this->config, $this->collect, $this->systemFactory, $this->jsonEncoder, $this->dateTime);
 }
 protected function setUp()
 {
     $this->objectManager = new ObjectManagerHelper($this);
     $this->backendConfigMock = $this->getMockBuilder(ConfigInterface::class)->disableOriginalConstructor()->setMethods(['getValue'])->getMockForAbstractClass();
     $this->customerRegistryMock = $this->getMock(CustomerRegistry::class, ['retrieveSecureData', 'retrieve'], [], '', false);
     $this->customerRepositoryMock = $this->getMockBuilder(CustomerRepositoryInterface::class)->disableOriginalConstructor()->getMock();
     $this->encryptorMock = $this->getMockBuilder(\Magento\Framework\Encryption\EncryptorInterface::class)->disableOriginalConstructor()->getMock();
     $this->dateTimeMock = $this->getMockBuilder(DateTime::class)->disableOriginalConstructor()->getMock();
     $this->dateTimeMock->expects($this->any())->method('formatDate')->willReturn('formattedDate');
     $this->customerSecureMock = $this->getMock(CustomerSecure::class, ['getId', 'getPasswordHash', 'isCustomerLocked', 'getFailuresNum', 'getFirstFailure', 'getLockExpires', 'setFirstFailure', 'setFailuresNum', 'setLockExpires'], [], '', false);
     $this->customerAuthUpdate = $this->getMockBuilder(\Magento\Customer\Model\CustomerAuthUpdate::class)->disableOriginalConstructor()->getMock();
     $this->authentication = $this->objectManager->getObject(Authentication::class, ['customerRegistry' => $this->customerRegistryMock, 'backendConfig' => $this->backendConfigMock, 'customerRepository' => $this->customerRepositoryMock, 'encryptor' => $this->encryptorMock, 'dateTime' => $this->dateTimeMock]);
     $this->objectManager->setBackwardCompatibleProperty($this->authentication, 'customerAuthUpdate', $this->customerAuthUpdate);
 }
 /**
  * Test case when module is enabled in config
  *
  * @return void
  */
 public function testReportSystemCacheFlush()
 {
     $testType = 'systemCacheFlush';
     $testAction = 'JSON string';
     $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);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->systemModel->expects($this->once())->method('setData')->with(['type' => $testType, 'action' => $testAction, 'updated_at' => $testUpdated])->willReturnSelf();
     $this->systemModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
 /**
  * @test
  * @return void
  * @covers \Magento\Theme\Model\Design::loadChange
  * @covers \Magento\Theme\Model\Design::__construct
  * @covers \Magento\Theme\Model\Design::_construct
  */
 public function testLoadChangeFromCache()
 {
     $storeId = 1;
     $localDate = '2\\28\\2000';
     $date = '28-02-2000';
     $cacheId = 'design_change_' . md5($storeId . $date);
     $this->localeDate->expects($this->once())->method('scopeTimeStamp')->with($storeId)->willReturn($localDate);
     $this->dateTime->expects($this->once())->method('formatDate')->with($localDate, false)->willReturn($date);
     $this->cacheManager->expects($this->once())->method('load')->with($cacheId)->willReturn(serialize(['test' => 'data']));
     $this->assertInstanceOf(get_class($this->model), $this->model->loadChange($storeId));
 }
Exemple #10
0
 public function testIsScopeDateInInterval()
 {
     $scope = $this->getMock('Magento\\Framework\\App\\ScopeInterface', ['getCode', 'getId']);
     $this->scopeResolver->expects($this->any())->method('getScope')->will($this->returnValue($scope));
     $this->dateTime->expects($this->at(0))->method('isEmptyDate')->will($this->returnValue(false));
     $this->dateTime->expects($this->at(1))->method('isEmptyDate')->will($this->returnValue(false));
     $this->dateTime->expects($this->at(2))->method('isEmptyDate')->will($this->returnValue(true));
     $this->dateTime->expects($this->at(3))->method('isEmptyDate')->will($this->returnValue(true));
     $this->assertFalse($this->timezone->isScopeDateInInterval('store'));
     $this->assertTrue($this->timezone->isScopeDateInInterval('store', null, '10 September 2036'));
 }
 public function testGetData()
 {
     $this->dateTime->expects($this->once())->method('formatDate')->will($this->returnValue(date('Y-m-d H:i:s')));
     $this->rssUrlBuilderInterface->expects($this->once())->method('getUrl')->with(['_secure' => true, '_nosecret' => true, 'type' => 'new_order'])->will($this->returnValue('http://magento.com/backend/rss/feed/index/type/new_order'));
     $this->timezoneInterface->expects($this->once())->method('formatDate')->will($this->returnValue('2014-09-10 17:39:50'));
     $order = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->setMethods(['__sleep', '__wakeup', 'getResourceCollection', 'getIncrementId', 'getId', 'getCreatedAt'])->disableOriginalConstructor()->getMock();
     $order->expects($this->once())->method('getId')->will($this->returnValue(1));
     $order->expects($this->once())->method('getIncrementId')->will($this->returnValue('100000001'));
     $order->expects($this->once())->method('getCreatedAt')->will($this->returnValue(time()));
     $collection = $this->getMockBuilder('\\Magento\\Sales\\Model\\ResourceModel\\Order\\Collection')->setMethods(['addAttributeToFilter', 'addAttributeToSort', 'getIterator'])->disableOriginalConstructor()->getMock();
     $collection->expects($this->once())->method('addAttributeToFilter')->will($this->returnSelf());
     $collection->expects($this->once())->method('addAttributeToSort')->will($this->returnSelf());
     $collection->expects($this->once())->method('getIterator')->will($this->returnValue(new \ArrayIterator([$order])));
     $order->expects($this->once())->method('getResourceCollection')->will($this->returnValue($collection));
     $this->orderFactory->expects($this->once())->method('create')->will($this->returnValue($order));
     $this->eventManager->expects($this->once())->method('dispatch')->will($this->returnSelf());
     $block = $this->getMock('Magento\\Sales\\Block\\Adminhtml\\Order\\Details', ['setOrder', 'toHtml'], [], '', false);
     $block->expects($this->once())->method('setOrder')->with($order)->will($this->returnSelf());
     $block->expects($this->once())->method('toHtml')->will($this->returnValue('Order Description'));
     $this->layout->expects($this->once())->method('getBlockSingleton')->will($this->returnValue($block));
     $this->urlBuiler->expects($this->once())->method('getUrl')->will($this->returnValue('http://magento.com/sales/order/view/order_id/1'));
     $this->assertEquals($this->feedData, $this->model->getRssData());
 }
 /**
  * Test case when module is enabled and user is logged in 
  *
  * @return void
  */
 public function testReportConcurrentAdmins()
 {
     $testAction = 'JSON string';
     $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->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->dateTime->expects($this->once())->method('formatDate')->willReturn($testUpdated);
     $this->usersModel->expects($this->once())->method('setData')->with(['type' => 'admin_activity', 'action' => $testAction, 'updated_at' => $testUpdated])->willReturnSelf();
     $this->usersModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
 /**
  * Test case when module is enabled in config and product updated
  *
  * @return void
  */
 public function testReportProductUpdated()
 {
     $testType = 'adminProductChange';
     $testAction = 'JSON string';
     $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);
     $event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getProduct'])->disableOriginalConstructor()->getMock();
     $eventObserver->expects($this->once())->method('getEvent')->willReturn($event);
     /** @var \Magento\Catalog\Model\Product|\PHPUnit_Framework_MockObject_MockObject $product */
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->setMethods(['getId'])->disableOriginalConstructor()->getMock();
     $product->isObjectNew(false);
     $event->expects($this->once())->method('getProduct')->willReturn($product);
     $this->dateTime->expects($this->once())->method('formatDate')->willReturn($testUpdated);
     $this->jsonEncoder->expects($this->once())->method('encode')->willReturn($testAction);
     $this->systemModel->expects($this->once())->method('setData')->with(['type' => $testType, 'action' => $testAction, 'updated_at' => $testUpdated])->willReturnSelf();
     $this->systemModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
 /**
  * Test case when module is enabled and user is logged in
  *
  * @return void
  */
 public function testReportConcurrentUsers()
 {
     $testCustomerId = 1;
     $testAction = 'JSON string';
     $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->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->dateTime->expects($this->once())->method('formatDate')->willReturn($testUpdated);
     $this->usersModel->expects($this->once())->method('setData')->with(['type' => 'user_action', 'action' => $testAction, 'updated_at' => $testUpdated])->willReturnSelf();
     $this->usersModel->expects($this->once())->method('save');
     $this->model->execute($eventObserver);
 }
Exemple #15
0
 public function testGetLastVisitAt()
 {
     $time = time();
     $this->dateTime->expects($this->once())->method('now')->will($this->returnValue($time));
     $this->assertEquals($time, $this->visitor->getLastVisitAt());
 }