Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / console / Tests / Helper / QuestionHelperTest.php
index cf12acdb665b45972c23b436cd38ffbd1ac56c15..76fe45ba2416087368880ea447c37591d22805b1 100644 (file)
@@ -12,9 +12,9 @@
 namespace Symfony\Component\Console\Tests\Helper;
 
 use Symfony\Component\Console\Formatter\OutputFormatter;
-use Symfony\Component\Console\Helper\QuestionHelper;
-use Symfony\Component\Console\Helper\HelperSet;
 use Symfony\Component\Console\Helper\FormatterHelper;
+use Symfony\Component\Console\Helper\HelperSet;
+use Symfony\Component\Console\Helper\QuestionHelper;
 use Symfony\Component\Console\Output\StreamOutput;
 use Symfony\Component\Console\Question\ChoiceQuestion;
 use Symfony\Component\Console\Question\ConfirmationQuestion;
@@ -89,6 +89,63 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
         $this->assertEquals('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, true), $this->createOutputInterface(), $question));
     }
 
+    public function testAskChoiceNonInteractive()
+    {
+        $questionHelper = new QuestionHelper();
+
+        $helperSet = new HelperSet(array(new FormatterHelper()));
+        $questionHelper->setHelperSet($helperSet);
+        $inputStream = $this->getInputStream("\n1\n  1  \nFabien\n1\nFabien\n1\n0,2\n 0 , 2  \n\n\n");
+
+        $heroes = array('Superman', 'Batman', 'Spiderman');
+
+        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0');
+
+        $this->assertSame('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
+
+        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, 'Batman');
+        $this->assertSame('Batman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
+
+        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
+        $this->assertNull($questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
+
+        $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, '0');
+        $question->setValidator(null);
+        $this->assertSame('Superman', $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
+
+        try {
+            $question = new ChoiceQuestion('What is your favorite superhero?', $heroes, null);
+            $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question);
+        } catch (\InvalidArgumentException $e) {
+            $this->assertSame('Value "" is invalid', $e->getMessage());
+        }
+
+        $question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, 1');
+        $question->setMultiselect(true);
+        $this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
+
+        $question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, 1');
+        $question->setMultiselect(true);
+        $question->setValidator(null);
+        $this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
+
+        $question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '0, Batman');
+        $question->setMultiselect(true);
+        $this->assertSame(array('Superman', 'Batman'), $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
+
+        $question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, null);
+        $question->setMultiselect(true);
+        $this->assertNull($questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question));
+
+        try {
+            $question = new ChoiceQuestion('Who are your favorite superheros?', $heroes, '');
+            $question->setMultiselect(true);
+            $questionHelper->ask($this->createStreamableInputInterfaceMock($inputStream, false), $this->createOutputInterface(), $question);
+        } catch (\InvalidArgumentException $e) {
+            $this->assertSame('Value "" is invalid', $e->getMessage());
+        }
+    }
+
     public function testAsk()
     {
         $dialog = new QuestionHelper();
@@ -221,7 +278,7 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
 
     public function testAskHiddenResponse()
     {
-        if ('\\' === DIRECTORY_SEPARATOR) {
+        if ('\\' === \DIRECTORY_SEPARATOR) {
             $this->markTestSkipped('This test is not supported on Windows');
         }
 
@@ -276,7 +333,7 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
 
         $error = 'This is not a color!';
         $validator = function ($color) use ($error) {
-            if (!in_array($color, array('white', 'black'))) {
+            if (!\in_array($color, array('white', 'black'))) {
                 throw new \InvalidArgumentException($error);
             }
 
@@ -637,7 +694,7 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
      */
     public function testLegacyAskHiddenResponse()
     {
-        if ('\\' === DIRECTORY_SEPARATOR) {
+        if ('\\' === \DIRECTORY_SEPARATOR) {
             $this->markTestSkipped('This test is not supported on Windows');
         }
 
@@ -688,7 +745,7 @@ class QuestionHelperTest extends AbstractQuestionHelperTest
 
         $error = 'This is not a color!';
         $validator = function ($color) use ($error) {
-            if (!in_array($color, array('white', 'black'))) {
+            if (!\in_array($color, array('white', 'black'))) {
                 throw new \InvalidArgumentException($error);
             }