@@ -140,6 +140,54 @@ public function testConfirmWithOddLengthConfirmAndEvenLengthButton() : void
140140 static ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
141141 }
142142
143+ public function testConfirmCancellableWithShortPrompt (): void
144+ {
145+ $ this ->terminal
146+ ->method ('read ' )
147+ ->will ($ this ->onConsecutiveCalls (
148+ "\n" ,
149+ "\n"
150+ ));
151+
152+ $ style = $ this ->getStyle ($ this ->terminal );
153+
154+ $ item = new SelectableItem ('Item 1 ' , function (CliMenu $ menu ) {
155+ $ menu ->cancellableConfirm ('PHP ' , null , true )
156+ ->display ('OK ' , 'Cancel ' );
157+
158+ $ menu ->close ();
159+ });
160+
161+ $ menu = new CliMenu ('PHP School FTW ' , [$ item ], $ this ->terminal , $ style );
162+ $ menu ->open ();
163+
164+ static ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
165+ }
166+
167+ public function testConfirmCancellableWithLongPrompt (): void
168+ {
169+ $ this ->terminal
170+ ->method ('read ' )
171+ ->will ($ this ->onConsecutiveCalls (
172+ "\n" ,
173+ "\n"
174+ ));
175+
176+ $ style = $ this ->getStyle ($ this ->terminal );
177+
178+ $ item = new SelectableItem ('Item 1 ' , function (CliMenu $ menu ) {
179+ $ menu ->cancellableConfirm ('PHP School Rocks FTW! ' , null , true )
180+ ->display ('OK ' , 'Cancel ' );
181+
182+ $ menu ->close ();
183+ });
184+
185+ $ menu = new CliMenu ('PHP School FTW ' , [$ item ], $ this ->terminal , $ style );
186+ $ menu ->open ();
187+
188+ static ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
189+ }
190+
143191 public function testConfirmCanOnlyBeClosedWithEnter () : void
144192 {
145193 $ this ->terminal
@@ -166,6 +214,79 @@ public function testConfirmCanOnlyBeClosedWithEnter() : void
166214 static ::assertStringEqualsFile ($ this ->getTestFile (), $ this ->output ->fetch ());
167215 }
168216
217+ public function testConfirmOkNonCancellableReturnsTrue ()
218+ {
219+ $ this ->terminal
220+ ->method ('read ' )
221+ ->will ($ this ->onConsecutiveCalls (
222+ "\n" ,
223+ 'tab ' ,
224+ "\n"
225+ ));
226+
227+ $ style = $ this ->getStyle ($ this ->terminal );
228+
229+ $ return = '' ;
230+
231+ $ item = new SelectableItem ('Item 1 ' , function (CliMenu $ menu ) use (&$ return ) {
232+ $ return = $ menu ->cancellableConfirm ('PHP School FTW! ' )
233+ ->display ('OK ' );
234+
235+ $ menu ->close ();
236+ });
237+
238+ $ menu = new CliMenu ('PHP School FTW ' , [$ item ], $ this ->terminal , $ style );
239+ $ menu ->open ();
240+
241+ static ::assertTrue ($ return );
242+ }
243+
244+ public function testConfirmOkCancellableReturnsTrue ()
245+ {
246+ $ this ->terminal
247+ ->method ('read ' )
248+ ->willReturn ("\n" , "\t" , "\t" , "\n" );
249+
250+ $ style = $ this ->getStyle ($ this ->terminal );
251+
252+ $ return = '' ;
253+
254+ $ item = new SelectableItem ('Item 1 ' , function (CliMenu $ menu ) use (&$ return ) {
255+ $ return = $ menu ->cancellableConfirm ('PHP School FTW! ' )
256+ ->display ('OK ' , 'Cancel ' );
257+
258+ $ menu ->close ();
259+ });
260+
261+ $ menu = new CliMenu ('PHP School FTW ' , [$ item ], $ this ->terminal , $ style );
262+ $ menu ->open ();
263+
264+ static ::assertTrue ($ return );
265+ }
266+
267+ public function testConfirmCancelCancellableReturnsFalse ()
268+ {
269+ $ this ->terminal
270+ ->method ('read ' )
271+ ->willReturn ("\n" , "\t" , "\n" );
272+
273+ $ style = $ this ->getStyle ($ this ->terminal );
274+
275+ $ return = '' ;
276+
277+ $ item = new SelectableItem ('Item 1 ' , function (CliMenu $ menu ) use (&$ return ) {
278+ $ return = $ menu ->cancellableConfirm ('PHP School FTW! ' , null )
279+ ->display ('OK ' , 'Cancel ' );
280+
281+ $ menu ->close ();
282+ });
283+
284+ $ menu = new CliMenu ('PHP School FTW ' , [$ item ], $ this ->terminal , $ style );
285+ $ menu ->open ();
286+
287+ static ::assertFalse ($ return );
288+ }
289+
169290 private function getTestFile () : string
170291 {
171292 return sprintf ('%s/../res/%s.txt ' , __DIR__ , $ this ->getName ());
0 commit comments