Skip to content

Commit

Permalink
2016-07-31 AC: Adds tests for the modSimpleEmailForm::main() method. …
Browse files Browse the repository at this point in the history
…Contributes to resolve issue #9.
  • Loading branch information
andrewscaya committed Aug 1, 2016
1 parent a8c8b30 commit 7778c97
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -3,4 +3,4 @@ Joomla Simple Email Form Module

[![Build Status](https://travis-ci.org/andrewscaya/mod_simpleemailform.svg?branch=master)](https://travis-ci.org/andrewscaya/mod_simpleemailform)

Code Coverage: 56.07% covered.
Code Coverage: 61.68% covered.
4 changes: 2 additions & 2 deletions helper.php
Expand Up @@ -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 @@ -324,7 +324,7 @@ public function __construct($params)
$this->_csrfField = $this->_fieldPrefix . '_oneTime_' . $this->_instance;
}

// Code coverage will be ignored as this part of the code is tested by phpt files.
// Code coverage - this part of the code will be ignored since it is tested by phpt files.
/**
* @codeCoverageIgnoreStart
*/
Expand Down
78 changes: 77 additions & 1 deletion test/modSimpleEmailFormTest.php
Expand Up @@ -52,6 +52,18 @@ class modSimpleEmailFormTest extends PHPUnit_Framework_TestCase
*/
private $csrfFieldProperty;

/**
*
* @var ReflectionProperty
*/
private $msgProperty;

/**
*
* @var ReflectionProperty
*/
private $testModeProperty;

/**
*
* @var ReflectionMethod
Expand Down Expand Up @@ -150,6 +162,10 @@ protected function tearDown()

$this->csrfFieldProperty = null;

$this->msgProperty = null;

$this->testModeProperty = null;

$this->formatErrorMessageMethod = null;

$this->buildCheckRadioFieldMethod = null;
Expand All @@ -158,6 +174,8 @@ protected function tearDown()

$this->cleanupCaptchasMethod = null;

\Mockery::close();

parent::tearDown();
}

Expand Down Expand Up @@ -763,12 +781,70 @@ protected function setCompareCsrfHashMethodAccessible()
/**
* Tests modSimpleEmailForm::main()
*/
public function testMain()
public function testMainReturnValueWithoutSubmit()
{
$doc = new \DOMDocument();
$doc->loadHTML($this->modSimpleEmailForm->main());
$nodeList = $doc->getElementsByTagName('form');
$this->assertEquals(1, count($nodeList));
$this->assertEquals('post', $nodeList->item(0)->getAttributeNode('method')->value);
}

/**
* Tests modSimpleEmailForm::main()
*/
public function testMainReturnValueWithSubmit()
{
$this->setCsrfFieldPropertyAccessible();
$csrfFieldValue = $this->csrfFieldProperty->getValue($this->modSimpleEmailForm);

$this->setMsgPropertyAccessible();
$msgValue = $this->msgProperty->getValue($this->modSimpleEmailForm);

$_POST['mod_simpleemailform_submit_1'] = true;
$_POST[$csrfFieldValue] = 'test';
$_SESSION[$csrfFieldValue] = 'test';

$this->modSimpleEmailForm->main();

/* @todo assertions */
}

/**
* Tests modSimpleEmailForm::main()
*/
public function testMainTestModeFalse()
{
$this->setTestModePropertyAccessible();

ini_set('display_errors', 0);
$this->testModeProperty->setValue($this->modSimpleEmailForm, 'N');
$this->modSimpleEmailForm->main();
$this->assertSame('0', ini_get('display_errors'));
}

/**
* Tests modSimpleEmailForm::main()
*/
public function testMainTestModeTrue()
{
$this->setTestModePropertyAccessible();

ini_set('display_errors', 0);
$this->testModeProperty->setValue($this->modSimpleEmailForm, 'Y');
$this->modSimpleEmailForm->main();
$this->assertSame('1', ini_get('display_errors'));
}

protected function setMsgPropertyAccessible()
{
$this->msgProperty = $this->modSimpleEmailFormReflection->getProperty('_msg');
$this->msgProperty->setAccessible(true);
}

protected function setTestModePropertyAccessible()
{
$this->testModeProperty = $this->modSimpleEmailFormReflection->getProperty('_testMode');
$this->testModeProperty->setAccessible(true);
}
}

0 comments on commit 7778c97

Please sign in to comment.