Skip to content

Commit

Permalink
2016-07-25 AC: Makes the code more PSR2 compliant.
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewscaya committed Jul 26, 2016
1 parent 72eb54c commit 0652e54
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 46 deletions.
20 changes: 10 additions & 10 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod_simpleEmailForm.php
Copyright 2010 - 2016 D. Bierer <doug@unlikelysource.com>
Version 1.8.9
Version 1.8.9
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand All @@ -24,7 +24,7 @@
* fixed error where session 1 time hash key not set 1st time generates notice
* fixed bug whereby page not found was generated after form posting; removed "#" as default "anchor" tag
* see: http://joomla.stackexchange.com/questions/16051/fix-the-invalid-address-error-after-upgrading-to-joomla-3-5-1
* @TODO: convert to JForm
* @TODO: convert to JForm
*/

class _SimpleEmailForm
Expand Down Expand Up @@ -864,7 +864,7 @@ public static function isEmailAddress($email)
$domain_array = explode(".", rtrim($domain, '.'));
$regex = '/^[A-Za-z0-9-]{0,63}$/';
foreach ($domain_array as $domain) {
// Must be something
// Must be something
if (!$domain) {
return false;
}
Expand Down Expand Up @@ -1035,13 +1035,13 @@ protected function buildFileUploadField($fieldNum = 1)
{
$inputClass = $this->_inputClass . '_upload';
return "<br />"
. "<input "
. "type=file "
. "name='mod_simpleemailform_upload_" . $fieldNum . '_' . $this->_instance . "' "
. "id='mod_simpleemailform_upload_" . $fieldNum . '_' . $this->_instance . "' "
. "enctype='multipart/form-data' "
. "class='" . $inputClass . "'"
. " />";
. "<input "
. "type=file "
. "name='mod_simpleemailform_upload_" . $fieldNum . '_' . $this->_instance . "' "
. "id='mod_simpleemailform_upload_" . $fieldNum . '_' . $this->_instance . "' "
. "enctype='multipart/form-data' "
. "class='" . $inputClass . "'"
. " />";
}

// 2015-04-23 DB: builds 1 time hash + stores in $_SESSION
Expand Down
72 changes: 36 additions & 36 deletions test/modSimpleEmailFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class modSimpleEmailFormTest extends PHPUnit_Framework_TestCase
* @var ReflectionProperty
*/
private $fieldPrefixProperty;

/**
*
* @var ReflectionProperty
Expand All @@ -63,13 +63,13 @@ class modSimpleEmailFormTest extends PHPUnit_Framework_TestCase
* @var ReflectionMethod
*/
private $buildCheckRadioFieldMethod;

/**
*
* @var ReflectionMethod
*/
private $renderCaptchaMethod;

/**
*
* @var ReflectionMethod
Expand Down Expand Up @@ -364,7 +364,7 @@ public function testTextCaptcha($captchaLen)
$match = '';
$output = $this->modSimpleEmailForm->textCaptcha('white', $captchaLen, 1, 'red', 1, $textCaptcha);
$this->assertEquals($captchaLen, strlen($output));

//@todo This part depends on styling being implemented in modSimpleEmailForm::textCaptcha
//$doc = new \DOMDocument();
//$doc->loadHTML($output);
Expand Down Expand Up @@ -393,31 +393,31 @@ public function providerTestTextCaptcha()
),
);
}

/**
* Tests modSimpleEmailForm::FormatErrorMessage()
*/

/**
* @param string we expect to be returned by formatErrorMessage
* @param string representing the color sent as an argument to formatErrorMessage
* @param string representing the message sent as an argument to formatErrorMessage
* @param string representing the filename sent as an argument to formatErrorMessage
* @dataProvider providerTestFormatErrorMessage
*/
public function testFormatErrorMessage($expectedResult, $color, $message, $fn = '')
{
$this->setFormatErrorMessageMethodAccessible();

$actualResult = $this->formatErrorMessageMethod->invokeArgs(
$this->modSimpleEmailForm,
array($color, $message, $fn)
);
);

$this->assertSame($expectedResult, $actualResult);
}

public function providerTestFormatErrorMessage()
{
return array(
Expand All @@ -435,7 +435,7 @@ public function providerTestFormatErrorMessage()
//array(<p><b><span style='color:$this->color;'>$this->standardMessage
// ('Warning - Invalid filename: no alnum character')</span></b></p>\n",
// $this->color, $this->standardMessage, $this->emptyFn),

//Three tests to check the behaviour with messages
//Test 4: Null message - to be replaced by the commented test below
array("<p><b><span style='color:$this->color;'>$this->nullMessage ($this->standardFn)</span></b></p>\n",
Expand All @@ -458,7 +458,7 @@ public function providerTestFormatErrorMessage()
//If it's not, all previous tests will fail.
);
}

protected function setFormatErrorMessageMethodAccessible()
{
$this->formatErrorMessageMethod = $this->modSimpleEmailFormReflection->getMethod('formatErrorMessage');
Expand Down Expand Up @@ -606,66 +606,66 @@ public function getLocalGreaterThan64()

return (string) $address;
}

/**
* Tests modSimpleEmailForm::renderCaptcha()
*/
public function testRenderCaptcha()
{
$this->setRenderCaptchaMethodAccessible();

$_SERVER['REMOTE_ADDR'] = '127.0.0.1';

$output = $this->renderCaptchaMethod->invokeArgs(
$this->modSimpleEmailForm,
array()
);

$doc = new \DOMDocument();
$doc->loadHTML($output);
$captchaInputNode = $doc->getElementsByTagName('input')->item(0);
$this->assertSame('mod_simpleemailform_captcha_1', $captchaInputNode->getAttributeNode('name')->value);
}

protected function setRenderCaptchaMethodAccessible()
{
$this->renderCaptchaMethod = $this->modSimpleEmailFormReflection->getMethod('renderCaptcha');
$this->renderCaptchaMethod->setAccessible(true);
}

/**
* Tests modSimpleEmailForm::cleanupCaptchas()
*/
public function testCleanupCaptchas()
{
$this->setCleanupCaptchasMethodAccessible();

$_SERVER['HTTP_HOST'] = 'localhost';

$output = $this->cleanupCaptchasMethod->invokeArgs(
$this->modSimpleEmailForm,
array()
);

$doc = new \DOMDocument();
$doc->loadHTML($output);
$spanNode = $doc->getElementsByTagName('span')->item(0);
$this->assertSame('Unable to cleanup old CAPTCHAs', $spanNode->nodeValue);
}

protected function setCleanupCaptchasMethodAccessible()
{
$this->cleanupCaptchasMethod = $this->modSimpleEmailFormReflection->getMethod('cleanupCaptchas');
$this->cleanupCaptchasMethod->setAccessible(true);
}

/**
* Tests modSimpleEmailForm::compareCsrfHash()
*
*
* @param bool representing the expected result
*
*
* @param string representing the form's CSRF
*
*
* @param string representing the session's CSRF
*
* @dataProvider providerTestCompareCsrfHash
Expand All @@ -674,30 +674,30 @@ public function testCompareCsrfHash($expected, $formCsrf, $formSess)
{
$this->setCsrfFieldPropertyAccessible();
$this->setCompareCsrfHashMethodAccessible();

$csrfFieldValue = $this->csrfFieldProperty->getValue($this->modSimpleEmailForm);

$_POST[$csrfFieldValue] = $formCsrf;

$_SESSION[$csrfFieldValue] = $formSess;

$output = $this->compareCsrfHashMethod->invokeArgs(
$this->modSimpleEmailForm,
array()
);

if ($expected) {
$this->assertTrue($output);
} else {
$this->assertFalse($output);
}
}

public function providerTestCompareCsrfHash()
{
$string1 = substr(str_shuffle(MD5(microtime())), 0, 10);
$string2 = substr(str_shuffle(MD5(microtime())), 0, 10);

return array(
array(
true, $string1, $string1
Expand All @@ -710,13 +710,13 @@ public function providerTestCompareCsrfHash()
),
);
}

protected function setCsrfFieldPropertyAccessible()
{
$this->csrfFieldProperty = $this->modSimpleEmailFormReflection->getProperty('_csrfField');
$this->csrfFieldProperty->setAccessible(true);
}

protected function setCompareCsrfHashMethodAccessible()
{
$this->compareCsrfHashMethod = $this->modSimpleEmailFormReflection->getMethod('compareCsrfHash');
Expand Down

0 comments on commit 0652e54

Please sign in to comment.