@@ -46,7 +46,10 @@ class DepersonalizePluginTest extends TestCase
46
46
protected function setUp (): void
47
47
{
48
48
$ this ->layoutMock = $ this ->getMockForAbstractClass (LayoutInterface::class);
49
- $ this ->checkoutSessionMock = $ this ->createPartialMock (CheckoutSession::class, ['clearStorage ' ]);
49
+ $ this ->checkoutSessionMock = $ this ->createPartialMock (
50
+ CheckoutSession::class,
51
+ ['clearStorage ' , 'setQuoteId ' , 'getQuoteId ' ]
52
+ );
50
53
$ this ->depersonalizeCheckerMock = $ this ->createMock (DepersonalizeChecker::class);
51
54
52
55
$ this ->plugin = (new ObjectManagerHelper ($ this ))->getObject (
@@ -70,6 +73,10 @@ public function testAfterGenerateElements(): void
70
73
->expects ($ this ->once ())
71
74
->method ('clearStorage ' )
72
75
->willReturnSelf ();
76
+ $ this ->checkoutSessionMock
77
+ ->expects ($ this ->once ())
78
+ ->method ('setQuoteId ' )
79
+ ->willReturn (1 );
73
80
74
81
$ this ->assertEmpty ($ this ->plugin ->afterGenerateElements ($ this ->layoutMock ));
75
82
}
@@ -86,7 +93,43 @@ public function testAfterGenerateElementsNoDepersonalize(): void
86
93
->expects ($ this ->never ())
87
94
->method ('clearStorage ' )
88
95
->willReturnSelf ();
96
+ $ this ->checkoutSessionMock
97
+ ->expects ($ this ->never ())
98
+ ->method ('setQuoteId ' )
99
+ ->willReturn (1 );
89
100
90
101
$ this ->assertEmpty ($ this ->plugin ->afterGenerateElements ($ this ->layoutMock ));
91
102
}
103
+
104
+ /**
105
+ * Test beforeGenerateElements method when depersonalization is needed.
106
+ *
107
+ * @return void
108
+ */
109
+ public function testBeforeGenerateXml (): void
110
+ {
111
+ $ this ->depersonalizeCheckerMock ->expects ($ this ->once ())->method ('checkIfDepersonalize ' )->willReturn (true );
112
+ $ this ->checkoutSessionMock
113
+ ->expects ($ this ->once ())
114
+ ->method ('getQuoteId ' )
115
+ ->willReturn (1 );
116
+
117
+ $ this ->assertEmpty ($ this ->plugin ->beforeGenerateXml ($ this ->layoutMock ));
118
+ }
119
+
120
+ /**
121
+ * Test beforeGenerateElements method when depersonalization is not needed.
122
+ *
123
+ * @return void
124
+ */
125
+ public function testBeforeGenerateXmlNoDepersonalize (): void
126
+ {
127
+ $ this ->depersonalizeCheckerMock ->expects ($ this ->once ())->method ('checkIfDepersonalize ' )->willReturn (false );
128
+ $ this ->checkoutSessionMock
129
+ ->expects ($ this ->never ())
130
+ ->method ('getQuoteId ' )
131
+ ->willReturn (1 );
132
+
133
+ $ this ->assertEmpty ($ this ->plugin ->beforeGenerateXml ($ this ->layoutMock ));
134
+ }
92
135
}
0 commit comments