aboutsummaryrefslogtreecommitdiffstats
path: root/tests/help/manager_test.php
diff options
context:
space:
mode:
authorJoas Schilling <nickvergessen@gmx.de>2015-05-17 21:45:18 +0200
committerJoas Schilling <nickvergessen@gmx.de>2015-05-17 21:45:18 +0200
commit6dcc14bc5824b3ff74a3cd3acd574ae5e530d1c3 (patch)
treeab4fcd30685ea59cc35c6d9273ea22529118153e /tests/help/manager_test.php
parent8ce0a64a16aa9d1b8edcef684c528cf44bc39cc6 (diff)
downloadforums-6dcc14bc5824b3ff74a3cd3acd574ae5e530d1c3.tar
forums-6dcc14bc5824b3ff74a3cd3acd574ae5e530d1c3.tar.gz
forums-6dcc14bc5824b3ff74a3cd3acd574ae5e530d1c3.tar.bz2
forums-6dcc14bc5824b3ff74a3cd3acd574ae5e530d1c3.tar.xz
forums-6dcc14bc5824b3ff74a3cd3acd574ae5e530d1c3.zip
[ticket/13844] Add unit tests for the help manager
PHPBB3-13844
Diffstat (limited to 'tests/help/manager_test.php')
-rw-r--r--tests/help/manager_test.php183
1 files changed, 183 insertions, 0 deletions
diff --git a/tests/help/manager_test.php b/tests/help/manager_test.php
new file mode 100644
index 0000000000..aaf63194fa
--- /dev/null
+++ b/tests/help/manager_test.php
@@ -0,0 +1,183 @@
+<?php
+/**
+ *
+ * This file is part of the phpBB Forum Software package.
+ *
+ * @copyright (c) phpBB Limited <https://www.phpbb.com>
+ * @license GNU General Public License, version 2 (GPL-2.0)
+ *
+ * For full copyright and license information, please see
+ * the docs/CREDITS.txt file.
+ *
+ */
+
+class phpbb_language_test extends phpbb_test_case
+{
+ /** @var \phpbb\help\manager */
+ protected $manager;
+ /** @var \phpbb\template\template */
+ protected $template;
+ /** @var \phpbb\language\language */
+ protected $language;
+
+ public function setUp()
+ {
+ $this->template = $this->getMockBuilder('\phpbb\template\template')
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->language = $this->getMockBuilder('\phpbb\language\language')
+ ->disableOriginalConstructor()
+ ->getMock();
+
+ $this->manager = new \phpbb\help\manager(
+ $this->template,
+ $this->language
+ );
+ }
+
+ public function add_block_data()
+ {
+ return array(
+ array('abc', false, array(), false),
+ array('def', true, array(), true),
+ array(
+ 'abc',
+ false,
+ array(
+ 'question1' => 'answer1',
+ 'question2' => 'answer2',
+ 'question3' => 'answer3',
+ ),
+ false
+ ),
+ );
+ }
+
+ /**
+ * @dataProvider add_block_data
+ *
+ * @param string $block_name
+ * @param bool $switch
+ * @param array $questions
+ * @param bool $switch_expected
+ */
+ public function test_add_block($block_name, $switch, $questions, $switch_expected)
+ {
+ $this->language->expects($this->at(0))
+ ->method('lang')
+ ->with($block_name)
+ ->willReturn(strtoupper($block_name));
+ $lang_call_count = 1;
+ foreach ($questions as $question => $answer)
+ {
+ $this->language->expects($this->at($lang_call_count))
+ ->method('lang')
+ ->with($question)
+ ->willReturn(strtoupper($question));
+ $lang_call_count++;
+
+ $this->language->expects($this->at($lang_call_count))
+ ->method('lang')
+ ->with($answer)
+ ->willReturn(strtoupper($answer));
+ $lang_call_count++;
+ }
+
+ $this->template->expects($this->at(0))
+ ->method('assign_block_vars')
+ ->with('faq_block', array(
+ 'BLOCK_TITLE' => strtoupper($block_name),
+ 'SWITCH_COLUMN' => $switch_expected,
+ ));
+ $template_call_count = 1;
+ foreach ($questions as $question => $answer)
+ {
+ $this->template->expects($this->at($template_call_count))
+ ->method('assign_block_vars')
+ ->with('faq_block.faq_row', array(
+ 'FAQ_QUESTION' => strtoupper($question),
+ 'FAQ_ANSWER' => strtoupper($answer),
+ ));
+ $template_call_count++;
+ }
+
+ $this->manager->add_block($block_name, $switch, $questions);
+
+ $this->assertEquals($switch_expected, $this->manager->switched_column());
+ }
+
+ public function add_question_data()
+ {
+ return array(
+ array('abc', false, false),
+ array('def', true, true),
+ );
+ }
+
+ /**
+ * @dataProvider add_question_data
+ *
+ * @param string $question
+ * @param string $answer
+ */
+ public function test_add_question($question, $answer)
+ {
+ $this->language->expects($this->at(0))
+ ->method('lang')
+ ->with($question)
+ ->willReturn(strtoupper($question));
+ $this->language->expects($this->at(1))
+ ->method('lang')
+ ->with($answer)
+ ->willReturn(strtoupper($answer));
+
+ $this->template->expects($this->once())
+ ->method('assign_block_vars')
+ ->with('faq_block.faq_row', array(
+ 'FAQ_QUESTION' => strtoupper($question),
+ 'FAQ_ANSWER' => strtoupper($answer),
+ ));
+
+ $this->manager->add_question($question, $answer);
+ }
+
+ public function test_add_block_double_switch()
+ {
+ $block_name = 'abc';
+ $switch_expected = true;
+
+ $this->language->expects($this->at(0))
+ ->method('lang')
+ ->with($block_name)
+ ->willReturn(strtoupper($block_name));
+
+ $this->template->expects($this->at(0))
+ ->method('assign_block_vars')
+ ->with('faq_block', array(
+ 'BLOCK_TITLE' => strtoupper($block_name),
+ 'SWITCH_COLUMN' => $switch_expected,
+ ));
+
+ $this->manager->add_block($block_name, true);
+ $this->assertTrue($this->manager->switched_column());
+
+ // Add a second block with switch
+ $block_name = 'def';
+ $switch_expected = false;
+
+ $this->language->expects($this->at(0))
+ ->method('lang')
+ ->with($block_name)
+ ->willReturn(strtoupper($block_name));
+
+ $this->template->expects($this->at(0))
+ ->method('assign_block_vars')
+ ->with('faq_block', array(
+ 'BLOCK_TITLE' => strtoupper($block_name),
+ 'SWITCH_COLUMN' => $switch_expected,
+ ));
+
+ $this->manager->add_block($block_name, true);
+ $this->assertTrue($this->manager->switched_column());
+ }
+}