aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorMarc Alexander <admin@m-a-styles.de>2017-12-31 11:53:15 +0100
committerMarc Alexander <admin@m-a-styles.de>2018-01-01 18:56:20 +0100
commita999718b42742c9911a24a74cf60f80e196d5cf8 (patch)
treef87c2792a77176d00d29f12c8787d7c3bf5ea55a /tests
parentede339c1c8b19fa01a61594d231902013ef473b0 (diff)
downloadforums-a999718b42742c9911a24a74cf60f80e196d5cf8.tar
forums-a999718b42742c9911a24a74cf60f80e196d5cf8.tar.gz
forums-a999718b42742c9911a24a74cf60f80e196d5cf8.tar.bz2
forums-a999718b42742c9911a24a74cf60f80e196d5cf8.tar.xz
forums-a999718b42742c9911a24a74cf60f80e196d5cf8.zip
[ticket/15055] Support console questions on windows
PHPBB3-15055
Diffstat (limited to 'tests')
-rw-r--r--tests/console/user/add_test.php48
-rw-r--r--tests/console/user/base.php5
-rw-r--r--tests/dbal/db_tools_test.php4
-rw-r--r--tests/tree/nestedset_forum_base.php10
4 files changed, 52 insertions, 15 deletions
diff --git a/tests/console/user/add_test.php b/tests/console/user/add_test.php
index 8641bf87b6..d1a1f8542e 100644
--- a/tests/console/user/add_test.php
+++ b/tests/console/user/add_test.php
@@ -14,12 +14,15 @@
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Tester\CommandTester;
use phpbb\console\command\user\add;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Question\Question;
require_once dirname(__FILE__) . '/base.php';
class phpbb_console_user_add_test extends phpbb_console_user_base
{
- public function get_command_tester()
+ public function get_command_tester($question_answers = [])
{
$application = new Application();
$application->add(new add(
@@ -34,7 +37,42 @@ class phpbb_console_user_add_test extends phpbb_console_user_base
$command = $application->find('user:add');
$this->command_name = $command->getName();
- $this->question = $command->getHelper('question');
+
+ if (!empty($question_answers))
+ {
+ $ask = function(InputInterface $input, OutputInterface $output, Question $question) use ($question_answers)
+ {
+ $text = $question->getQuestion();
+
+ // handle a question
+ foreach ($question_answers as $expected_question => $answer)
+ {
+ if (strpos($text, $expected_question) !== false)
+ {
+ $response = $answer;
+ }
+ }
+
+ if (!isset($response))
+ {
+ throw new \RuntimeException('Was asked for input on an unhandled question: ' . $text);
+ }
+
+ $output->writeln(print_r($response, true));
+ return $response;
+ };
+ $helper = $this->createMock('\Symfony\Component\Console\Helper\QuestionHelper');
+ $helper->expects($this->any())
+ ->method('ask')
+ ->will($this->returnCallback($ask));
+ $this->question = $helper;
+ $command->getHelperSet()->set($helper, 'question');
+ }
+ else
+ {
+ $this->question = $command->getHelper('question');
+ }
+
return new CommandTester($command);
}
@@ -57,7 +95,11 @@ class phpbb_console_user_add_test extends phpbb_console_user_base
public function test_add_dialog()
{
- $command_tester = $this->get_command_tester();
+ $command_tester = $this->get_command_tester([
+ 'USERNAME' => 'bar',
+ 'PASSWORD' => 'password',
+ 'EMAIL_ADDRESS' => 'bar@test.com',
+ ]);
$this->assertEquals(2, $this->get_user_id('Admin'));
diff --git a/tests/console/user/base.php b/tests/console/user/base.php
index 6e5436fb9d..b84c0bb267 100644
--- a/tests/console/user/base.php
+++ b/tests/console/user/base.php
@@ -34,11 +34,6 @@ abstract class phpbb_console_user_base extends phpbb_database_test_case
{
global $auth, $db, $cache, $config, $user, $phpbb_dispatcher, $phpbb_container, $phpbb_root_path, $phpEx;
- if (strtolower(substr(PHP_OS, 0, 5)) !== 'linux')
- {
- $this->markTestSkipped('Unable to test console feature on OS other than Linux.');
- }
-
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$phpbb_container = new phpbb_mock_container_builder();
$phpbb_container->set('cache.driver', new phpbb_mock_cache());
diff --git a/tests/dbal/db_tools_test.php b/tests/dbal/db_tools_test.php
index dbe2c2909a..72a3718662 100644
--- a/tests/dbal/db_tools_test.php
+++ b/tests/dbal/db_tools_test.php
@@ -462,10 +462,6 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
// Index name has > 30 chars - that should not be possible.
$too_long_index_name = str_repeat('i', 31);
$this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $too_long_index_name));
- if (strpos($this->tools->sql_layer, 'mssql') === false)
- {
- $this->setExpectedTriggerError(E_USER_ERROR);
- }
$this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp'));
}
}
diff --git a/tests/tree/nestedset_forum_base.php b/tests/tree/nestedset_forum_base.php
index 62f3e0bcab..498c6a69a2 100644
--- a/tests/tree/nestedset_forum_base.php
+++ b/tests/tree/nestedset_forum_base.php
@@ -69,7 +69,7 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case
static $forums;
if (empty($forums))
- {
+ {
$this->create_forum('Parent with two flat children');
$this->create_forum('Flat child #1', 1);
$this->create_forum('Flat child #2', 1);
@@ -86,7 +86,7 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case
// Updating forum_parents column here so it's not empty
// This is required, so we can see whether the methods
- // correctly clear the values.
+ // correctly clear the values.
$sql = "UPDATE phpbb_forums
SET forum_parents = 'a:0:{}'";
$this->db->sql_query($sql);
@@ -100,6 +100,8 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case
}
else
{
+ // Turn on identity insert on mssql to be able to insert into
+ // identity columns (e.g. forum_id)
if (strpos($this->db->sql_layer, 'mssql') !== false)
{
$sql = 'SET IDENTITY_INSERT phpbb_forums ON';
@@ -112,12 +114,14 @@ class phpbb_tests_tree_nestedset_forum_base extends phpbb_database_test_case
$this->database_synchronisation(array(
'phpbb_forums' => array('forum_id'),
));
+
+ // Disable identity insert on mssql again
if (strpos($this->db->sql_layer, 'mssql') !== false)
{
$sql = 'SET IDENTITY_INSERT phpbb_forums OFF';
$this->db->sql_query($sql);
}
- }
+ }
}
protected function create_forum($name, $parent_id = 0)