From c1d787edf88d8e271da13812dbc5fbd6a02b1764 Mon Sep 17 00:00:00 2001 From: ayushchd Date: Tue, 16 Jul 2013 21:40:53 +0545 Subject: [PATCH 1/6] Move getTagArray to bootstrap --- test/bootstrap-dist.php | 27 ++++ test/libraries/PMA_FormDisplay_tpl_test.php | 132 ++++++++----------- test/libraries/PMA_user_preferences_test.php | 10 +- 3 files changed, 84 insertions(+), 85 deletions(-) diff --git a/test/bootstrap-dist.php b/test/bootstrap-dist.php index 0edf05e329..95cca261bd 100644 --- a/test/bootstrap-dist.php +++ b/test/bootstrap-dist.php @@ -71,4 +71,31 @@ if (PMA_HAS_RUNKIT && $GLOBALS['runkit_internal_override']) { echo "Please install runkit and enable runkit.internal_override!\n"; } +/** + * Return the tag array to be used with assertTag by parsing + * a given HTML element + * + * @param string $elementHTML HTML for element to be parsed + * @param array $arr Additional array elements like content, parent + * + * @return array Tag array to be used with assertTag + */ +function PMA_getTagArray($elementHTML, $arr = array()) +{ + + // get attributes + preg_match_all("/\s+(.*?)\=\s*\"(.*?)\"/is", $elementHTML, $matches); + foreach ($matches[1] as $key => $val) { + $arr['attributes'][trim($val)] = trim($matches[2][$key]); + } + $matches = array(); + + // get tag + preg_match("/^\<(.*?)(\s|\>)/i", $elementHTML, $matches); + if (isset($matches[1])) { + $arr['tag'] = trim($matches[1]); + } + + return $arr; +} ?> diff --git a/test/libraries/PMA_FormDisplay_tpl_test.php b/test/libraries/PMA_FormDisplay_tpl_test.php index c9ddc07b80..371f7c8a7d 100644 --- a/test/libraries/PMA_FormDisplay_tpl_test.php +++ b/test/libraries/PMA_FormDisplay_tpl_test.php @@ -21,34 +21,6 @@ require_once 'libraries/user_preferences.lib.php'; */ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase { - /** - * Return the tag array to be used with assertTag by parsing - * a given HTML element - * - * @param string $elementHTML HTML for element to be parsed - * @param array $arr Additional array elements like content, parent - * - * @return array Tag array to be used with assertTag - */ - private function _getTagArray($elementHTML, $arr = array()) - { - - // get attributes - preg_match_all("/\s+(.*?)\=\s*\"(.*?)\"/is", $elementHTML, $matches); - foreach ($matches[1] as $key => $val) { - $arr['attributes'][trim($val)] = trim($matches[2][$key]); - } - $matches = array(); - - // get tag - preg_match("/^\<(.*?)(\s|\>)/i", $elementHTML, $matches); - if (isset($matches[1])) { - $arr['tag'] = trim($matches[1]); - } - - return $arr; - } - /** * Test for PMA_displayFormTop() * @@ -63,7 +35,7 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase $result = ob_get_clean(); $this->assertTag( - $this->_getTagArray( + PMA_getTagArray( '
' ), @@ -71,14 +43,14 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase ); $this->assertTag( - $this->_getTagArray( + PMA_getTagArray( '' ), $result ); $this->assertTag( - $this->_getTagArray( + PMA_getTagArray( '' ), @@ -86,21 +58,21 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase ); $this->assertTag( - $this->_getTagArray( + PMA_getTagArray( '' ), $result ); $this->assertTag( - $this->_getTagArray( + PMA_getTagArray( '' ), $result ); $this->assertTag( - $this->_getTagArray( + PMA_getTagArray( '' ), $result @@ -119,22 +91,22 @@ class PMA_FormDisplay_Tpl_Test extends PHPUnit_Framework_TestCase $result = ob_get_clean(); $this->assertTag( - $this->_getTagArray('