64 $this->config = $this->getMockBuilder(\
Magento\NewRelicReporting\Model\Config::class)
65 ->disableOriginalConstructor()
66 ->setMethods([
'isNewRelicEnabled'])
68 $this->customerSession = $this->getMockBuilder(\
Magento\Customer\Model\Session::class)
69 ->disableOriginalConstructor()
70 ->setMethods([
'isLoggedIn',
'getCustomerId'])
72 $this->customerRepository = $this->getMockBuilder(\
Magento\Customer\Api\CustomerRepositoryInterface::class)
74 $this->storeManager = $this->getMockBuilder(\
Magento\Store\Model\StoreManagerInterface::class)
76 $this->usersFactory = $this->getMockBuilder(\
Magento\NewRelicReporting\Model\UsersFactory::class)
77 ->disableOriginalConstructor()
78 ->setMethods([
'create'])
80 $this->usersModel = $this->getMockBuilder(\
Magento\NewRelicReporting\Model\Users::class)
81 ->disableOriginalConstructor()
83 $this->jsonEncoder = $this->getMockBuilder(\
Magento\Framework\Json\EncoderInterface::class)
86 $this->usersFactory->expects($this->any())
88 ->willReturn($this->usersModel);
92 $this->customerSession,
93 $this->customerRepository,
105 public function testReportConcurrentUsersModuleDisabledFromConfig()
108 $eventObserver = $this->getMockBuilder(\
Magento\Framework\Event\Observer::class)
109 ->disableOriginalConstructor()
112 $this->config->expects($this->once())
113 ->method(
'isNewRelicEnabled')
116 $this->model->execute($eventObserver);
124 public function testReportConcurrentUsersUserIsNotLoggedIn()
127 $eventObserver = $this->getMockBuilder(\
Magento\Framework\Event\Observer::class)
128 ->disableOriginalConstructor()
131 $this->config->expects($this->once())
132 ->method(
'isNewRelicEnabled')
134 $this->customerSession->expects($this->once())
135 ->method(
'isLoggedIn')
138 $this->model->execute($eventObserver);
146 public function testReportConcurrentUsers()
149 $testAction =
'JSON string';
152 $eventObserver = $this->getMockBuilder(\
Magento\Framework\Event\Observer::class)
153 ->disableOriginalConstructor()
156 $this->config->expects($this->once())
157 ->method(
'isNewRelicEnabled')
159 $this->customerSession->expects($this->once())
160 ->method(
'isLoggedIn')
162 $this->customerSession->expects($this->once())
163 ->method(
'getCustomerId')
164 ->willReturn($testCustomerId);
165 $customerMock = $this->getMockBuilder(\
Magento\Customer\Api\Data\CustomerInterface::class)->getMock();
166 $this->customerRepository->expects($this->once())
168 ->willReturn($customerMock);
169 $storeMock = $this->getMockBuilder(\
Magento\Store\Model\Store::class)->disableOriginalConstructor()->getMock();
170 $this->storeManager->expects($this->once())
172 ->willReturn($storeMock);
173 $websiteMock = $this->getMockBuilder(
174 \
Magento\Store\Model\Website::class
175 )->disableOriginalConstructor()->getMock();
176 $this->storeManager->expects($this->once())
177 ->method(
'getWebsite')
178 ->willReturn($websiteMock);
179 $this->jsonEncoder->expects($this->once())
181 ->willReturn($testAction);
182 $this->usersModel->expects($this->once())
184 ->with([
'type' =>
'user_action',
'action' => $testAction])
186 $this->usersModel->expects($this->once())
189 $this->model->execute($eventObserver);