From 03d2c6413c25b1faf7f37ff20625ce986b19eb88 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 7 Dec 2012 21:57:33 -0500 Subject: [ticket/11248] Convert line endings to LF - develop edition. PHPBB3-11248 --- tests/session/append_sid_test.php | 108 +++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 54 deletions(-) (limited to 'tests') diff --git a/tests/session/append_sid_test.php b/tests/session/append_sid_test.php index 34f6dea8ca..b9e9ac1aa9 100644 --- a/tests/session/append_sid_test.php +++ b/tests/session/append_sid_test.php @@ -1,54 +1,54 @@ - 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument as array'), - - // Custom sid parameter - array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid', 'using session_id'), - - // Testing anchors - array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in url-argument'), - array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument'), - array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument (array)'), - - // Anchors and custom sid - array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), - array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), - array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), - - // Empty parameters should not append the ? - array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'), - array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'), - array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'), - ); - } - - /** - * @dataProvider append_sid_data - */ - public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description) - { - global $phpbb_dispatcher; - - $phpbb_dispatcher = new phpbb_mock_event_dispatcher; - $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); - } -} - + 1, 'f' => 2), true, false, 'viewtopic.php?t=1&f=2', 'parameters in params-argument as array'), + + // Custom sid parameter + array('viewtopic.php', 't=1&f=2', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid', 'using session_id'), + + // Testing anchors + array('viewtopic.php?t=1&f=2#anchor', false, true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in url-argument'), + array('viewtopic.php', 't=1&f=2#anchor', true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, false, 'viewtopic.php?t=1&f=2#anchor', 'anchor in params-argument (array)'), + + // Anchors and custom sid + array('viewtopic.php?t=1&f=2#anchor', false, true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in url-argument using session_id'), + array('viewtopic.php', 't=1&f=2#anchor', true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument using session_id'), + array('viewtopic.php', array('t' => 1, 'f' => 2, '#' => 'anchor'), true, 'custom-sid', 'viewtopic.php?t=1&f=2&sid=custom-sid#anchor', 'anchor in params-argument (array) using session_id'), + + // Empty parameters should not append the ? + array('viewtopic.php', false, true, false, 'viewtopic.php', 'no params using bool false'), + array('viewtopic.php', '', true, false, 'viewtopic.php', 'no params using empty string'), + array('viewtopic.php', array(), true, false, 'viewtopic.php', 'no params using empty array'), + ); + } + + /** + * @dataProvider append_sid_data + */ + public function test_append_sid($url, $params, $is_amp, $session_id, $expected, $description) + { + global $phpbb_dispatcher; + + $phpbb_dispatcher = new phpbb_mock_event_dispatcher; + $this->assertEquals($expected, append_sid($url, $params, $is_amp, $session_id)); + } +} + -- cgit v1.2.1 From 9eb9fa2b9d117b919dfcc1e37d6c1186841b4fe7 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 13 Dec 2012 22:38:17 -0600 Subject: [ticket/8610] Create helper functions to create topic/post in functional tests This will be used to test splitting/copying/merging/etc in functional tests Also convert functional posting_test.php to use these functions PHPBB3-8610 --- tests/functional/posting_test.php | 89 +++--------------- .../test_framework/phpbb_functional_test_case.php | 101 +++++++++++++++++++++ 2 files changed, 112 insertions(+), 78 deletions(-) (limited to 'tests') diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index f54a3591b2..6aa7a46974 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -15,88 +15,21 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case public function test_post_new_topic() { $this->login(); - $this->add_lang('posting'); - $crawler = $this->request('GET', 'posting.php?mode=post&f=2&sid=' . $this->sid); - $this->assertContains($this->lang('POST_TOPIC'), $crawler->filter('html')->text()); + // Test creating topic + $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); - $hidden_fields = array(); - $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); - }); + $crawler = $this->request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); + $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text()); - $test_message = 'This is a test topic posted by the testing framework.'; - $form_data = array( - 'subject' => 'Test Topic 1', - 'message' => $test_message, - 'post' => true, - 'f' => 2, - 'mode' => 'post', - 'sid' => $this->sid, - ); + // Test creating a reply + $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); - foreach ($hidden_fields as $fields) - { - foreach($fields as $field) - { - $form_data[$field['name']] = $field['value']; - } - } + $crawler = $this->request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); + $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); - // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) - // is not at least 2 seconds before submission, cancel the form - $form_data['lastclick'] = 0; - - // I use a request because the form submission method does not allow you to send data that is not - // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) - // Instead, I send it as a request with the submit button "post" set to true. - $crawler = $this->client->request('POST', 'posting.php', $form_data); - $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); - - $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); - $this->assertContains($test_message, $crawler->filter('html')->text()); - } - - public function test_post_reply() - { - $this->login(); - $this->add_lang('posting'); - - $crawler = $this->request('GET', 'posting.php?mode=reply&t=2&f=2&sid=' . $this->sid); - $this->assertContains($this->lang('POST_REPLY'), $crawler->filter('html')->text()); - - $hidden_fields = array(); - $hidden_fields[] = $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); - }); - - $test_message = 'This is a test post posted by the testing framework.'; - $form_data = array( - 'subject' => 'Re: Test Topic 1', - 'message' => $test_message, - 'post' => true, - 't' => 2, - 'f' => 2, - 'mode' => 'reply', - 'sid' => $this->sid, - ); - - foreach ($hidden_fields as $fields) - { - foreach($fields as $field) - { - $form_data[$field['name']] = $field['value']; - } - } - - // For reasoning behind the following command, see the test_post_new_topic() test - $form_data['lastclick'] = 0; - - // Submit the post - $crawler = $this->client->request('POST', 'posting.php', $form_data); - $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); - - $crawler = $this->request('GET', 'viewtopic.php?t=2&sid=' . $this->sid); - $this->assertContains($test_message, $crawler->filter('html')->text()); + // Test quoting a message + $crawler = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); + $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 8ab6469e9a..e6a9023a3b 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -275,6 +275,107 @@ class phpbb_functional_test_case extends phpbb_test_case return user_add($user_row); } + /** + * Creates a topic + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + protected function create_topic($forum_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return $this->submit_post($posting_url, 'POST_TOPIC', $form_data); + } + + /** + * Creates a post + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + protected function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return $this->submit_post($posting_url, 'POST_REPLY', $form_data); + } + + /** + * Helper for submitting posts + * + * @param string $posting_url + * @param string $posting_contains + * @param array $form_data + * @return array post_id, topic_id + */ + protected function submit_post($posting_url, $posting_contains, $form_data) + { + $this->add_lang('posting'); + + $crawler = $this->request('GET', $posting_url); + $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); + + $hidden_fields = array( + $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }), + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form + $form_data['lastclick'] = 0; + + // I use a request because the form submission method does not allow you to send data that is not + // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) + // Instead, I send it as a request with the submit button "post" set to true. + $crawler = $this->client->request('POST', $posting_url, $form_data); + $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + + $url = $crawler->selectLink(str_replace('%s', '', $this->lang['VIEW_MESSAGE']))->link()->getUri(); + + $matches = $topic_id = $post_id = false; + preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); + + $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; + $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; + + return array( + 'topic_id' => $topic_id, + 'post_id' => $post_id, + ); + } + protected function login($username = 'admin') { $this->add_lang('ucp'); -- cgit v1.2.1 From d739745ea4ccc224b6b7fb686339138733c2203d Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 13 Dec 2012 23:09:45 -0600 Subject: [ticket/8610] Move posting helpers to separate file This is to prevent cluttering up the functional test case class more PHPBB3-8610 --- tests/functional/posting_test.php | 8 +- .../test_framework/phpbb_functional_test_case.php | 115 +++----------------- tests/test_framework/posting_helpers.php | 119 +++++++++++++++++++++ 3 files changed, 137 insertions(+), 105 deletions(-) create mode 100644 tests/test_framework/posting_helpers.php (limited to 'tests') diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index 6aa7a46974..dd078286d6 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -15,15 +15,19 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case public function test_post_new_topic() { $this->login(); + + include(__DIR__ . './../test_framework/posting_helpers.php'); + + $posting_helper = new phpbb_test_framework_posting_helpers($this); // Test creating topic - $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); + $post = $posting_helper->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); $crawler = $this->request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text()); // Test creating a reply - $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); + $post2 = $posting_helper->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); $crawler = $this->request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index e6a9023a3b..097db62e29 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -275,107 +275,6 @@ class phpbb_functional_test_case extends phpbb_test_case return user_add($user_row); } - /** - * Creates a topic - * - * Be sure to login before creating - * - * @param int $forum_id - * @param string $subject - * @param string $message - * @param array $additional_form_data Any additional form data to be sent in the request - * @return array post_id, topic_id - */ - protected function create_topic($forum_id, $subject, $message, $additional_form_data = array()) - { - $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; - - $form_data = array_merge(array( - 'subject' => $subject, - 'message' => $message, - 'post' => true, - ), $additional_form_data); - - return $this->submit_post($posting_url, 'POST_TOPIC', $form_data); - } - - /** - * Creates a post - * - * Be sure to login before creating - * - * @param int $forum_id - * @param string $subject - * @param string $message - * @param array $additional_form_data Any additional form data to be sent in the request - * @return array post_id, topic_id - */ - protected function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) - { - $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; - - $form_data = array_merge(array( - 'subject' => $subject, - 'message' => $message, - 'post' => true, - ), $additional_form_data); - - return $this->submit_post($posting_url, 'POST_REPLY', $form_data); - } - - /** - * Helper for submitting posts - * - * @param string $posting_url - * @param string $posting_contains - * @param array $form_data - * @return array post_id, topic_id - */ - protected function submit_post($posting_url, $posting_contains, $form_data) - { - $this->add_lang('posting'); - - $crawler = $this->request('GET', $posting_url); - $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); - - $hidden_fields = array( - $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); - }), - ); - - foreach ($hidden_fields as $fields) - { - foreach($fields as $field) - { - $form_data[$field['name']] = $field['value']; - } - } - - // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) - // is not at least 2 seconds before submission, cancel the form - $form_data['lastclick'] = 0; - - // I use a request because the form submission method does not allow you to send data that is not - // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) - // Instead, I send it as a request with the submit button "post" set to true. - $crawler = $this->client->request('POST', $posting_url, $form_data); - $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); - - $url = $crawler->selectLink(str_replace('%s', '', $this->lang['VIEW_MESSAGE']))->link()->getUri(); - - $matches = $topic_id = $post_id = false; - preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); - - $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; - $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; - - return array( - 'topic_id' => $topic_id, - 'post_id' => $post_id, - ); - } - protected function login($username = 'admin') { $this->add_lang('ucp'); @@ -400,7 +299,7 @@ class phpbb_functional_test_case extends phpbb_test_case } } - protected function add_lang($lang_file) + public function add_lang($lang_file) { if (is_array($lang_file)) { @@ -422,7 +321,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->lang = array_merge($this->lang, $lang); } - protected function lang() + public function lang() { $args = func_get_args(); $key = $args[0]; @@ -451,4 +350,14 @@ class phpbb_functional_test_case extends phpbb_test_case $content = $this->client->getResponse()->getContent(); $this->assertNotContains('Fatal error:', $content); } + + public function get_sid() + { + return $this->sid; + } + + public function get_client() + { + return $this->client; + } } diff --git a/tests/test_framework/posting_helpers.php b/tests/test_framework/posting_helpers.php new file mode 100644 index 0000000000..329cf5a1b4 --- /dev/null +++ b/tests/test_framework/posting_helpers.php @@ -0,0 +1,119 @@ +test_case = $test_case; + } + + /** + * Creates a topic + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->test_case->get_sid()}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return $this->submit_post($posting_url, 'POST_TOPIC', $form_data); + } + + /** + * Creates a post + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->test_case->get_sid()}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return $this->submit_post($posting_url, 'POST_REPLY', $form_data); + } + + /** + * Helper for submitting posts + * + * @param string $posting_url + * @param string $posting_contains + * @param array $form_data + * @return array post_id, topic_id + */ + protected function submit_post($posting_url, $posting_contains, $form_data) + { + $this->test_case->add_lang('posting'); + + $crawler = $this->test_case->request('GET', $posting_url); + $this->test_case->assertContains($this->test_case->lang($posting_contains), $crawler->filter('html')->text()); + + $hidden_fields = array( + $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }), + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form + $form_data['lastclick'] = 0; + + // I use a request because the form submission method does not allow you to send data that is not + // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) + // Instead, I send it as a request with the submit button "post" set to true. + $crawler = $this->test_case->get_client()->request('POST', $posting_url, $form_data); + $this->test_case->assertContains($this->test_case->lang('POST_STORED'), $crawler->filter('html')->text()); + + $url = $crawler->selectLink($this->test_case->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); + + $matches = $topic_id = $post_id = false; + preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); + + $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; + $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; + + return array( + 'topic_id' => $topic_id, + 'post_id' => $post_id, + ); + } +} -- cgit v1.2.1 From 754dc9c1592001ac4f223358fd708bd338f49fb3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 12:56:42 +0100 Subject: [ticket/11250] Add parsing tests for our basic bbcodes in simple cases PHPBB3-11250 --- tests/bbcode/parser_test.php | 148 ++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 140 insertions(+), 8 deletions(-) (limited to 'tests') diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 8c7fbc7128..697bcde610 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -13,17 +13,149 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { - public function test_both_passes() + public function string_bbcode_data() { - $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); - - $parser = new phpbb_bbcode_parser(); + return array( + // Default BBCodes from in their simplest way + array( + 'Test default bbcodes: simple bold', + '[b]bold[/b]', + '[b:]bold[/b:]', + ), + array( + 'Test default bbcodes: simple underlined', + '[u]underlined[/u]', + '[u:]underlined[/u:]', + ), + array( + 'Test default bbcodes: simple italic', + '[i]italic[/i]', + '[i:]italic[/i:]', + ), + array( + 'Test default bbcodes: simple color rgb', + '[color=#FF0000]colored[/color]', + '[color=#FF0000:]colored[/color:]', + ), + array( + 'Test default bbcodes: simple color name', + '[color=red]colored[/color]', + '[color=red:]colored[/color:]', + ), + array( + 'Test default bbcodes: simple quote', + '[quote]quoted[/quote]', + '[quote:]quoted[/quote:]', + ), + array( + 'Test default bbcodes: simple quote with username', + '[quote="username"]quoted[/quote]', + '[quote="username":]quoted[/quote:]', + ), + array( + 'Test default bbcodes: simple code', + '[code]unparsed code[/code]', + '[code:]unparsed code[/code:]', + ), + array( + 'Test default bbcodes: simple php code', + '[code=php]unparsed code[/code]', + '[code=php:]unparsed code[/code:]', + ), + array( + 'Test default bbcodes: simple list', + '[list]no item[/list]', + '[list:]no item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item only', + '[*]unparsed', + '[*]unparsed', + ), + array( + 'Test default bbcodes: simple list-item', + '[list][*]item[/list]', + '[list:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item closed', + '[list][*]item[/*][/list]', + '[list:][*:]item[/*:][/list:]', + ), + array( + 'Test default bbcodes: simple list-item numbered', + '[list=1][*]item[/list]', + '[list=1:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item alpha', + '[list=a][*]item[/list]', + '[list=a:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item roman', + '[list=i][*]item[/list]', + '[list=i:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item disc', + '[list=disc][*]item[/list]', + '[list=disc:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item circle', + '[list=circle][*]item[/list]', + '[list=circle:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple list-item square', + '[list=square][*]item[/list]', + '[list=square:][*:]item[/list:]', + ), + array( + 'Test default bbcodes: simple img', + '[img]https://area51.phpbb.com/images/area51.png[/img]', + '[img:]https://area51.phpbb.com/images/area51.png[/img:]', + ), + array( + 'Test default bbcodes: simple url', + '[url]https://area51.phpbb.com/[/url]', + '[url:]https://area51.phpbb.com/[/url:]', + ), + array( + 'Test default bbcodes: simple url with description', + '[url=https://area51.phpbb.com/]Area51[/url]', + '[url=https://area51.phpbb.com/:]Area51[/url:]', + ), + array( + 'Test default bbcodes: simple email', + '[email]bbcode-test@phpbb.com[/email]', + '[email:]bbcode-test@phpbb.com[/email:]', + ), + array( + 'Test default bbcodes: simple email with description', + '[email=bbcode-test@phpbb.com]Email[/email]', + '[email=bbcode-test@phpbb.com:]Email[/email:]', + ), + ); + } + - $result = $parser->first_pass('[i]Italic [u]underlined text[/u][/i]'); - $result = $parser->second_pass($result); + /** + * @dataProvider string_bbcode_data + */ + public function test_firstpass($description, $message, $expected) + { + $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); - $expected = 'Italic underlined text'; + global $user, $request; + $user = new phpbb_mock_user; + $request = new phpbb_mock_request; - $this->assertEquals($expected, $result, 'Simple nested BBCode first+second pass'); + $bbcode = new bbcode_firstpass(); + $bbcode->message = $message; + $bbcode->bbcode_init(false); + $bbcode->parse_bbcode(); + $this->assertEquals($expected, $bbcode->message); } } -- cgit v1.2.1 From ade9f831aa151de428c4d2b33fce48f9733db336 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 12:58:57 +0100 Subject: [ticket/11250] Move quote special cases from class to unit tests PHPBB3-11250 --- tests/bbcode/parser_test.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 697bcde610..410eeabe92 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -137,6 +137,32 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[email=bbcode-test@phpbb.com]Email[/email]', '[email=bbcode-test@phpbb.com:]Email[/email:]', ), + + array( + 'PHPBB3-1401 - correct: parsed', + '[quote="[test]test"]test [ test[/quote]', + '[quote="[test]test":]test [ test[/quote:]', + ), + array( + 'PHPBB3-6117 - correct: parsed', + '[quote]test[/quote] test ] and [ test [quote]test[/quote]', + '[quote:]test[/quote:] test ] and [ test [quote:]test[/quote:]', + ), + array( + 'PHPBB3-6200 - correct: parsed', + '[quote="["]test[/quote]', + '[quote="[":]test[/quote:]', + ), + array( + 'PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted', + '[quote]test[/[/b]quote] test [/quote][/quote] test', + '[quote:]test[/[/b]quote] test [/quote:][/quote] test', + ), + array( + 'PHPBB3-8096 - first quote tag parsed, second quote tag unparsed', + '[quote="a"]a[/quote][quote="a]a[/quote]', + '[quote="a":]a[/quote:][quote="a]a[/quote]', + ), ); } -- cgit v1.2.1 From deceeb737335b0724c9a15c1f7332ec6deddc3f3 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:00:14 +0100 Subject: [ticket/11250] Add some more tests for quotes PHPBB3-11250 --- tests/bbcode/parser_test.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 410eeabe92..f700177498 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -163,6 +163,32 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[quote="a"]a[/quote][quote="a]a[/quote]', '[quote="a":]a[/quote:][quote="a]a[/quote]', ), + + array( + 'Allow textual BBcodes in usernames', + '[quote="[i]test[/i]"]test[/quote]', + '[quote="[i:]test[/i:]":]test[/quote:]', + ), + array( + 'Allow links BBcodes in usernames', + '[quote="[url=http://www.phpbb.com/]test[/url]"]test[/quote]', + '[quote="[url=http://www.phpbb.com/:]test[/url:]":]test[/quote:]', + ), + array( + 'Disallow img BBcodes in usernames - Username displayed as [img]http://www.phpbb.com/[/img]', + '[quote="[img]http://www.phpbb.com/[/img]"]test[/quote]', + '[quote="[img]http://www.phpbb.com/[/img]":]test[/quote:]', + ), + array( + 'Disallow flash BBcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]', + '[quote="[flash]http://www.phpbb.com/[/flash]"]test[/quote]', + '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', + ), + array( + 'parsed - Username displayed as [quote]test[/quote]', + '[quote="[quote]test[/quote]"]test[/quote]', + '[quote="[quote]test[/quote]":]test[/quote:]', + ), ); } -- cgit v1.2.1 From 90a81a064bd119792a2848c3699d1f1ec0ad1827 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:03:10 +0100 Subject: [ticket/11250] Add some comments and fix a description PHPBB3-11250 --- tests/bbcode/parser_test.php | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'tests') diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index f700177498..ed55a69640 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -2,15 +2,11 @@ /** * * @package testing -* @version $Id$ -* @copyright (c) 2008 phpBB Group +* @copyright (c) 2012 phpBB Group * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 * */ -// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser_base.php'; -// require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode/bbcode_parser.php'; - class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { public function string_bbcode_data() @@ -138,6 +134,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[email=bbcode-test@phpbb.com:]Email[/email:]', ), + // Special cases for quote which were reported as bugs before array( 'PHPBB3-1401 - correct: parsed', '[quote="[test]test"]test [ test[/quote]', @@ -164,6 +161,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[quote="a":]a[/quote:][quote="a]a[/quote]', ), + // Nesting bbcodes into quote usernames array( 'Allow textual BBcodes in usernames', '[quote="[i]test[/i]"]test[/quote]', @@ -185,7 +183,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', ), array( - 'parsed - Username displayed as [quote]test[/quote]', + 'Disallow quote BBcodes in usernames - Username displayed as [quote]test[/quote]', '[quote="[quote]test[/quote]"]test[/quote]', '[quote="[quote]test[/quote]":]test[/quote:]', ), -- cgit v1.2.1 From bf312b529384890e1e45a0b073277156b5ab4c5b Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:04:44 +0100 Subject: [ticket/11250] Fix method names PHPBB3-11250 --- tests/bbcode/parser_test.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index ed55a69640..8f0aeab386 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -9,7 +9,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { - public function string_bbcode_data() + public function bbcode_firstpass_data() { return array( // Default BBCodes from in their simplest way @@ -192,9 +192,9 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase /** - * @dataProvider string_bbcode_data + * @dataProvider bbcode_firstpass_data */ - public function test_firstpass($description, $message, $expected) + public function test_bbcode_firstpass($description, $message, $expected) { $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); -- cgit v1.2.1 From cce821f99d1ad83b029c31baf84328d257cced23 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:09:05 +0100 Subject: [ticket/11250] Add tests for size and attachment PHPBB3-11250 --- tests/bbcode/parser_test.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tests') diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 8f0aeab386..32e23236f6 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -38,6 +38,11 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[color=red]colored[/color]', '[color=red:]colored[/color:]', ), + array( + 'Test default bbcodes: simple size', + '[size=75]smaller[/size]', + '[size=75:]smaller[/size:]', + ), array( 'Test default bbcodes: simple quote', '[quote]quoted[/quote]', @@ -133,6 +138,11 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[email=bbcode-test@phpbb.com]Email[/email]', '[email=bbcode-test@phpbb.com:]Email[/email:]', ), + array( + 'Test default bbcodes: simple attachment', + '[attachment=0]filename[/attachment]', + '[attachment=0:]filename[/attachment:]', + ), // Special cases for quote which were reported as bugs before array( -- cgit v1.2.1 From 1e5da1417ad051a16383c967488d88394b3698ae Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:58:39 +0100 Subject: [ticket/11250] Fix parsing result with special chars : . and [ are replaced by their html representation if they are text only PHPBB3-11250 --- tests/bbcode/parser_test.php | 75 +++++++++++++++++++++++--------------------- 1 file changed, 40 insertions(+), 35 deletions(-) (limited to 'tests') diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 32e23236f6..0e1f405bae 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -7,6 +7,11 @@ * */ +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_content.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/bbcode.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/message_parser.php'; + class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { public function bbcode_firstpass_data() @@ -50,8 +55,8 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase ), array( 'Test default bbcodes: simple quote with username', - '[quote="username"]quoted[/quote]', - '[quote="username":]quoted[/quote:]', + '[quote="username"]quoted[/quote]', + '[quote="username":]quoted[/quote:]', ), array( 'Test default bbcodes: simple code', @@ -61,12 +66,12 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase array( 'Test default bbcodes: simple php code', '[code=php]unparsed code[/code]', - '[code=php:]unparsed code[/code:]', + '[code=php:]unparsed code[/code:]', ), array( 'Test default bbcodes: simple list', '[list]no item[/list]', - '[list:]no item[/list:]', + '[list:]no item[/list:u:]', ), array( 'Test default bbcodes: simple list-item only', @@ -76,79 +81,79 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase array( 'Test default bbcodes: simple list-item', '[list][*]item[/list]', - '[list:][*:]item[/list:]', + '[list:][*:]item[/*:m:][/list:u:]', ), array( 'Test default bbcodes: simple list-item closed', '[list][*]item[/*][/list]', - '[list:][*:]item[/*:][/list:]', + '[list:][*:]item[/*:][/list:u:]', ), array( 'Test default bbcodes: simple list-item numbered', '[list=1][*]item[/list]', - '[list=1:][*:]item[/list:]', + '[list=1:][*:]item[/*:m:][/list:o:]', ), array( 'Test default bbcodes: simple list-item alpha', '[list=a][*]item[/list]', - '[list=a:][*:]item[/list:]', + '[list=a:][*:]item[/*:m:][/list:o:]', ), array( 'Test default bbcodes: simple list-item roman', '[list=i][*]item[/list]', - '[list=i:][*:]item[/list:]', + '[list=i:][*:]item[/*:m:][/list:o:]', ), array( 'Test default bbcodes: simple list-item disc', '[list=disc][*]item[/list]', - '[list=disc:][*:]item[/list:]', + '[list=disc:][*:]item[/*:m:][/list:u:]', ), array( 'Test default bbcodes: simple list-item circle', '[list=circle][*]item[/list]', - '[list=circle:][*:]item[/list:]', + '[list=circle:][*:]item[/*:m:][/list:u:]', ), array( 'Test default bbcodes: simple list-item square', '[list=square][*]item[/list]', - '[list=square:][*:]item[/list:]', + '[list=square:][*:]item[/*:m:][/list:u:]', ), array( 'Test default bbcodes: simple img', '[img]https://area51.phpbb.com/images/area51.png[/img]', - '[img:]https://area51.phpbb.com/images/area51.png[/img:]', + '[img:]https://area51.phpbb.com/images/area51.png[/img:]', ), array( 'Test default bbcodes: simple url', '[url]https://area51.phpbb.com/[/url]', - '[url:]https://area51.phpbb.com/[/url:]', + '[url:]https://area51.phpbb.com/[/url:]', ), array( 'Test default bbcodes: simple url with description', '[url=https://area51.phpbb.com/]Area51[/url]', - '[url=https://area51.phpbb.com/:]Area51[/url:]', + '[url=https://area51.phpbb.com/:]Area51[/url:]', ), array( 'Test default bbcodes: simple email', '[email]bbcode-test@phpbb.com[/email]', - '[email:]bbcode-test@phpbb.com[/email:]', + '[email:]bbcode-test@phpbb.com[/email:]', ), array( 'Test default bbcodes: simple email with description', '[email=bbcode-test@phpbb.com]Email[/email]', - '[email=bbcode-test@phpbb.com:]Email[/email:]', + '[email=bbcode-test@phpbb.com:]Email[/email:]', ), array( 'Test default bbcodes: simple attachment', '[attachment=0]filename[/attachment]', - '[attachment=0:]filename[/attachment:]', + '[attachment=0:]filename[/attachment:]', ), // Special cases for quote which were reported as bugs before array( 'PHPBB3-1401 - correct: parsed', - '[quote="[test]test"]test [ test[/quote]', - '[quote="[test]test":]test [ test[/quote:]', + '[quote="[test]test"]test [ test[/quote]', + '[quote="[test]test":]test [ test[/quote:]', ), array( 'PHPBB3-6117 - correct: parsed', @@ -157,8 +162,8 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase ), array( 'PHPBB3-6200 - correct: parsed', - '[quote="["]test[/quote]', - '[quote="[":]test[/quote:]', + '[quote="["]test[/quote]', + '[quote="[":]test[/quote:]', ), array( 'PHPBB3-9364 - quoted: "test[/[/b]quote] test" / non-quoted: "[/quote] test" - also failed if layout distorted', @@ -167,35 +172,35 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase ), array( 'PHPBB3-8096 - first quote tag parsed, second quote tag unparsed', - '[quote="a"]a[/quote][quote="a]a[/quote]', - '[quote="a":]a[/quote:][quote="a]a[/quote]', + '[quote="a"]a[/quote][quote="a]a[/quote]', + '[quote="a":]a[/quote:][quote="a]a[/quote]', ), // Nesting bbcodes into quote usernames array( 'Allow textual BBcodes in usernames', - '[quote="[i]test[/i]"]test[/quote]', - '[quote="[i:]test[/i:]":]test[/quote:]', + '[quote="[i]test[/i]"]test[/quote]', + '[quote="[i:]test[/i:]":]test[/quote:]', ), array( 'Allow links BBcodes in usernames', - '[quote="[url=http://www.phpbb.com/]test[/url]"]test[/quote]', - '[quote="[url=http://www.phpbb.com/:]test[/url:]":]test[/quote:]', + '[quote="[url=https://area51.phpbb.com/]test[/url]"]test[/quote]', + '[quote="[url=https://area51.phpbb.com/:]test[/url:]":]test[/quote:]', ), array( - 'Disallow img BBcodes in usernames - Username displayed as [img]http://www.phpbb.com/[/img]', - '[quote="[img]http://www.phpbb.com/[/img]"]test[/quote]', - '[quote="[img]http://www.phpbb.com/[/img]":]test[/quote:]', + 'Allow img BBcodes in usernames - Username displayed the image', + '[quote="[img]https://area51.phpbb.com/images/area51.png[/img]"]test[/quote]', + '[quote="[img:]https://area51.phpbb.com/images/area51.png[/img:]":]test[/quote:]', ), array( 'Disallow flash BBcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]', - '[quote="[flash]http://www.phpbb.com/[/flash]"]test[/quote]', - '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', + '[quote="[flash]http://www.phpbb.com/[/flash]"]test[/quote]', + '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', ), array( 'Disallow quote BBcodes in usernames - Username displayed as [quote]test[/quote]', - '[quote="[quote]test[/quote]"]test[/quote]', - '[quote="[quote]test[/quote]":]test[/quote:]', + '[quote="[quote]test[/quote]"]test[/quote]', + '[quote="[quote]test[/quote]":]test[/quote:]', ), ); } -- cgit v1.2.1 From 8bbf3a788fd14a0c9dd67e985d401ce19c1da8a5 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 13:59:48 +0100 Subject: [ticket/11250] Run tests by default and add an option for incomplete ones PHPBB3-11250 --- tests/bbcode/parser_test.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index 0e1f405bae..be5cb8524e 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -211,7 +211,10 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase */ public function test_bbcode_firstpass($description, $message, $expected) { - $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); + if ($incomplete) + { + $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); + } global $user, $request; $user = new phpbb_mock_user; -- cgit v1.2.1 From 4f080ba0d66846ced15295cb0813245d54bd1833 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 14:29:11 +0100 Subject: [ticket/11250] Add tests for simple nesting and code PHPBB3-11250 --- tests/bbcode/parser_test.php | 51 ++++++++++++++++++++++++++++++++++++++------ 1 file changed, 44 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index be5cb8524e..b87c3668a9 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -17,7 +17,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase public function bbcode_firstpass_data() { return array( - // Default BBCodes from in their simplest way + // Default bbcodes from in their simplest way array( 'Test default bbcodes: simple bold', '[b]bold[/b]', @@ -176,32 +176,69 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase '[quote="a":]a[/quote:][quote="a]a[/quote]', ), + // Simple bbcodes nesting + array( + 'Allow textual bbcodes in textual bbcodes', + '[b]bold [i]bold + italic[/i][/b]', + '[b:]bold [i:]bold + italic[/i:][/b:]', + ), + array( + 'Allow textual bbcodes in url with description', + '[url=https://area51.phpbb.com/]Area51 [i]italic[/i][/url]', + '[url=https://area51.phpbb.com/:]Area51 [i:]italic[/i:][/url:]', + ), + array( + 'Allow url with description in textual bbcodes', + '[i]italic [url=https://area51.phpbb.com/]Area51[/url][/i]', + '[i:]italic [url=https://area51.phpbb.com/:]Area51[/url:][/i:]', + ), + // Nesting bbcodes into quote usernames array( - 'Allow textual BBcodes in usernames', + 'Allow textual bbcodes in usernames', '[quote="[i]test[/i]"]test[/quote]', '[quote="[i:]test[/i:]":]test[/quote:]', ), array( - 'Allow links BBcodes in usernames', + 'Allow links bbcodes in usernames', '[quote="[url=https://area51.phpbb.com/]test[/url]"]test[/quote]', '[quote="[url=https://area51.phpbb.com/:]test[/url:]":]test[/quote:]', ), array( - 'Allow img BBcodes in usernames - Username displayed the image', + 'Allow img bbcodes in usernames - Username displayed the image', '[quote="[img]https://area51.phpbb.com/images/area51.png[/img]"]test[/quote]', '[quote="[img:]https://area51.phpbb.com/images/area51.png[/img:]":]test[/quote:]', ), array( - 'Disallow flash BBcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]', + 'Disallow flash bbcodes in usernames - Username displayed as [flash]http://www.phpbb.com/[/flash]', '[quote="[flash]http://www.phpbb.com/[/flash]"]test[/quote]', '[quote="[flash]http://www.phpbb.com/[/flash]":]test[/quote:]', ), array( - 'Disallow quote BBcodes in usernames - Username displayed as [quote]test[/quote]', + 'Disallow quote bbcodes in usernames - Username displayed as [quote]test[/quote]', '[quote="[quote]test[/quote]"]test[/quote]', '[quote="[quote]test[/quote]":]test[/quote:]', ), + + // Do not parse bbcodes in code boxes + array( + 'Do not parse textual bbcodes in code', + '[code]unparsed code [b]bold [i]bold + italic[/i][/b][/code]', + '[code:]unparsed code [b]bold [i]bold + italic[/i][/b][/code:]', + ), + array( + 'Do not parse quote bbcodes in code', + '[code]unparsed code [quote="username"]quoted[/quote][/code]', + '[code:]unparsed code [quote="username"]quoted[/quote][/code:]', + ), + + // New user friendly mixed nesting + array( + 'Textual bbcode nesting into textual bbcode', + '[b]bold [i]bold + italic[/b] italic[/i]', + '[b:]bold [i:]bold + italic[/b:] italic[/i:]', + 'Incomplete: secondpass parses as [b:]bold [i:]bold + italic[/i:] italic[/b:]', + ), ); } @@ -209,7 +246,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase /** * @dataProvider bbcode_firstpass_data */ - public function test_bbcode_firstpass($description, $message, $expected) + public function test_bbcode_firstpass($description, $message, $expected, $incomplete = false) { if ($incomplete) { -- cgit v1.2.1 From ebe1f5d8dace9c3899432706f21a8dc8403fc350 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 14 Dec 2012 18:31:12 +0100 Subject: [ticket/11250] Use user defined message as incomplete message PHPBB3-11250 --- tests/bbcode/parser_test.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/bbcode/parser_test.php b/tests/bbcode/parser_test.php index b87c3668a9..d0dcce5bbf 100644 --- a/tests/bbcode/parser_test.php +++ b/tests/bbcode/parser_test.php @@ -237,12 +237,11 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase 'Textual bbcode nesting into textual bbcode', '[b]bold [i]bold + italic[/b] italic[/i]', '[b:]bold [i:]bold + italic[/b:] italic[/i:]', - 'Incomplete: secondpass parses as [b:]bold [i:]bold + italic[/i:] italic[/b:]', + 'Incomplete test case: secondpass parses as [b:]bold [i:]bold + italic[/i:] italic[/b:]', ), ); } - /** * @dataProvider bbcode_firstpass_data */ @@ -250,7 +249,7 @@ class phpbb_bbcode_parser_test extends PHPUnit_Framework_TestCase { if ($incomplete) { - $this->markTestIncomplete('New bbcode parser has not been backported from feature/ascraeus-experiment yet.'); + $this->markTestIncomplete($incomplete); } global $user, $request; -- cgit v1.2.1 From d1eb3449af5e7675f6896406e78fa1f240d4a3e8 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 14 Dec 2012 14:05:46 -0500 Subject: [ticket/11268] Delete phpbb_db_driver_mysql4 as there is no such thing. PHPBB3-11268 --- tests/test_framework/phpbb_database_test_connection_manager.php | 1 - 1 file changed, 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_database_test_connection_manager.php b/tests/test_framework/phpbb_database_test_connection_manager.php index 4ce5f03a8b..03097a10a0 100644 --- a/tests/test_framework/phpbb_database_test_connection_manager.php +++ b/tests/test_framework/phpbb_database_test_connection_manager.php @@ -227,7 +227,6 @@ class phpbb_database_test_connection_manager switch ($this->config['dbms']) { case 'phpbb_db_driver_mysql': - case 'phpbb_db_driver_mysql4': case 'phpbb_db_driver_mysqli': $sql = 'SHOW TABLES'; break; -- cgit v1.2.1 From ff83580af1af7623012843c56fba605ec2ad7df1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 13:45:33 -0500 Subject: [ticket/10758] Add a test for acp login. PHPBB3-10758 --- tests/functional/auth_test.php | 11 +++++++++++ tests/test_framework/phpbb_functional_test_case.php | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/functional/auth_test.php b/tests/functional/auth_test.php index 662b1bd38b..f92a4a2210 100644 --- a/tests/functional/auth_test.php +++ b/tests/functional/auth_test.php @@ -49,4 +49,15 @@ class phpbb_functional_auth_test extends phpbb_functional_test_case $this->assert_response_success(); $this->assertContains($this->lang('REGISTER'), $crawler->filter('.navbar')->text()); } + + public function test_acp_login() + { + $this->login(); + $this->admin_login(); + + // check that we are logged in + $crawler = $this->request('GET', 'adm/index.php?sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains($this->lang('ADMIN_PANEL'), $crawler->filter('h1')->text()); + } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 67a5050892..c599abcbcd 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -323,7 +323,7 @@ class phpbb_functional_test_case extends phpbb_test_case * Login to the ACP * You must run login() before calling this. */ - protected function admin_login() + protected function admin_login($username = 'admin') { $this->add_lang('acp/common'); @@ -343,7 +343,9 @@ class phpbb_functional_test_case extends phpbb_test_case { if (strpos($field, 'password_') === 0) { - $login = $this->client->submit($form, array('username' => 'admin', $field => 'admin')); + $crawler = $this->client->submit($form, array('username' => $username, $field => $username)); + $this->assert_response_success(); + $this->assertContains($this->lang('LOGIN_ADMIN_SUCCESS'), $crawler->filter('html')->text()); $cookies = $this->cookieJar->all(); -- cgit v1.2.1 From 7b9092ea3b4ea63bd8c20c1b66b8bd4240e2c497 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 16:17:18 -0500 Subject: [ticket/10758] Functional test for changing a user's permission. PHPBB3-10758 --- tests/functional/acp_permissions_test.php | 53 +++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/functional/acp_permissions_test.php (limited to 'tests') diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php new file mode 100644 index 0000000000..4c5ae9bbb1 --- /dev/null +++ b/tests/functional/acp_permissions_test.php @@ -0,0 +1,53 @@ +login(); + $this->admin_login(); + $this->add_lang('acp/permissions'); + + // Permissions tab + // XXX hardcoded ids + $crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid); + $this->assert_response_success(); + // these language strings are html + $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + + // User permissions + $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); + $this->assert_response_success(); + $this->assertContains($this->lang('ACP_USERS_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + + // Select admin + $form = $crawler->selectButton($this->lang('SUBMIT'))->form(); + $data = array('username[0]' => 'admin'); + $form->setValues($data); + $crawler = $this->client->submit($form); + $this->assert_response_success(); + $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + + // Set u_hideonline to never + $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); + // initially it should be a yes + $values = $form->getValues(); + $this->assertEquals(1, $values['setting[2][0][u_hideonline]']); + // set to never + $data = array('setting[2][0][u_hideonline]' => '0'); + $form->setValues($data); + $crawler = $this->client->submit($form); + $this->assert_response_success(); + $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text()); + } +} -- cgit v1.2.1 From 175b6deb6d263a3184d4b51cb1f00137cadc542e Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Sat, 15 Dec 2012 16:22:54 -0600 Subject: [ticket/8610] Do not use requests to submit posts except in posting_test.php Moving my functional test functions from posting_helpers.php to posting_test.php since it is a bit nicer and more reusable if posting_test.php is to be expanded in the future. PHPBB3-8610 --- tests/functional/posting_test.php | 112 +++++++++++++++++-- .../test_framework/phpbb_functional_test_case.php | 14 +-- tests/test_framework/posting_helpers.php | 119 --------------------- 3 files changed, 108 insertions(+), 137 deletions(-) delete mode 100644 tests/test_framework/posting_helpers.php (limited to 'tests') diff --git a/tests/functional/posting_test.php b/tests/functional/posting_test.php index dd078286d6..d05207edf0 100644 --- a/tests/functional/posting_test.php +++ b/tests/functional/posting_test.php @@ -15,25 +15,125 @@ class phpbb_functional_posting_test extends phpbb_functional_test_case public function test_post_new_topic() { $this->login(); - - include(__DIR__ . './../test_framework/posting_helpers.php'); - - $posting_helper = new phpbb_test_framework_posting_helpers($this); // Test creating topic - $post = $posting_helper->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); + $post = $this->create_topic(2, 'Test Topic 1', 'This is a test topic posted by the testing framework.'); $crawler = $this->request('GET', "viewtopic.php?t={$post['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test topic posted by the testing framework.', $crawler->filter('html')->text()); // Test creating a reply - $post2 = $posting_helper->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); + $post2 = $this->create_post(2, $post['topic_id'], 'Re: Test Topic 1', 'This is a test post posted by the testing framework.'); $crawler = $this->request('GET', "viewtopic.php?t={$post2['topic_id']}&sid={$this->sid}"); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); // Test quoting a message $crawler = $this->request('GET', "posting.php?mode=quote&f=2&t={$post2['topic_id']}&p={$post2['post_id']}&sid={$this->sid}"); + $this->assert_response_success(); $this->assertContains('This is a test post posted by the testing framework.', $crawler->filter('html')->text()); } + + /** + * Creates a topic + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return $this->submit_post($posting_url, 'POST_TOPIC', $form_data); + } + + /** + * Creates a post + * + * Be sure to login before creating + * + * @param int $forum_id + * @param string $subject + * @param string $message + * @param array $additional_form_data Any additional form data to be sent in the request + * @return array post_id, topic_id + */ + public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) + { + $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->sid}"; + + $form_data = array_merge(array( + 'subject' => $subject, + 'message' => $message, + 'post' => true, + ), $additional_form_data); + + return $this->submit_post($posting_url, 'POST_REPLY', $form_data); + } + + /** + * Helper for submitting posts + * + * @param string $posting_url + * @param string $posting_contains + * @param array $form_data + * @return array post_id, topic_id + */ + protected function submit_post($posting_url, $posting_contains, $form_data) + { + $this->add_lang('posting'); + + $crawler = $this->request('GET', $posting_url); + $this->assert_response_success(); + $this->assertContains($this->lang($posting_contains), $crawler->filter('html')->text()); + + $hidden_fields = array( + $crawler->filter('[type="hidden"]')->each(function ($node, $i) { + return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); + }), + ); + + foreach ($hidden_fields as $fields) + { + foreach($fields as $field) + { + $form_data[$field['name']] = $field['value']; + } + } + + // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) + // is not at least 2 seconds before submission, cancel the form + $form_data['lastclick'] = 0; + + // I use a request because the form submission method does not allow you to send data that is not + // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) + // Instead, I send it as a request with the submit button "post" set to true. + $crawler = $this->client->request('POST', $posting_url, $form_data); + $this->assert_response_success(); + $this->assertContains($this->lang('POST_STORED'), $crawler->filter('html')->text()); + + $url = $crawler->selectLink($this->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); + + $matches = $topic_id = $post_id = false; + preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); + + $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; + $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; + + return array( + 'topic_id' => $topic_id, + 'post_id' => $post_id, + ); + } } diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 097db62e29..8ab6469e9a 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -299,7 +299,7 @@ class phpbb_functional_test_case extends phpbb_test_case } } - public function add_lang($lang_file) + protected function add_lang($lang_file) { if (is_array($lang_file)) { @@ -321,7 +321,7 @@ class phpbb_functional_test_case extends phpbb_test_case $this->lang = array_merge($this->lang, $lang); } - public function lang() + protected function lang() { $args = func_get_args(); $key = $args[0]; @@ -350,14 +350,4 @@ class phpbb_functional_test_case extends phpbb_test_case $content = $this->client->getResponse()->getContent(); $this->assertNotContains('Fatal error:', $content); } - - public function get_sid() - { - return $this->sid; - } - - public function get_client() - { - return $this->client; - } } diff --git a/tests/test_framework/posting_helpers.php b/tests/test_framework/posting_helpers.php deleted file mode 100644 index 329cf5a1b4..0000000000 --- a/tests/test_framework/posting_helpers.php +++ /dev/null @@ -1,119 +0,0 @@ -test_case = $test_case; - } - - /** - * Creates a topic - * - * Be sure to login before creating - * - * @param int $forum_id - * @param string $subject - * @param string $message - * @param array $additional_form_data Any additional form data to be sent in the request - * @return array post_id, topic_id - */ - public function create_topic($forum_id, $subject, $message, $additional_form_data = array()) - { - $posting_url = "posting.php?mode=post&f={$forum_id}&sid={$this->test_case->get_sid()}"; - - $form_data = array_merge(array( - 'subject' => $subject, - 'message' => $message, - 'post' => true, - ), $additional_form_data); - - return $this->submit_post($posting_url, 'POST_TOPIC', $form_data); - } - - /** - * Creates a post - * - * Be sure to login before creating - * - * @param int $forum_id - * @param string $subject - * @param string $message - * @param array $additional_form_data Any additional form data to be sent in the request - * @return array post_id, topic_id - */ - public function create_post($forum_id, $topic_id, $subject, $message, $additional_form_data = array()) - { - $posting_url = "posting.php?mode=reply&f={$forum_id}&t={$topic_id}&sid={$this->test_case->get_sid()}"; - - $form_data = array_merge(array( - 'subject' => $subject, - 'message' => $message, - 'post' => true, - ), $additional_form_data); - - return $this->submit_post($posting_url, 'POST_REPLY', $form_data); - } - - /** - * Helper for submitting posts - * - * @param string $posting_url - * @param string $posting_contains - * @param array $form_data - * @return array post_id, topic_id - */ - protected function submit_post($posting_url, $posting_contains, $form_data) - { - $this->test_case->add_lang('posting'); - - $crawler = $this->test_case->request('GET', $posting_url); - $this->test_case->assertContains($this->test_case->lang($posting_contains), $crawler->filter('html')->text()); - - $hidden_fields = array( - $crawler->filter('[type="hidden"]')->each(function ($node, $i) { - return array('name' => $node->getAttribute('name'), 'value' => $node->getAttribute('value')); - }), - ); - - foreach ($hidden_fields as $fields) - { - foreach($fields as $field) - { - $form_data[$field['name']] = $field['value']; - } - } - - // Bypass time restriction that said that if the lastclick time (i.e. time when the form was opened) - // is not at least 2 seconds before submission, cancel the form - $form_data['lastclick'] = 0; - - // I use a request because the form submission method does not allow you to send data that is not - // contained in one of the actual form fields that the browser sees (i.e. it ignores "hidden" inputs) - // Instead, I send it as a request with the submit button "post" set to true. - $crawler = $this->test_case->get_client()->request('POST', $posting_url, $form_data); - $this->test_case->assertContains($this->test_case->lang('POST_STORED'), $crawler->filter('html')->text()); - - $url = $crawler->selectLink($this->test_case->lang('VIEW_MESSAGE', '', ''))->link()->getUri(); - - $matches = $topic_id = $post_id = false; - preg_match_all('#&t=([0-9]+)(&p=([0-9]+))?#', $url, $matches); - - $topic_id = (int) (isset($matches[1][0])) ? $matches[1][0] : 0; - $post_id = (int) (isset($matches[3][0])) ? $matches[3][0] : 0; - - return array( - 'topic_id' => $topic_id, - 'post_id' => $post_id, - ); - } -} -- cgit v1.2.1 From 54d96dfac720d5aa1cdc617ca93749d26ee9f264 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 17 Dec 2012 12:59:44 +0100 Subject: [ticket/10763] Make functions for remote avatars static fileupload::image_types() and filespec::get_extension() are called statically while submitting the form for the remote avatar. Make them static as described in the ticket in order to prevent a PHP notice. Also change the tests to use the static functions. PHPBB3-10763 --- tests/mock/fileupload.php | 29 ----------------------------- tests/upload/filespec_test.php | 3 +-- 2 files changed, 1 insertion(+), 31 deletions(-) (limited to 'tests') diff --git a/tests/mock/fileupload.php b/tests/mock/fileupload.php index 409036ba63..cbcbf4a6ab 100644 --- a/tests/mock/fileupload.php +++ b/tests/mock/fileupload.php @@ -20,33 +20,4 @@ class phpbb_mock_fileupload { return true; } - - /** - * Copied verbatim from phpBB/includes/functions_upload.php's fileupload - * class to ensure the correct behaviour of filespec::move_file. - * - * Maps file extensions to the constant in second index of the array - * returned by getimagesize() - */ - public function image_types() - { - return array( - IMAGETYPE_GIF => array('gif'), - IMAGETYPE_JPEG => array('jpg', 'jpeg'), - IMAGETYPE_PNG => array('png'), - IMAGETYPE_SWF => array('swf'), - IMAGETYPE_PSD => array('psd'), - IMAGETYPE_BMP => array('bmp'), - IMAGETYPE_TIFF_II => array('tif', 'tiff'), - IMAGETYPE_TIFF_MM => array('tif', 'tiff'), - IMAGETYPE_JPC => array('jpg', 'jpeg'), - IMAGETYPE_JP2 => array('jpg', 'jpeg'), - IMAGETYPE_JPX => array('jpg', 'jpeg'), - IMAGETYPE_JB2 => array('jpg', 'jpeg'), - IMAGETYPE_SWC => array('swc'), - IMAGETYPE_IFF => array('iff'), - IMAGETYPE_WBMP => array('wbmp'), - IMAGETYPE_XBM => array('xbm'), - ); - } } diff --git a/tests/upload/filespec_test.php b/tests/upload/filespec_test.php index c7ff2e78e0..87cd00197f 100644 --- a/tests/upload/filespec_test.php +++ b/tests/upload/filespec_test.php @@ -205,8 +205,7 @@ class phpbb_filespec_test extends phpbb_test_case */ public function test_get_extension($filename, $expected) { - $filespec = $this->get_filespec(); - $this->assertEquals($expected, $filespec->get_extension($filename)); + $this->assertEquals($expected, filespec::get_extension($filename)); } public function is_image_variables() -- cgit v1.2.1 From ac3e69cb0856779016dcc02060e8e30b804fcd67 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 19 Dec 2012 21:49:41 -0500 Subject: [ticket/10758] Check that acl was changed in the test. PHPBB3-10758 --- tests/functional/acp_permissions_test.php | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php index 4c5ae9bbb1..0fa7898963 100644 --- a/tests/functional/acp_permissions_test.php +++ b/tests/functional/acp_permissions_test.php @@ -19,7 +19,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $this->add_lang('acp/permissions'); // Permissions tab - // XXX hardcoded ids + // XXX hardcoded id $crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid); $this->assert_response_success(); // these language strings are html @@ -38,6 +38,17 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $this->assert_response_success(); $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + // XXX globals for phpbb_auth, refactor it later + global $db, $cache; + $db = $this->get_db(); + $cache = new phpbb_mock_null_cache; + + $auth = new phpbb_auth; + // XXX hardcoded id + $user_data = $auth->obtain_user_data(2); + $auth->acl($user_data); + $this->assertEquals(1, $auth->acl_get('u_hideonline')); + // Set u_hideonline to never $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); // initially it should be a yes @@ -49,5 +60,12 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $crawler = $this->client->submit($form); $this->assert_response_success(); $this->assertContains($this->lang('AUTH_UPDATED'), $crawler->text()); + + // check acl again + $auth = new phpbb_auth; + // XXX hardcoded id + $user_data = $auth->obtain_user_data(2); + $auth->acl($user_data); + $this->assertEquals(0, $auth->acl_get('u_hideonline')); } } -- cgit v1.2.1 From 3327a4676ce2f894881485aa8f5a5c40c9ea260e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 17:26:48 -0500 Subject: [ticket/10758] Test moderator and admin permissions. PHPBB3-10758 --- tests/functional/acp_permissions_test.php | 65 ++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 5 deletions(-) (limited to 'tests') diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php index 0fa7898963..511306ac84 100644 --- a/tests/functional/acp_permissions_test.php +++ b/tests/functional/acp_permissions_test.php @@ -12,19 +12,27 @@ */ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case { - public function test_set_permission() + public function setUp() { + parent::setUp(); + $this->login(); $this->admin_login(); $this->add_lang('acp/permissions'); + } + public function test_permissions_tab() + { // Permissions tab // XXX hardcoded id $crawler = $this->request('GET', 'adm/index.php?i=16&sid=' . $this->sid); $this->assert_response_success(); // these language strings are html $this->assertContains($this->lang('ACP_PERMISSIONS_EXPLAIN'), $this->client->getResponse()->getContent()); + } + public function test_select_user() + { // User permissions $crawler = $this->request('GET', 'adm/index.php?i=acp_permissions&icat=16&mode=setting_user_global&sid=' . $this->sid); $this->assert_response_success(); @@ -37,6 +45,53 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case $crawler = $this->client->submit($form); $this->assert_response_success(); $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); + } + + public function permissions_data() + { + return array( + // description + // permission type + // permission name + // mode + // object name + // object id + array( + 'user permission', + 'u_', + 'u_hideonline', + 'setting_user_global', + 'user_id', + 2, + ), + array( + 'moderator permission', + 'm_', + 'm_ban', + 'setting_mod_global', + 'group_id', + 4, + ), + array( + 'admin permission', + 'a_', + 'a_forum', + 'setting_admin_global', + 'group_id', + 5, + ), + ); + } + + /** + * @dataProvider permissions_data + */ + public function test_change_permission($description, $permission_type, $permission, $mode, $object_name, $object_id) + { + // Get the form + $crawler = $this->request('GET', "adm/index.php?i=acp_permissions&icat=16&mode=$mode&${object_name}[0]=$object_id&type=$permission_type&sid=" . $this->sid); + $this->assert_response_success(); + $this->assertContains($this->lang('ACL_SET'), $crawler->filter('h1')->eq(1)->text()); // XXX globals for phpbb_auth, refactor it later global $db, $cache; @@ -47,15 +102,15 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case // XXX hardcoded id $user_data = $auth->obtain_user_data(2); $auth->acl($user_data); - $this->assertEquals(1, $auth->acl_get('u_hideonline')); + $this->assertEquals(1, $auth->acl_get($permission)); // Set u_hideonline to never $form = $crawler->selectButton($this->lang('APPLY_PERMISSIONS'))->form(); // initially it should be a yes $values = $form->getValues(); - $this->assertEquals(1, $values['setting[2][0][u_hideonline]']); + $this->assertEquals(1, $values["setting[$object_id][0][$permission]"]); // set to never - $data = array('setting[2][0][u_hideonline]' => '0'); + $data = array("setting[$object_id][0][$permission]" => '0'); $form->setValues($data); $crawler = $this->client->submit($form); $this->assert_response_success(); @@ -66,6 +121,6 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case // XXX hardcoded id $user_data = $auth->obtain_user_data(2); $auth->acl($user_data); - $this->assertEquals(0, $auth->acl_get('u_hideonline')); + $this->assertEquals(0, $auth->acl_get($permission)); } } -- cgit v1.2.1 From f9cee47003ad76c124822675cf4db0406af1bd70 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 15 Dec 2012 17:33:07 -0500 Subject: [ticket/10758] Admin is not working yet. PHPBB3-10758 --- tests/functional/acp_permissions_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/functional/acp_permissions_test.php b/tests/functional/acp_permissions_test.php index 511306ac84..f7fd44fc89 100644 --- a/tests/functional/acp_permissions_test.php +++ b/tests/functional/acp_permissions_test.php @@ -72,6 +72,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case 'group_id', 4, ), + /* Admin does not work yet, probably because founder can do everything array( 'admin permission', 'a_', @@ -80,6 +81,7 @@ class phpbb_functional_acp_permissions_test extends phpbb_functional_test_case 'group_id', 5, ), + */ ); } -- cgit v1.2.1 From e50f69187f21e29a12512880e0c69f2876e84aa1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 20 Dec 2012 04:35:30 -0500 Subject: [ticket/11037] Eliminate global $db usage in cache drivers. The only time $db is needed in cache drivers is to navigate the result set in sql_save. Pass it as a parameter in that function. PHPBB3-11037 --- tests/mock/cache.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/mock/cache.php b/tests/mock/cache.php index bc18ca066b..71af3037f5 100644 --- a/tests/mock/cache.php +++ b/tests/mock/cache.php @@ -121,7 +121,11 @@ class phpbb_mock_cache implements phpbb_cache_driver_interface public function sql_load($query) { } - public function sql_save($query, $query_result, $ttl) + + /** + * {@inheritDoc} + */ + public function sql_save(phpbb_db_driver $db, $query, $query_result, $ttl) { return $query_result; } -- cgit v1.2.1 From 00d8f944da084a660ef72f21438b22297eb1c857 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 20 Dec 2012 13:20:05 -0500 Subject: [ticket/11285] Use more granularity in dependency checks in compress test Some of the tests can be run without zlib or bz2 extensions present. PHPBB3-11285 --- tests/compress/compress_test.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/compress/compress_test.php b/tests/compress/compress_test.php index 65094671e3..ce193cf3ba 100644 --- a/tests/compress/compress_test.php +++ b/tests/compress/compress_test.php @@ -32,10 +32,16 @@ class phpbb_compress_test extends phpbb_test_case $phpbb_root_path = ''; $this->path = dirname(__FILE__) . '/fixtures/'; + } - if (!@extension_loaded('zlib') || !@extension_loaded('bz2')) + protected function check_extensions($extensions) + { + foreach ($extensions as $extension) { - $this->markTestSkipped('PHP needs to be compiled with --with-zlib and --with-bz2 in order to run these tests'); + if (!@extension_loaded($extension)) + { + $this->markTestSkipped("$extension extension is not loaded"); + } } } @@ -103,17 +109,18 @@ class phpbb_compress_test extends phpbb_test_case public function tar_archive_list() { return array( - array('archive.tar', '.tar'), - array('archive.tar.gz', '.tar.gz'), - array('archive.tar.bz2', '.tar.bz2'), + array('archive.tar', '.tar', array()), + array('archive.tar.gz', '.tar.gz', array('zlib')), + array('archive.tar.bz2', '.tar.bz2', array('bz2')), ); } /** * @dataProvider tar_archive_list */ - public function test_extract_tar($filename, $type) + public function test_extract_tar($filename, $type, $extensions) { + $this->check_extensions($extensions); $compress = new compress_tar('r', $this->path . $filename); $compress->extract('tests/compress/' . self::EXTRACT_DIR); $this->valid_extraction(); @@ -130,8 +137,10 @@ class phpbb_compress_test extends phpbb_test_case * @depends test_extract_tar * @dataProvider tar_archive_list */ - public function test_compress_tar($filename, $type) + public function test_compress_tar($filename, $type, $extensions) { + $this->check_extensions($extensions); + $tar = dirname(__FILE__) . self::ARCHIVE_DIR . $filename; $compress = new compress_tar('w', $tar); $this->archive_files($compress); @@ -149,6 +158,8 @@ class phpbb_compress_test extends phpbb_test_case */ public function test_compress_zip() { + $this->check_extensions(array('zlib')); + $zip = dirname(__FILE__) . self::ARCHIVE_DIR . 'archive.zip'; $compress = new compress_zip('w', $zip); $this->archive_files($compress); -- cgit v1.2.1 From b6f40f7c33a4cdb4a31af6374b2b1fd7c13deb08 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 20 Dec 2012 20:27:59 -0500 Subject: [ticket/10758-upload] Convert error to a failure. PHPBB3-10758 --- tests/functional/fileupload_form_test.php | 2 +- tests/test_framework/phpbb_functional_test_case.php | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 99afcfdc3d..68dfba8fb9 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -45,7 +45,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case public function test_empty_file() { $crawler = $this->upload_file('empty.png', 'image/png'); - $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $crawler->filter('div#message p')->text()); + $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $this->assert_filter($crawler, 'div#message p')->text()); } public function test_invalid_extension() diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 67a5050892..a051410d7b 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -424,4 +424,20 @@ class phpbb_functional_test_case extends phpbb_test_case $content = $this->client->getResponse()->getContent(); $this->assertNotContains('Fatal error:', $content); } + + public function assert_filter($crawler, $expr, $msg = null) + { + $nodes = $crawler->filter($expr); + if ($msg) + { + $msg .= "\n"; + } + else + { + $msg = ''; + } + $msg .= "`$expr` not found in DOM."; + $this->assertGreaterThan(0, count($nodes), $msg); + return $nodes; + } } -- cgit v1.2.1 From cc0f6d471f9dd0d035669e408c1b7c53e157bc6e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Fri, 21 Dec 2012 01:45:24 -0500 Subject: [ticket/10758-upload] Mark tests that don't work incomplete. PHPBB3-10758 --- tests/functional/fileupload_form_test.php | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tests') diff --git a/tests/functional/fileupload_form_test.php b/tests/functional/fileupload_form_test.php index 68dfba8fb9..b663c89e95 100644 --- a/tests/functional/fileupload_form_test.php +++ b/tests/functional/fileupload_form_test.php @@ -44,6 +44,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case public function test_empty_file() { + $this->markTestIncomplete('Test fails intermittently.'); $crawler = $this->upload_file('empty.png', 'image/png'); $this->assertEquals($this->lang('ATTACHED_IMAGE_NOT_IMAGE'), $this->assert_filter($crawler, 'div#message p')->text()); } @@ -63,6 +64,7 @@ class phpbb_functional_fileupload_form_test extends phpbb_functional_test_case public function test_valid_file() { + $this->markTestIncomplete('Test fails intermittently.'); $crawler = $this->upload_file('valid.jpg', 'image/jpeg'); $this->assert_response_success(); // ensure there was no error message rendered -- cgit v1.2.1 From c0b3151f0d8c394ab1522332549132ffc4ca3d63 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 25 Dec 2012 07:15:58 -0500 Subject: [ticket/11294] Update required/optional extension list for olympus. PHPBB3-11294 --- tests/RUNNING_TESTS.txt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 7c2a7c3fce..95c6b0a057 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -17,7 +17,24 @@ PHP extensions Unit tests use several PHP extensions that board code does not use. Currently the following PHP extensions must be installed and enabled to run unit tests: -- ctype +- ctype (also a phpunit dependency) +- dom (phpunit dependency) + +Some of the functionality in phpBB and/or the test suite uses additional +PHP extensions. If these extensions are not loaded, respective tests +will be skipped: + +- apc (APC cache driver) +- bz2 (compress tests) +- interbase, pdo_firebird (Firebird database driver) +- mysql, pdo_mysql (MySQL database driver) +- mysqli, pdo_mysql (MySQLi database driver) +- pdo (any database tests) +- pgsql, pdo_pgsql (PostgreSQL database driver) +- simplexml (any database tests) +- sqlite, pdo_sqlite (SQLite database driver, requires SQLite 2.x support + in pdo_sqlite) +- zlib (compress tests) Database Tests -------------- -- cgit v1.2.1 From bc797c7da22ef1b0c68494d9a93eb23b981e2ebd Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 26 Dec 2012 10:41:13 -0500 Subject: [ticket/11294] Capitalize phpunit. PHPBB3-11294 --- tests/RUNNING_TESTS.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index 95c6b0a057..de9c751238 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -17,8 +17,8 @@ PHP extensions Unit tests use several PHP extensions that board code does not use. Currently the following PHP extensions must be installed and enabled to run unit tests: -- ctype (also a phpunit dependency) -- dom (phpunit dependency) +- ctype (also a PHPUnit dependency) +- dom (PHPUnit dependency) Some of the functionality in phpBB and/or the test suite uses additional PHP extensions. If these extensions are not loaded, respective tests @@ -61,7 +61,7 @@ to use in the environment as follows: $ PHPBB_TEST_CONFIG=tests/test_config.php phpunit Alternatively you can specify parameters in the environment, so e.g. the -following will run phpunit with the same parameters as in the shown +following will run PHPUnit with the same parameters as in the shown test_config.php file: $ PHPBB_TEST_DBMS='mysqli' PHPBB_TEST_DBHOST='localhost' \ -- cgit v1.2.1 From ca7327ba2671b6070b865d013d76f0a8894f2879 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 25 Dec 2012 07:17:41 -0500 Subject: [ticket/11294] Update required/optional extension list for develop. PHPBB3-11294 --- tests/RUNNING_TESTS.txt | 3 +++ 1 file changed, 3 insertions(+) (limited to 'tests') diff --git a/tests/RUNNING_TESTS.txt b/tests/RUNNING_TESTS.txt index ee2657c85f..cede81d59d 100644 --- a/tests/RUNNING_TESTS.txt +++ b/tests/RUNNING_TESTS.txt @@ -19,6 +19,7 @@ the following PHP extensions must be installed and enabled to run unit tests: - ctype (also a PHPUnit dependency) - dom (PHPUnit dependency) +- json (also a phpBB dependency) Some of the functionality in phpBB and/or the test suite uses additional PHP extensions. If these extensions are not loaded, respective tests @@ -29,8 +30,10 @@ will be skipped: - interbase, pdo_firebird (Firebird database driver) - mysql, pdo_mysql (MySQL database driver) - mysqli, pdo_mysql (MySQLi database driver) +- pcntl (flock class) - pdo (any database tests) - pgsql, pdo_pgsql (PostgreSQL database driver) +- redis (https://github.com/nicolasff/phpredis, Redis cache driver) - simplexml (any database tests) - sqlite, pdo_sqlite (SQLite database driver, requires SQLite 2.x support in pdo_sqlite) -- cgit v1.2.1 From 9c7772040c473fd453971eeb2c9ee8ed26069a2d Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sat, 29 Dec 2012 14:23:14 -0500 Subject: [ticket/11037] Fix unit tests. PHPBB3-11037 --- tests/cache/common_test_case.php | 5 +++-- tests/cache/null_driver_test.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) (limited to 'tests') diff --git a/tests/cache/common_test_case.php b/tests/cache/common_test_case.php index fa298ec9ae..a5bc2bfda9 100644 --- a/tests/cache/common_test_case.php +++ b/tests/cache/common_test_case.php @@ -64,9 +64,10 @@ abstract class phpbb_cache_common_test_case extends phpbb_database_test_case public function test_cache_sql() { - global $db, $cache; + global $db, $cache, $phpbb_root_path, $phpEx; + $config = new phpbb_config(array()); $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); + $cache = new phpbb_cache_service($this->driver, $config, $db, $phpbb_root_path, $phpEx); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; diff --git a/tests/cache/null_driver_test.php b/tests/cache/null_driver_test.php index 86553d4dc5..43a0cc806c 100644 --- a/tests/cache/null_driver_test.php +++ b/tests/cache/null_driver_test.php @@ -47,9 +47,10 @@ class phpbb_cache_null_driver_test extends phpbb_database_test_case public function test_cache_sql() { - global $db, $cache; + global $db, $cache, $phpbb_root_path, $phpEx; + $config = new phpbb_config(array()); $db = $this->new_dbal(); - $cache = new phpbb_cache_service($this->driver); + $cache = new phpbb_cache_service($this->driver, $config, $db, $phpbb_root_path, $phpEx); $sql = "SELECT * FROM phpbb_config WHERE config_name = 'foo'"; -- cgit v1.2.1 From 0483971f7786b10c3359dfbe4912501de0d6c7de Mon Sep 17 00:00:00 2001 From: Igor Wiedler Date: Wed, 2 Jan 2013 21:44:22 +0100 Subject: [ticket/11305] Mock container for cache driver in functional create_user() create_user has calls to fetch the cache driver from the container. This PR mocks the container and returns a null cache driver in that case. PHPBB3-11305 --- tests/test_framework/phpbb_functional_test_case.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/test_framework/phpbb_functional_test_case.php b/tests/test_framework/phpbb_functional_test_case.php index 59979e035d..e346223a4b 100644 --- a/tests/test_framework/phpbb_functional_test_case.php +++ b/tests/test_framework/phpbb_functional_test_case.php @@ -262,7 +262,7 @@ class phpbb_functional_test_case extends phpbb_test_case $config['rand_seed_last_update'] = time() + 600; // Required by user_add - global $db, $cache, $phpbb_dispatcher; + global $db, $cache, $phpbb_dispatcher, $phpbb_container; $db = $this->get_db(); if (!function_exists('phpbb_mock_null_cache')) { @@ -270,6 +270,14 @@ class phpbb_functional_test_case extends phpbb_test_case } $cache = new phpbb_mock_null_cache; + $cache_driver = new phpbb_cache_driver_null(); + $phpbb_container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); + $phpbb_container + ->expects($this->any()) + ->method('get') + ->with('cache.driver') + ->will($this->returnValue($cache_driver)); + if (!function_exists('utf_clean_string')) { require_once(__DIR__ . '/../../phpBB/includes/utf/utf_tools.php'); -- cgit v1.2.1 From 71e07ecc471f013aec698654cf5cfa928c8ad0e8 Mon Sep 17 00:00:00 2001 From: Nathan Guse Date: Thu, 10 Jan 2013 19:21:12 -0600 Subject: [ticket/11320] Include functions file as we need phpbb_convert_30_dbms_to_31 PHPBB3-11320 --- tests/test_framework/phpbb_test_case_helpers.php | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'tests') diff --git a/tests/test_framework/phpbb_test_case_helpers.php b/tests/test_framework/phpbb_test_case_helpers.php index 47459832d5..20ae384f21 100644 --- a/tests/test_framework/phpbb_test_case_helpers.php +++ b/tests/test_framework/phpbb_test_case_helpers.php @@ -77,6 +77,11 @@ class phpbb_test_case_helpers { include($test_config); + if (!function_exists('phpbb_convert_30_dbms_to_31')) + { + require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; + } + $config = array_merge($config, array( 'dbms' => phpbb_convert_30_dbms_to_31($dbms), 'dbhost' => $dbhost, -- cgit v1.2.1 From 4c50a35b62a46de69b439f9ac8007721d76881b0 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Mon, 14 Jan 2013 01:14:29 +0100 Subject: [ticket/11323] Add tests for inclusion of defined variables This adds 2 tests for the template engine. The test using include_define_variable.html will test if a defined variable, which was defined with another template variable, can be used to include a file. The second test will do the same inside a loop using a loop variable. PHPBB3-11323 --- tests/template/template_test.php | 17 ++++++++++++++++- tests/template/templates/include_define_variable.html | 2 ++ tests/template/templates/include_loop_define.html | 4 ++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tests/template/templates/include_define_variable.html create mode 100644 tests/template/templates/include_loop_define.html (limited to 'tests') diff --git a/tests/template/template_test.php b/tests/template/template_test.php index 9b3c6ac245..291b424bdd 100644 --- a/tests/template/template_test.php +++ b/tests/template/template_test.php @@ -238,7 +238,22 @@ class phpbb_template_template_test extends phpbb_test_case array('loop' => array(array('VARIABLE' => 'x'), array('VARIABLE' => 'y')), 'loop.inner' => array(array(), array())), array('loop'), '', - ),/* no top level nested loops + ), + array( + 'include_define_variable.html', + array('VARIABLE' => 'variable.html'), + array(), + array(), + 'variable.html', + ), + array( + 'include_loop_define.html', + array('VARIABLE' => 'value'), + array('loop' => array(array('NESTED_FILE' => 'variable.html'))), + array(), + 'value', + ), + /* no top level nested loops array( 'loop_vars.html', array(), diff --git a/tests/template/templates/include_define_variable.html b/tests/template/templates/include_define_variable.html new file mode 100644 index 0000000000..aff9b574c2 --- /dev/null +++ b/tests/template/templates/include_define_variable.html @@ -0,0 +1,2 @@ + + diff --git a/tests/template/templates/include_loop_define.html b/tests/template/templates/include_loop_define.html new file mode 100644 index 0000000000..f539b21396 --- /dev/null +++ b/tests/template/templates/include_loop_define.html @@ -0,0 +1,4 @@ + + + + -- cgit v1.2.1