-
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 add game comment page
- Loading branch information
Showing
2 changed files
with
272 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,37 @@ | ||
<?php | ||
error_reporting(E_ALL); | ||
|
||
session_start(); | ||
|
||
/* Classes importeren */ | ||
include('Classes/User.php'); | ||
include('Classes/Template.php'); | ||
|
||
/* Includes importeren */ | ||
include('Includes/connect.php'); | ||
include('Includes/slashes.php'); | ||
|
||
/* Classes initialiseren */ | ||
$cUser = new User(); | ||
|
||
/* Verbinden met mysql */ | ||
connectDB(); | ||
|
||
/* Permissies controleren */ | ||
if((isset($_GET['topicid'])) && (isset($_POST['reactie'])) && (isset($_GET['id']))) | ||
{ | ||
if(($cUser -> checkSession()) || ($cUser -> checkCookie())) | ||
{ | ||
$sQuery = "INSERT INTO berichten (berichtid, topicid, userid, bericht, datum, tijd) | ||
VALUES ('', '" . add($_GET['topicid']) . "', '" . $cUser -> m_iUserid . "', | ||
'" . add($_POST['reactie']) . "', NOW(), NOW());"; | ||
if(mysql_query($sQuery)) | ||
{ | ||
$cUser -> addPost(); | ||
header('Location: gameview.php?id=' . $_GET['id'] . '&topicid=' . $_GET['topicid']); | ||
} | ||
else | ||
{ | ||
Print 'Er is iets niet in orde met de database'; | ||
} | ||
} | ||
else | ||
{ | ||
header('Location: loginForm.php'); | ||
} | ||
} | ||
else | ||
{ | ||
header('HTTP/1.0 404 Page not Found'); | ||
} | ||
?> | ||
<?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/connect.php'); | ||
include_once('Includes/slashes.php'); | ||
|
||
/* Classes initialiseren */ | ||
$cUser = new User(); | ||
|
||
/* Verbinden met mysql */ | ||
connectDB(); | ||
|
||
/* Permissies controleren */ | ||
if ((isset($_GET['topicid'])) && (isset($_POST['reactie'])) && (isset($_GET['id']))) { | ||
if (($cUser->checkSession()) || ($cUser->checkCookie())) { | ||
$sQuery = "INSERT INTO berichten (berichtid, topicid, userid, bericht, datum, tijd) | ||
VALUES ('', '" . add($_GET['topicid']) . "', '" . $cUser->m_iUserid . "', | ||
'" . add($_POST['reactie']) . "', NOW(), NOW());"; | ||
if (mysql_query($sQuery)) { | ||
$cUser->addPost(); | ||
header('Location: gameview.php?id=' . $_GET['id'] . '&topicid=' . $_GET['topicid']); | ||
} else { | ||
print 'Er is iets niet in orde met de database'; | ||
} | ||
} else { | ||
header('Location: loginForm.php'); | ||
} | ||
} else { | ||
header('HTTP/1.0 404 Page not Found'); | ||
} |
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,235 @@ | ||
<?php | ||
|
||
namespace Tests\Pages; | ||
|
||
use Tests\Factories\ConsoleFactory; | ||
use Tests\Factories\GameFactory; | ||
use Tests\Factories\TopicFactory; | ||
use Tests\TestCase; | ||
|
||
class AddGameCommentTest extends TestCase | ||
{ | ||
private $userId; | ||
private $consoleId; | ||
private $gameId; | ||
private $topicId; | ||
|
||
protected function setUp() | ||
{ | ||
parent::setUp(); | ||
|
||
$this->userId = $this->login(); | ||
|
||
$this->consoleId = ConsoleFactory::create(self::$pdo, 'Xbox'); | ||
|
||
$this->gameId = GameFactory::create( | ||
self::$pdo, | ||
$this->consoleId, | ||
'Halo', | ||
'halo', | ||
'Developer', | ||
'Publisher', | ||
'http://developer.com', | ||
'http://publisher.com' | ||
); | ||
|
||
$this->topicId = TopicFactory::create( | ||
self::$pdo, | ||
$this->userId, | ||
'Review', | ||
'It is a really nice game!' | ||
); | ||
TopicFactory::attach( | ||
self::$pdo, | ||
$this->topicId, | ||
$this->gameId | ||
); | ||
} | ||
|
||
/** @test */ | ||
public function it_adds_a_game_comment_for_a_logged_in_user() | ||
{ | ||
$page = $this->visitPage( | ||
__DIR__ . '/../../addpost.php', | ||
[ | ||
'id' => $this->gameId, | ||
'topicid' => $this->topicId | ||
], | ||
[ | ||
'reactie' => 'Really good game!' | ||
] | ||
); | ||
|
||
$this->assertEquals('', $page); | ||
$this->assertDatabaseHas('berichten', [ | ||
'topicid' => $this->topicId, | ||
'userid' => $this->userId, | ||
'bericht' => 'Really good game!' | ||
]); | ||
$this->assertDatabaseHas('users', [ | ||
'username' => 'Mark', | ||
'posts' => 1 | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_404_when_game_id_is_missing() | ||
{ | ||
$page = $this->visitPage( | ||
__DIR__ . '/../../addpost.php', | ||
[ | ||
'topicid' => $this->topicId | ||
], | ||
[ | ||
'reactie' => 'Really good game!' | ||
] | ||
); | ||
|
||
$this->assertEquals('', $page); | ||
$this->assertDatabaseMissing('berichten', [ | ||
'topicid' => $this->topicId, | ||
'userid' => $this->userId, | ||
'bericht' => 'Really good game!' | ||
]); | ||
$this->assertDatabaseHas('users', [ | ||
'username' => 'Mark', | ||
'posts' => 0 | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_404_when_topic_id_is_missing() | ||
{ | ||
$page = $this->visitPage( | ||
__DIR__ . '/../../addpost.php', | ||
[ | ||
'id' => $this->gameId | ||
], | ||
[ | ||
'reactie' => 'Really good game!' | ||
] | ||
); | ||
|
||
$this->assertEquals('', $page); | ||
$this->assertDatabaseMissing('berichten', [ | ||
'topicid' => $this->topicId, | ||
'userid' => $this->userId, | ||
'bericht' => 'Really good game!' | ||
]); | ||
$this->assertDatabaseHas('users', [ | ||
'username' => 'Mark', | ||
'posts' => 0 | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_404_when_topic_doesnt_exist() | ||
{ | ||
$page = $this->visitPage( | ||
__DIR__ . '/../../addpost.php', | ||
[ | ||
'id' => $this->gameId, | ||
'topicid' => 999 | ||
], | ||
[ | ||
'reactie' => 'Really good game!' | ||
] | ||
); | ||
|
||
$this->assertEquals('', $page); | ||
$this->assertDatabaseMissing('berichten', [ | ||
'topicid' => 999, | ||
'userid' => $this->userId, | ||
'bericht' => 'Really good game!' | ||
]); | ||
$this->assertDatabaseHas('users', [ | ||
'username' => 'Mark', | ||
'posts' => 0 | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_404_when_topic_doesnt_exist_for_game() | ||
{ | ||
$newTopicId = TopicFactory::create( | ||
self::$pdo, | ||
$this->userId, | ||
'Different topic', | ||
'The content of the different topic' | ||
); | ||
|
||
$page = $this->visitPage( | ||
__DIR__ . '/../../addpost.php', | ||
[ | ||
'id' => $this->gameId, | ||
'topicid' => $newTopicId | ||
], | ||
[ | ||
'reactie' => 'Really good game!' | ||
] | ||
); | ||
|
||
$this->assertEquals('', $page); | ||
$this->assertDatabaseMissing('berichten', [ | ||
'topicid' => $newTopicId, | ||
'userid' => $this->userId, | ||
'bericht' => 'Really good game!' | ||
]); | ||
$this->assertDatabaseHas('users', [ | ||
'username' => 'Mark', | ||
'posts' => 0 | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_shows_404_when_comment_data_is_missing() | ||
{ | ||
$page = $this->visitPage( | ||
__DIR__ . '/../../addpost.php', | ||
[ | ||
'id' => $this->gameId, | ||
'topicid' => $this->topicId | ||
], | ||
[] | ||
); | ||
|
||
$this->assertEquals('', $page); | ||
$this->assertDatabaseMissing('berichten', [ | ||
'topicid' => $this->topicId, | ||
'userid' => $this->userId, | ||
'bericht' => '' | ||
]); | ||
$this->assertDatabaseHas('users', [ | ||
'username' => 'Mark', | ||
'posts' => 0 | ||
]); | ||
} | ||
|
||
/** @test */ | ||
public function it_redirects_to_login_when_user_isnt_logged_in() | ||
{ | ||
$this->logout(); | ||
|
||
$page = $this->visitPage( | ||
__DIR__ . '/../../addpost.php', | ||
[ | ||
'id' => $this->gameId, | ||
'topicid' => $this->topicId | ||
], | ||
[ | ||
'reactie' => 'Really good game!' | ||
] | ||
); | ||
|
||
$this->assertEquals('', $page); | ||
$this->assertDatabaseMissing('berichten', [ | ||
'topicid' => $this->topicId, | ||
'userid' => $this->userId, | ||
'bericht' => 'Really good game!' | ||
]); | ||
$this->assertDatabaseHas('users', [ | ||
'username' => 'Mark', | ||
'posts' => 0 | ||
]); | ||
} | ||
} |