-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added test coverage for contact form
- Loading branch information
Showing
2 changed files
with
152 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,40 @@ | ||
<?php | ||
error_reporting(E_ALL); | ||
session_start(); | ||
|
||
/* Classes importeren */ | ||
include('Classes/User.php'); | ||
include('Classes/Template.php'); | ||
|
||
/* Includes importeren */ | ||
include('Includes/slashes.php'); | ||
include('Includes/connect.php'); | ||
|
||
/* Verbinding met database maken */ | ||
connectDB(); | ||
|
||
/*Classes initialiseren */ | ||
$cUser = new User(); | ||
$cTPL = new Template('Templates/main.tpl'); | ||
|
||
/* Pagina goed weergeven */ | ||
include('Includes/login.php'); | ||
|
||
/* Controleren of het formulier is verzonden */ | ||
if(isset($_POST['titel'])) | ||
{ | ||
$sQuery = "INSERT INTO mail (mailid, titel, bericht, email, gelezen) | ||
VALUES ('', '" . add($_POST['titel']) . "', '" . add($_POST['bericht']) . "', | ||
'" . add($_POST['email']) . "', 0);"; | ||
if(mysql_query($sQuery)) | ||
{ | ||
$cTPL -> setPlace('TITEL', 'Email verzonden'); | ||
$cTPL -> setPlace('CONTENT', 'Je email is met succes verzonden. Wij proberen zo snel mogelijk reactie te geven'); | ||
} | ||
else | ||
{ | ||
$cTPL -> setPlace('TITEL', 'Fout met database'); | ||
$cTPL -> setPlace('CONTENT', 'Door een fout met de database is je email niet verzonden.'); | ||
} | ||
} | ||
else | ||
{ | ||
$cTPL -> setPlace('TITEL', 'Contact'); | ||
$cTPL -> setFile('CONTENT', 'Templates/contact.tpl'); | ||
} | ||
|
||
$cTPL -> show(); | ||
?> | ||
<?php | ||
error_reporting(E_ALL & ~E_DEPRECATED); | ||
session_start(); | ||
|
||
/* Classes importeren */ | ||
include_once('Classes/User.php'); | ||
include_once('Classes/Template.php'); | ||
|
||
/* Includes importeren */ | ||
include_once('Includes/slashes.php'); | ||
include_once('Includes/connect.php'); | ||
|
||
/* Verbinding met database maken */ | ||
connectDB(); | ||
|
||
/*Classes initialiseren */ | ||
$cUser = new User(); | ||
$cTPL = new Template('Templates/main.tpl'); | ||
|
||
/* Pagina goed weergeven */ | ||
include('Includes/login.php'); | ||
|
||
/* Controleren of het formulier is verzonden */ | ||
if (isset($_POST['titel'])) { | ||
$sQuery = "INSERT INTO mail (mailid, titel, bericht, email, gelezen) | ||
VALUES ('', '" . add($_POST['titel']) . "', '" . add($_POST['bericht']) . "', | ||
'" . add($_POST['email']) . "', 0);"; | ||
if (mysql_query($sQuery)) { | ||
$cTPL->setPlace('TITEL', 'Email verzonden'); | ||
$cTPL->setPlace('CONTENT', 'Je email is met succes verzonden. Wij proberen zo snel mogelijk reactie te geven'); | ||
} else { | ||
$cTPL->setPlace('TITEL', 'Fout met database'); | ||
$cTPL->setPlace('CONTENT', 'Door een fout met de database is je email niet verzonden.'); | ||
} | ||
} else { | ||
$cTPL->setPlace('TITEL', 'Contact'); | ||
$cTPL->setFile('CONTENT', 'Templates/contact.tpl'); | ||
} | ||
|
||
$cTPL->show(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?php | ||
|
||
namespace Tests\Pages; | ||
|
||
use Tests\TestCase; | ||
|
||
class ContactTest extends TestCase | ||
{ | ||
/** @test */ | ||
public function it_shows_contact_form() | ||
{ | ||
$page = $this->visitPage(__DIR__ . '/../../contact.php'); | ||
|
||
$this->assertContains( | ||
'Let op: ALs je een vraag hebt, zet er dan een email adres bij. Anders kunnen wij niet antwoorden:', | ||
$page | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_stores_a_valid_email() | ||
{ | ||
$page = $this->visitPage( | ||
__DIR__ . '/../../contact.php', | ||
[], | ||
[ | ||
'titel' => 'Hello!', | ||
'email' => '[email protected]', | ||
'bericht' => 'Hello, from me!' | ||
] | ||
); | ||
|
||
$this->assertContains('Email verzonden', $page); | ||
$this->assertDatabaseHas('mail', [ | ||
'titel' => 'Hello!', | ||
'email' => '[email protected]', | ||
'bericht' => 'Hello, from me!', | ||
'gelezen' => 0 | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_contact_form_when_no_title_was_provided() | ||
{ | ||
$page = $this->visitPage( | ||
__DIR__ . '/../../contact.php', | ||
[], | ||
[ | ||
'email' => '[email protected]', | ||
'bericht' => 'Hello, from me!' | ||
] | ||
); | ||
|
||
$this->assertContains( | ||
'Let op: ALs je een vraag hebt, zet er dan een email adres bij. Anders kunnen wij niet antwoorden:', | ||
$page | ||
); | ||
$this->assertDatabaseMissing('mail', [ | ||
'titel' => '', | ||
'email' => '[email protected]', | ||
'bericht' => 'Hello, from me!', | ||
'gelezen' => 0 | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_contact_form_when_no_email_was_provided() | ||
{ | ||
$page = $this->visitPage( | ||
__DIR__ . '/../../contact.php', | ||
[], | ||
[ | ||
'titel' => 'Hello!', | ||
'bericht' => 'Hello, from me!' | ||
] | ||
); | ||
|
||
$this->assertContains( | ||
'Let op: ALs je een vraag hebt, zet er dan een email adres bij. Anders kunnen wij niet antwoorden:', | ||
$page | ||
); | ||
$this->assertDatabaseMissing('mail', [ | ||
'titel' => 'Hello!', | ||
'bericht' => 'Hello, from me!', | ||
'gelezen' => 0 | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_contact_form_when_no_body_was_provided() | ||
{ | ||
$page = $this->visitPage( | ||
__DIR__ . '/../../contact.php', | ||
[], | ||
[ | ||
'titel' => 'Hello!', | ||
'email' => '[email protected]' | ||
] | ||
); | ||
|
||
$this->assertContains( | ||
'Let op: ALs je een vraag hebt, zet er dan een email adres bij. Anders kunnen wij niet antwoorden:', | ||
$page | ||
); | ||
$this->assertDatabaseMissing('mail', [ | ||
'titel' => 'Hello!', | ||
'email' => '[email protected]', | ||
'bericht' => '', | ||
'gelezen' => 0 | ||
]); | ||
} | ||
} |