Skip to content

Commit

Permalink
Added tests for links page
Browse files Browse the repository at this point in the history
Enhances test coverage #9
  • Loading branch information
Markkaz committed Jul 7, 2021
1 parent a2fac0c commit d1eea26
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 75 deletions.
140 changes: 65 additions & 75 deletions links.php
Original file line number Diff line number Diff line change
@@ -1,75 +1,65 @@
<?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();
$cTPL = new Template('Templates/main.tpl');

/* Verbinding met de database maken */
connectDB();

$cTPL -> 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();
?>
<?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();
$cTPL = new Template('Templates/main.tpl');

/* Verbinding met de database maken */
connectDB();

$cTPL->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();
20 changes: 20 additions & 0 deletions tests/Factories/LinkFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Tests\Factories;

class LinkFactory
{
public static function create(\PDO $pdo, $name, $url)
{
$sql = 'INSERT INTO links
(link, url, incomming, outcomming)
VALUES
(?, ?, 0, 0)';
$query = $pdo->prepare($sql);
$query->execute([
$name, $url
]);

return $pdo->lastInsertId();
}
}
23 changes: 23 additions & 0 deletions tests/Pages/LinksTestTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace Tests\Pages;

use Tests\Factories\LinkFactory;
use Tests\TestCase;

class LinksTestTest extends TestCase
{
/** @test */
public function it_shows_links()
{
LinkFactory::create(self::$pdo, 'Spelcodes', 'https://spelcodes.nl');
LinkFactory::create(self::$pdo, 'Webdevils', 'https://webdevils.nl');

$page = $this->visitPage(
__DIR__ . '/../../links.php'
);

$this->assertContains('Spelcodes', $page);
$this->assertContains('Webdevils', $page);
}
}

0 comments on commit d1eea26

Please sign in to comment.