@@ -46,7 +46,10 @@ class DepersonalizePluginTest extends TestCase
4646 protected function setUp (): void
4747 {
4848 $ 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+ );
5053 $ this ->depersonalizeCheckerMock = $ this ->createMock (DepersonalizeChecker::class);
5154
5255 $ this ->plugin = (new ObjectManagerHelper ($ this ))->getObject (
@@ -70,6 +73,10 @@ public function testAfterGenerateElements(): void
7073 ->expects ($ this ->once ())
7174 ->method ('clearStorage ' )
7275 ->willReturnSelf ();
76+ $ this ->checkoutSessionMock
77+ ->expects ($ this ->once ())
78+ ->method ('setQuoteId ' )
79+ ->willReturn (1 );
7380
7481 $ this ->assertEmpty ($ this ->plugin ->afterGenerateElements ($ this ->layoutMock ));
7582 }
@@ -86,7 +93,43 @@ public function testAfterGenerateElementsNoDepersonalize(): void
8693 ->expects ($ this ->never ())
8794 ->method ('clearStorage ' )
8895 ->willReturnSelf ();
96+ $ this ->checkoutSessionMock
97+ ->expects ($ this ->never ())
98+ ->method ('setQuoteId ' )
99+ ->willReturn (1 );
89100
90101 $ this ->assertEmpty ($ this ->plugin ->afterGenerateElements ($ this ->layoutMock ));
91102 }
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+ }
92135}
0 commit comments