44 $this->registry = $this->createMock(\
Magento\Framework\Registry::class);
45 $this->session = $this->getMockBuilder(\
Magento\
Customer\Model\Session::class)
46 ->disableOriginalConstructor()
47 ->setMethods([
'getSessionId',
'getVisitorData',
'setVisitorData'])
50 $this->objectManagerHelper =
new ObjectManagerHelper($this);
62 ])->disableOriginalConstructor()->getMock();
63 $this->resource->expects($this->any())->method(
'getIdFieldName')->willReturn(
'visitor_id');
64 $this->resource->expects($this->any())->method(
'addCommitCallback')->willReturnSelf();
66 $arguments = $this->objectManagerHelper->getConstructArguments(
69 'registry' => $this->registry,
70 'session' => $this->session,
71 'resource' => $this->resource,
80 $oldSessionId =
'asdfhasdfjhkj2198sadf8sdf897';
81 $newSessionId =
'bsdfhasdfjhkj2198sadf8sdf897';
82 $this->session->expects($this->any())->method(
'getSessionId')->willReturn($newSessionId);
83 $this->session->expects($this->atLeastOnce())->method(
'getVisitorData')
84 ->willReturn([
'session_id' => $oldSessionId]);
85 $this->visitor->initByRequest(
null);
86 $this->assertEquals($newSessionId, $this->visitor->getSessionId());
91 $this->session->expects($this->once())->method(
'setVisitorData')->will($this->returnSelf());
92 $this->assertSame($this->visitor, $this->visitor->saveByRequest(
null));
97 $this->visitor = $this->objectManagerHelper->getObject(
100 'registry' => $this->registry,
101 'session' => $this->session,
102 'resource' => $this->resource,
103 'ignores' => [
'test_route_name' =>
true],
106 $request = new \Magento\Framework\DataObject([
'route_name' =>
'test_route_name']);
107 $action = new \Magento\Framework\DataObject([
'request' =>
$request]);
108 $event = new \Magento\Framework\DataObject([
'controller_action' => $action]);
109 $observer = new \Magento\Framework\DataObject([
'event' => $event]);
110 $this->assertTrue($this->visitor->isModuleIgnored(
$observer));
115 $customer = new \Magento\Framework\DataObject([
'id' =>
'1']);
116 $observer = new \Magento\Framework\DataObject([
120 $this->visitor->bindCustomerLogin(
$observer);
121 $this->assertTrue($this->visitor->getDoCustomerLogin());
122 $this->assertEquals(
$customer->getId(), $this->visitor->getCustomerId());
124 $this->visitor->unsetData();
125 $this->visitor->setCustomerId(
'2');
126 $this->visitor->bindCustomerLogin(
$observer);
127 $this->assertNull($this->visitor->getDoCustomerLogin());
128 $this->assertEquals(
'2', $this->visitor->getCustomerId());
133 $observer = new \Magento\Framework\DataObject();
135 $this->visitor->setCustomerId(
'1');
136 $this->visitor->bindCustomerLogout(
$observer);
137 $this->assertTrue($this->visitor->getDoCustomerLogout());
139 $this->visitor->unsetData();
140 $this->visitor->bindCustomerLogout(
$observer);
141 $this->assertNull($this->visitor->getDoCustomerLogout());
146 $quote = new \Magento\Framework\DataObject([
'id' =>
'1',
'is_checkout_cart' =>
true]);
147 $observer = new \Magento\Framework\DataObject([
150 $this->visitor->bindQuoteCreate(
$observer);
151 $this->assertTrue($this->visitor->getDoQuoteCreate());
156 $quote = new \Magento\Framework\DataObject([
'id' =>
'1']);
157 $observer = new \Magento\Framework\DataObject([
160 $this->visitor->bindQuoteDestroy(
$observer);
161 $this->assertTrue($this->visitor->getDoQuoteDestroy());
166 $this->resource->expects($this->once())->method(
'clean')->with($this->visitor)->willReturnSelf();
167 $this->visitor->clean();