Skip to content

Commit

Permalink
Added test coverage for incoming links counter
Browse files Browse the repository at this point in the history
Relates to #9
  • Loading branch information
Markkaz committed Jul 7, 2021
1 parent d1eea26 commit 34e50bb
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 37 deletions.
38 changes: 38 additions & 0 deletions tests/Pages/LinksTestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,42 @@ public function it_shows_links()
$this->assertContains('Spelcodes', $page);
$this->assertContains('Webdevils', $page);
}

/** @test */
public function it_counts_outgoing_clicks()
{
$linkId = LinkFactory::create(self::$pdo, 'Spelcodes', 'https://spelcodes.nl');

$page = $this->visitPage(
__DIR__ . '/../../uit.php',
['id' => $linkId]
);

$this->assertEquals('', $page);
$this->assertDatabaseHas('links', [
'link' => 'Spelcodes',
'outcomming' => 1
]);
}

/** @test */
public function it_shows_404_when_id_isnt_provided()
{
$page = $this->visitPage(
__DIR__ . '/../../uit.php'
);

$this->assertEquals('', $page);
}

/** @test */
public function it_shows_404_when_link_doesnt_exist()
{
$page = $this->visitPage(
__DIR__ . '/../../uit.php',
['id' => 999]
);

$this->assertEquals('', $page);
}
}
64 changes: 27 additions & 37 deletions uit.php
Original file line number Diff line number Diff line change
@@ -1,37 +1,27 @@
<?php
error_reporting(E_ALL);

/* Includes importeren */
include('Includes/connect.php');
include('Includes/slashes.php');

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

/* Controleren of er een id is meegegeven */
if(isset($_GET['id']))
{
$sQuery = "UPDATE links SET outcomming=outcomming+1 WHERE linkid='" . add($_GET['id']) . "';";
if(mysql_query($sQuery))
{
$sQuery = "SELECT url FROM links WHERE linkid='" . add($_GET['id']) . "';";
if($cResult = mysql_query($sQuery))
{
$aData = mysql_fetch_assoc($cResult);
header('Location: ' . $aData['url']);
}
else
{
header('HTTP/1.0 404');
}
}
else
{
header('HTTP/1.0 404');
}
}
else
{
header('HTTP/1.0 404');
}
?>
<?php
error_reporting(E_ALL & ~E_DEPRECATED);

/* Includes importeren */
include_once('Includes/connect.php');
include_once('Includes/slashes.php');

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

/* Controleren of er een id is meegegeven */
if (isset($_GET['id'])) {
$sQuery = "UPDATE links SET outcomming=outcomming+1 WHERE linkid='" . add($_GET['id']) . "';";
if (mysql_query($sQuery)) {
$sQuery = "SELECT url FROM links WHERE linkid='" . add($_GET['id']) . "';";
if ($cResult = mysql_query($sQuery)) {
$aData = mysql_fetch_assoc($cResult);
header('Location: ' . $aData['url']);
} else {
header('HTTP/1.0 404');
}
} else {
header('HTTP/1.0 404');
}
} else {
header('HTTP/1.0 404');
}

0 comments on commit 34e50bb

Please sign in to comment.