From 33a0859f4ac3454c12dda651f708e16fc6c45adb Mon Sep 17 00:00:00 2001 From: Marc Alexander <admin@m-a-styles.de> Date: Thu, 30 May 2013 20:34:21 +0200 Subject: [ticket/11579] Move tests into seperate files depending on needed fixture PHPBB3-11579 --- tests/functions/validate_email_test.php | 72 +++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 tests/functions/validate_email_test.php (limited to 'tests/functions/validate_email_test.php') diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php new file mode 100644 index 0000000000..47aa37e11f --- /dev/null +++ b/tests/functions/validate_email_test.php @@ -0,0 +1,72 @@ +<?php +/** +* +* @package testing +* @copyright (c) 2013 phpBB Group +* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2 +* +*/ + +require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; +require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; +require_once dirname(__FILE__) . '/../mock/user.php'; +require_once dirname(__FILE__) . '/common_validate_data.php'; + +class phpbb_functions_validate_email_test extends phpbb_database_test_case +{ + protected $db; + protected $user; + protected $common; + + public function getDataSet() + { + return $this->createXMLDataSet(dirname(__FILE__) . '/fixtures/validate_email.xml'); + } + + protected function setUp() + { + parent::setUp(); + + $this->db = $this->new_dbal(); + $this->user = new phpbb_mock_user; + $this->common = new phpbb_functions_common_validate_data; + } + + public function test_validate_email() + { + global $config, $db, $user; + + $config['email_check_mx'] = true; + $db = $this->db; + $user = $this->user; + $user->optionset('banned_users', array('banned@example.com')); + + $this->common->validate_data_check(array( + 'empty' => '', + 'allowed' => 'foobar@example.com', + 'invalid' => 'fööbar@example.com', + 'valid_complex' => "'%$~test@example.com", + 'taken' => 'admin@example.com', + 'banned' => 'banned@example.com', + 'no_mx' => 'test@wwrrrhhghgghgh.ttv', + ), + array( + 'empty' => array('email'), + 'allowed' => array('email', 'foobar@example.com'), + 'invalid' => array('email'), + 'valid_complex' => array('email'), + 'taken' => array('email'), + 'banned' => array('email'), + 'no_mx' => array('email'), + ), + array( + 'empty' => array(), + 'allowed' => array(), + 'invalid' => array('EMAIL_INVALID'), + 'valid_complex' => array(), + 'taken' => array('EMAIL_TAKEN'), + 'banned' => array('EMAIL_BANNED'), + 'no_mx' => array('DOMAIN_NO_MX_RECORD'), + )); + } +} -- cgit v1.2.1 From 3487b70cc066f090c55990a9082ed9684d438147 Mon Sep 17 00:00:00 2001 From: Marc Alexander <admin@m-a-styles.de> Date: Mon, 3 Jun 2013 16:06:11 +0200 Subject: [ticket/11579] Use test case helper class and use assert prefix for method PHPBB3-11579 --- tests/functions/validate_email_test.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'tests/functions/validate_email_test.php') diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php index 47aa37e11f..2e81d3277e 100644 --- a/tests/functions/validate_email_test.php +++ b/tests/functions/validate_email_test.php @@ -10,13 +10,13 @@ require_once dirname(__FILE__) . '/../../phpBB/includes/functions.php'; require_once dirname(__FILE__) . '/../../phpBB/includes/functions_user.php'; require_once dirname(__FILE__) . '/../mock/user.php'; -require_once dirname(__FILE__) . '/common_validate_data.php'; +require_once dirname(__FILE__) . '/validate_data_helper.php'; class phpbb_functions_validate_email_test extends phpbb_database_test_case { protected $db; protected $user; - protected $common; + protected $helper; public function getDataSet() { @@ -29,7 +29,7 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $this->db = $this->new_dbal(); $this->user = new phpbb_mock_user; - $this->common = new phpbb_functions_common_validate_data; + $this->helper = new phpbb_functions_validate_data_helper($this); } public function test_validate_email() @@ -41,7 +41,16 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $user = $this->user; $user->optionset('banned_users', array('banned@example.com')); - $this->common->validate_data_check(array( + $this->helper->assert_validate_data(array( + 'empty' => array(), + 'allowed' => array(), + 'invalid' => array('EMAIL_INVALID'), + 'valid_complex' => array(), + 'taken' => array('EMAIL_TAKEN'), + 'banned' => array('EMAIL_BANNED'), + 'no_mx' => array('DOMAIN_NO_MX_RECORD'), + ), + array( 'empty' => '', 'allowed' => 'foobar@example.com', 'invalid' => 'fööbar@example.com', @@ -58,15 +67,6 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case 'taken' => array('email'), 'banned' => array('email'), 'no_mx' => array('email'), - ), - array( - 'empty' => array(), - 'allowed' => array(), - 'invalid' => array('EMAIL_INVALID'), - 'valid_complex' => array(), - 'taken' => array('EMAIL_TAKEN'), - 'banned' => array('EMAIL_BANNED'), - 'no_mx' => array('DOMAIN_NO_MX_RECORD'), )); } } -- cgit v1.2.1 From 11678678b810c26376728166cf334550cbc30124 Mon Sep 17 00:00:00 2001 From: Marc Alexander <admin@m-a-styles.de> Date: Mon, 3 Jun 2013 21:30:13 +0200 Subject: [ticket/11579] Rework calls to validate_data_helper PHPBB3-11579 --- tests/functions/validate_email_test.php | 62 +++++++++++++++++++-------------- 1 file changed, 36 insertions(+), 26 deletions(-) (limited to 'tests/functions/validate_email_test.php') diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php index 2e81d3277e..93b5ba0896 100644 --- a/tests/functions/validate_email_test.php +++ b/tests/functions/validate_email_test.php @@ -41,32 +41,42 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $user = $this->user; $user->optionset('banned_users', array('banned@example.com')); - $this->helper->assert_validate_data(array( - 'empty' => array(), - 'allowed' => array(), - 'invalid' => array('EMAIL_INVALID'), - 'valid_complex' => array(), - 'taken' => array('EMAIL_TAKEN'), - 'banned' => array('EMAIL_BANNED'), - 'no_mx' => array('DOMAIN_NO_MX_RECORD'), - ), - array( - 'empty' => '', - 'allowed' => 'foobar@example.com', - 'invalid' => 'fööbar@example.com', - 'valid_complex' => "'%$~test@example.com", - 'taken' => 'admin@example.com', - 'banned' => 'banned@example.com', - 'no_mx' => 'test@wwrrrhhghgghgh.ttv', - ), - array( - 'empty' => array('email'), - 'allowed' => array('email', 'foobar@example.com'), - 'invalid' => array('email'), - 'valid_complex' => array('email'), - 'taken' => array('email'), - 'banned' => array('email'), - 'no_mx' => array('email'), + $this->helper->assert_valid_data(array( + 'empty' => array( + array(), + '', + array('email'), + ), + 'allowed' => array( + array(), + 'foobar@example.com', + array('email', 'foobar@example.com'), + ), + 'invalid' => array( + array('EMAIL_INVALID'), + 'fööbar@example.com', + array('email'), + ), + 'valid_complex' => array( + array(), + "'%$~test@example.com", + array('email'), + ), + 'taken' => array( + array('EMAIL_TAKEN'), + 'admin@example.com', + array('email'), + ), + 'banned' => array( + array('EMAIL_BANNED'), + 'banned@example.com', + array('email'), + ), + 'no_mx' => array( + array('DOMAIN_NO_MX_RECORD'), + 'test@wwrrrhhghgghgh.ttv', + array('email'), + ), )); } } -- cgit v1.2.1 From c6ba894acdfdf5b0800dc3903d01605ddd83e8e9 Mon Sep 17 00:00:00 2001 From: Marc Alexander <admin@m-a-styles.de> Date: Wed, 5 Jun 2013 17:36:20 +0200 Subject: [ticket/11579] Add method for validating emails for valid MX and mark as slow A method for setting up the prerequisities also has been added in order to reduce the amount of necessary code. PHPBB3-11579 --- tests/functions/validate_email_test.php | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'tests/functions/validate_email_test.php') diff --git a/tests/functions/validate_email_test.php b/tests/functions/validate_email_test.php index 93b5ba0896..9a6ce39251 100644 --- a/tests/functions/validate_email_test.php +++ b/tests/functions/validate_email_test.php @@ -32,14 +32,24 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case $this->helper = new phpbb_functions_validate_data_helper($this); } - public function test_validate_email() + /** + * Get validation prerequesites + * + * @param bool $check_mx Whether mx records should be checked + */ + protected function set_validation_prerequisites($check_mx) { global $config, $db, $user; - $config['email_check_mx'] = true; + $config['email_check_mx'] = $check_mx; $db = $this->db; $user = $this->user; $user->optionset('banned_users', array('banned@example.com')); + } + + public function test_validate_email() + { + $this->set_validation_prerequisites(false); $this->helper->assert_valid_data(array( 'empty' => array( @@ -72,9 +82,25 @@ class phpbb_functions_validate_email_test extends phpbb_database_test_case 'banned@example.com', array('email'), ), + )); + } + + /** + * @group slow + */ + public function test_validate_email_mx() + { + $this->set_validation_prerequisites(true); + + $this->helper->assert_valid_data(array( + 'valid' => array( + array(), + 'foobar@phpbb.com', + array('email'), + ), 'no_mx' => array( array('DOMAIN_NO_MX_RECORD'), - 'test@wwrrrhhghgghgh.ttv', + 'test@does-not-exist.phpbb.com', array('email'), ), )); -- cgit v1.2.1