Skip to content

Commit

Permalink
2016-07-14 AC: Completes unit tests for the modSimpleEmailForm::Forma…
Browse files Browse the repository at this point in the history
…tErrorMessage() method. Contributes to resolve issue #9.
  • Loading branch information
andrewscaya committed Jul 26, 2016
1 parent cd422a9 commit 9f9bd5b
Showing 1 changed file with 166 additions and 60 deletions.
226 changes: 166 additions & 60 deletions test/modSimpleEmailFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,37 @@ class modSimpleEmailFormTest extends PHPUnit_Framework_TestCase
*/
private $modSimpleEmailForm;

public $object;
/**
*
* @var modSimpleEmailForm
*/
private $modSimpleEmailFormReflection;

/**
* Color argument
*
* @var color
*/
protected $color = 'red';

/**
* Message argument
*
* @var standardMessage
*/
protected $standardMessage = 'This is a test';
protected $nullMessage = null;
protected $emptyMessage = ' ';

//
/**
* Filename argument
*
* @var fn
*/
protected $fn = 'test.php';
protected $fnNull = null;
protected $fnSpace = ' ';

/**
* Prepares the environment before running a test.
Expand All @@ -27,6 +57,10 @@ protected function setUp()
$message = '';

$this->modSimpleEmailForm = new modSimpleEmailForm($params);

$this->modSimpleEmailFormReflection = new \ReflectionClass($this->modSimpleEmailForm);
$this->formatErrorMessageMethod = $this->modSimpleEmailFormReflection->getMethod('formatErrorMessage');
$this->formatErrorMessageMethod->setAccessible(true);
}

/**
Expand All @@ -36,6 +70,8 @@ protected function tearDown()
{
$this->modSimpleEmailForm = null;

$this->modSimpleEmailFormReflection = null;

parent::tearDown();
}

Expand Down Expand Up @@ -112,68 +148,138 @@ public function testAllPhptFiles()
// modSimpleEmailForm::isEmailAddress(/* parameters */);
// }

//Three tests to check the function's behaviour with filenames
/**
* Tests modSimpleEmailForm::FormatErrorMessage()
*/
public function testFormatErrorMessageNoFn()
{
$message = $this->formatErrorMessageMethod->invokeArgs(
$this->modSimpleEmailForm,
array($this->color, $this->standardMessage)
);
$this->assertSame(
"<p><b><span style='color:$this->color;'>$this->standardMessage</span></b></p>\n",
$message
);
}

/**
* Tests modSimpleEmailForm::FormatErrorMessage()
*/
public function testFormatErrorMessageWithFn()
{
$message = $this->formatErrorMessageMethod->invokeArgs(
$this->modSimpleEmailForm,
array($this->color, $this->standardMessage, $this->fn)
);
$this->assertSame(
"<p><b><span style='color:$this->color;'>$this->standardMessage ($this->fn)</span></b></p>\n",
$message
);
}

/**
* Tests modSimpleEmailForm::FormatErrorMessage()
*/
public function testFormatErrorMessageInvalidFn()
{
$message = $this->formatErrorMessageMethod->invokeArgs(
$this->modSimpleEmailForm,
array($this->color, $this->standardMessage, $this->fnSpace)
);
// @todo
// $this->assertSame(
// "<p><b><span style='color:$this->color;'>$this->standardMessage('Warning - Invalid filename: no alnum character')</span></b></p>\n",
// $message
// );

$this->assertSame(
"<p><b><span style='color:$this->color;'>$this->standardMessage ( )</span></b></p>\n",
$message
);
}

//Three tests to ckeck the function's behaviour with messages
/**
* Tests modSimpleEmailForm::FormatErrorMessage()
*/
public function testFormatErrornullMessageMessage()
{
$message = $this->formatErrorMessageMethod->invokeArgs(
$this->modSimpleEmailForm,
array($this->color, $this->nullMessage, $this->fn)
);
// @todo
// $this->assertSame(
// "<p><b><span style='color:$this->color;'>$this->standardMessage('Warning - Invalid filename: no alnum character')</span></b></p>\n",
// $message
// );

$this->assertSame(
"<p><b><span style='color:$this->color;'>$this->nullMessage ($this->fn)</span></b></p>\n",
$message
);
}

/**
* Tests modSimpleEmailForm::FormatErrorMessage()
*/
public function testFormatErrorMessageSpaceMessage()
{
$message = $this->formatErrorMessageMethod->invokeArgs(
$this->modSimpleEmailForm,
array($this->color, $this->emptyMessage, $this->fn)
);
// @todo
// $this->assertSame(
// "<p><b><span style='color:$this->color;'>$this->standardMessage('Warning - Invalid filename: no alnum character')</span></b></p>\n",
// $message
// );

$this->assertSame(
"<p><b><span style='color:$this->color;'>$this->emptyMessage ($this->fn)</span></b></p>\n",
$message
);
}

/**
* formatErrorMessage
*/

//Argument for color
protected $color = "red";

//Arguments for message
protected $standardMessage = "This is a test";
protected $messageNull = null;
protected $emptyMessage = " ";

//Arguments for filename
protected $fn = "test.php";
protected $fnNull = null;
protected $fnSpace = " ";

//Three tests to ckeck the function's behaviour with filenames
public function testFormatErrorMessageNoFn () {
$message = formatErrorMessage($this->color, $this->standardMessage);
$this->assertSame("<p><b><span style='color:$this->color;'>$this->standardMessage</span></b></p>\n", $message);
}

public function testFormatErrorMessageWithFn () {
$message = formatErrorMessage($this->color, $this->standardMessage, $this->fn);
$this->assertSame("<p><b><span style='color:$this->color;'>$this->standardMessage ($fn)</span></b></p>\n", $message);
}

public function testFormatErrorMessageInvalidFn () {
$message = formatErrorMessage($this->color, $this->standardMessage, $this->fnSpace);
$this->assertSame("<p><b><span style='color:$this->color;'>$this->standardMessage
('Warning - Invalid filename: no alnum character')</span></b></p>\n", $message);
}

//Three tests to ckeck the function's behaviour with messages
public function testFormatErrorMessageNullMessage () {
$message = formatErrorMessage($this->color, $this->messageNull, $this->fn);
$this->assertSame("<p><b><span style='color:$this->color;'>$this->standardMessage
('Warning - Invalid filename: no alnum character')</span></b></p>\n", $messagee);
}

public function testFormatErrorMessageSpaceMessage () {
$message = formatErrorMessage($this->color, $this->emptyMessage, $this->fn);
$this->assertSame("<p><b><span style='color:$this->color;'>$this->standardMessage
('Warning - Invalid filename: no alnum character')</span></b></p>\n", $message);
}

public function testFormatErrorMessageRealMessage () {
$message = formatErrorMessage($this->color, $this->standardMessage, $this->fn);
$this->assertSame("<p><b><span style='color:$this->color;'>$this->standardMessage
($this->fn)</span></b></p>\n", $message);
}

//Only important thing with color is that the value is put in its
//rightful place. Html is valid no matter what the value is.
public function testFormatErrorMessageColor () {
$message = formatErrorMessage($this->color, $this->standardMessage, $this->fn);
$this->assertSame("<p><b><span style='color:$this->color;'>$this->standardMessage
($this->fn)</span></b></p>\n", $message);
* Tests modSimpleEmailForm::FormatErrorMessage()
*/
public function testFormatErrorMessageRealMessage()
{
$message = $this->formatErrorMessageMethod->invokeArgs(
$this->modSimpleEmailForm,
array($this->color, $this->standardMessage, $this->fn)
);
$this->assertSame(
"<p><b><span style='color:$this->color;'>$this->standardMessage ($this->fn)</span></b></p>\n",
$message
);
}

/*
* Only important thing with color is that the value is put in its
* rightful place. Html is valid no matter what the value is.
*/

/**
* Tests modSimpleEmailForm::FormatErrorMessage()
*/
public function testFormatErrorMessageColor()
{
$message = $this->formatErrorMessageMethod->invokeArgs(
$this->modSimpleEmailForm,
array($this->color, $this->standardMessage, $this->fn)
);
$this->assertSame(
"<p><b><span style='color:$this->color;'>$this->standardMessage ($this->fn)</span></b></p>\n",
$message
);
}

/**
* Tests modSimpleEmailForm->main()
* Tests modSimpleEmailForm::main()
*/
public function testMain()
{
Expand Down

0 comments on commit 9f9bd5b

Please sign in to comment.