@@ -330,4 +330,95 @@ public function testGetValueForApi($input, $expected) {
330330 $ output = $ instance ->getValueForApi ();
331331 $ this ->string ($ output )->isEqualTo ($ expected );
332332 }
333+
334+ public function providerParseAnswerValues () {
335+ return [
336+ [
337+ 'question ' => $ this ->getQuestion (),
338+ 'value ' => '' ,
339+ 'expected ' => true ,
340+ 'expectedValue ' => '' ,
341+ ],
342+ [
343+ 'question ' => $ this ->getQuestion (),
344+ 'value ' => 'foo ' ,
345+ 'expected ' => true ,
346+ 'expectedValue ' => 'foo ' ,
347+ ],
348+ [
349+ 'question ' => $ this ->getQuestion (),
350+ 'value ' => 'foo \\bar ' ,
351+ 'expected ' => true ,
352+ 'expectedValue ' => 'foo \\bar ' ,
353+ ],
354+ [
355+ 'question ' => $ this ->getQuestion (),
356+ 'value ' => 'foo \\\\bar ' ,
357+ 'expected ' => true ,
358+ 'expectedValue ' => 'foo \\bar ' ,
359+ ],
360+ ];
361+ }
362+
363+ /**
364+ * @dataProvider providerParseAnswerValues
365+ */
366+ public function testParseAnswerValues ($ question , $ value , $ expected , $ expectedValue ) {
367+ $ instance = $ this ->newTestedInstance ($ question );
368+ $ output = $ instance ->parseAnswerValues ([
369+ 'formcreator_field_ ' . $ question ->getID () => $ value
370+ ]);
371+ $ this ->boolean ($ output )->isEqualTo ($ expected );
372+ }
373+
374+ public function providerGetValueForTargetText () {
375+ return [
376+ [
377+ 'question ' => $ this ->getQuestion (),
378+ 'value ' => '' ,
379+ 'expected ' => true ,
380+ 'expectedValue ' => '' ,
381+ ],
382+ [
383+ 'question ' => $ this ->getQuestion (),
384+ 'value ' => 'foo ' ,
385+ 'expected ' => true ,
386+ 'expectedValue ' => 'foo ' ,
387+ ],
388+ [
389+ 'question ' => $ this ->getQuestion (),
390+ 'value ' => 'foo \\bar ' ,
391+ 'expected ' => true ,
392+ 'expectedValue ' => 'foo \\bar ' ,
393+ ],
394+ [
395+ 'question ' => $ this ->getQuestion (),
396+ 'value ' => 'foo \\\\bar ' ,
397+ 'expected ' => true ,
398+ 'expectedValue ' => 'foo \\bar ' ,
399+ ],
400+ ];
401+ }
402+
403+ /**
404+ * @dataProvider providerGetValueForTargetText
405+ *
406+ * @return void
407+ */
408+ public function testGetValueForTargetText ($ question , $ value , $ expected , $ expectedValue ) {
409+ $ instance = $ this ->newTestedInstance ($ question );
410+ $ output = $ instance ->parseAnswerValues ([
411+ 'formcreator_field_ ' . $ question ->getID () => $ value
412+ ]);
413+
414+ $ output = $ instance ->getValueForTargetText ('' , false );
415+ if ($ expected === false ) {
416+ $ this ->variable ($ output )->isNull ();
417+ } else {
418+ $ this ->string ($ output )
419+ ->isEqualTo ($ expectedValue );
420+ }
421+ }
422+
423+
333424}
0 commit comments