From d1eea2668b490a336a1054f51c34298971020a69 Mon Sep 17 00:00:00 2001 From: Mark Kazemier Date: Wed, 7 Jul 2021 22:08:23 +0200 Subject: [PATCH] Added tests for links page Enhances test coverage #9 --- links.php | 140 +++++++++++++++----------------- tests/Factories/LinkFactory.php | 20 +++++ tests/Pages/LinksTestTest.php | 23 ++++++ 3 files changed, 108 insertions(+), 75 deletions(-) create mode 100644 tests/Factories/LinkFactory.php create mode 100644 tests/Pages/LinksTestTest.php diff --git a/links.php b/links.php index 3f4e6ef..6d062f6 100644 --- a/links.php +++ b/links.php @@ -1,75 +1,65 @@ - setPlace('TITEL', 'Link partners'); - -/* Controleren of je bent ingelogd en of je admin bent */ -if(($cUser -> checkSession()) || ($cUser -> checkCookie())) -{ - $cTPL -> setBlock('LOGIN', 'logout'); - $cTPL -> setBlock('FORUMLINKS', 'forumingelogd'); - - if(2047 & $cUser -> m_iPermis) - { - $cTPL -> parse(); - $cTPL -> setBlock('ADMIN', 'admin'); - $cTPL -> setBlock('FORUMADMIN', 'forumadmin'); - } -} -else -{ - $cTPL -> setBlock('LOGIN', 'login'); - $cTPL -> parse(); - $cTPL -> setPlace('THISPAGE', $_SERVER['PHP_SELF']); - $cTPL -> setBlock('FORUMLINKS', 'forumnormaal'); -} - -/*De pagina zelf */ -$cTPL -> setFile('CONTENT', 'Templates/links.tpl'); -$cTPL -> parse(); - -$sQuery = "SELECT linkid, link, incomming, outcomming FROM links ORDER BY link;"; -if($cResult = mysql_query($sQuery)) -{ - $sBG = ''; - while($aData = mysql_fetch_assoc($cResult)) - { - if($sBG == '') - { - $sBG = 'img/patroon.gif'; - } - else - { - $sBG = ''; - } - $cTPL -> setBlock('LINK', 'link'); - $cTPL -> parse(); - - $cTPL -> setPlace('ID', $aData['linkid']); - $cTPL -> setPlace('LINKNAAM', $aData['link']); - $cTPL -> setPlace('IN', $aData['incomming']); - $cTPL -> setPlace('UIT', $aData['outcomming']); - $cTPL -> setPlace('BG', $sBG); - $cTPL -> parse(); - } -} - -$cTPL -> show(); -?> \ No newline at end of file +setPlace('TITEL', 'Link partners'); + +/* Controleren of je bent ingelogd en of je admin bent */ +if (($cUser->checkSession()) || ($cUser->checkCookie())) { + $cTPL->setBlock('LOGIN', 'logout'); + $cTPL->setBlock('FORUMLINKS', 'forumingelogd'); + + if (2047 & $cUser->m_iPermis) { + $cTPL->parse(); + $cTPL->setBlock('ADMIN', 'admin'); + $cTPL->setBlock('FORUMADMIN', 'forumadmin'); + } +} else { + $cTPL->setBlock('LOGIN', 'login'); + $cTPL->parse(); + $cTPL->setPlace('THISPAGE', $_SERVER['PHP_SELF']); + $cTPL->setBlock('FORUMLINKS', 'forumnormaal'); +} + +/*De pagina zelf */ +$cTPL->setFile('CONTENT', 'Templates/links.tpl'); +$cTPL->parse(); + +$sQuery = "SELECT linkid, link, incomming, outcomming FROM links ORDER BY link;"; +if ($cResult = mysql_query($sQuery)) { + $sBG = ''; + while ($aData = mysql_fetch_assoc($cResult)) { + if ($sBG == '') { + $sBG = 'img/patroon.gif'; + } else { + $sBG = ''; + } + $cTPL->setBlock('LINK', 'link'); + $cTPL->parse(); + + $cTPL->setPlace('ID', $aData['linkid']); + $cTPL->setPlace('LINKNAAM', $aData['link']); + $cTPL->setPlace('IN', $aData['incomming']); + $cTPL->setPlace('UIT', $aData['outcomming']); + $cTPL->setPlace('BG', $sBG); + $cTPL->parse(); + } +} + +$cTPL->show(); diff --git a/tests/Factories/LinkFactory.php b/tests/Factories/LinkFactory.php new file mode 100644 index 0000000..e5fce8b --- /dev/null +++ b/tests/Factories/LinkFactory.php @@ -0,0 +1,20 @@ +prepare($sql); + $query->execute([ + $name, $url + ]); + + return $pdo->lastInsertId(); + } +} \ No newline at end of file diff --git a/tests/Pages/LinksTestTest.php b/tests/Pages/LinksTestTest.php new file mode 100644 index 0000000..3aac9c7 --- /dev/null +++ b/tests/Pages/LinksTestTest.php @@ -0,0 +1,23 @@ +visitPage( + __DIR__ . '/../../links.php' + ); + + $this->assertContains('Spelcodes', $page); + $this->assertContains('Webdevils', $page); + } +}