Skip to content

Commit

Permalink
Merge pull request #693 from teiling88/misc/give-me-more-tests
Browse files Browse the repository at this point in the history
Misc/give me more tests
  • Loading branch information
teiling88 committed Nov 23, 2017
2 parents 2fa2b9e + ec796da commit 07d500e
Show file tree
Hide file tree
Showing 14 changed files with 126 additions and 108 deletions.
Expand Up @@ -3,6 +3,7 @@
namespace Oc\GeoCache\Persistence\GeoCache;

use Oc\GeoCache\Enum\WaypointType;
use Oc\GeoCache\Exception\UnknownWaypointTypeException;
use Oc\Repository\Exception\RecordNotFoundException;
use Oc\Repository\Exception\RecordsNotFoundException;

Expand Down Expand Up @@ -46,11 +47,11 @@ public function fetchAll()
*/
public function fetchByWaypoint($waypoint)
{
$waypointType = WaypointType::guess($waypoint);

$waypointEntity = null;

try {
$waypointType = WaypointType::guess($waypoint);

if ($waypointType === WaypointType::OC) {
$waypointEntity = $this->geoCacheRepository->fetchOneBy([
'wp_oc' => $waypoint,
Expand All @@ -60,6 +61,8 @@ public function fetchByWaypoint($waypoint)
}
} catch (RecordNotFoundException $e) {
$waypointEntity = null;
} catch (UnknownWaypointTypeException $e) {
$waypointEntity = null;
}

return $waypointEntity;
Expand Down
28 changes: 10 additions & 18 deletions phpunit.xml.dist
Expand Up @@ -18,24 +18,16 @@
</testsuites>
<filter>
<whitelist>
<directory>htdocs/</directory>
<exclude>
<directory>htdocs/app/</directory>
<directory>htdocs/bin/</directory>
<directory>htdocs/cache2/</directory>
<directory>htdocs/config2/</directory>
<directory>htdocs/doc/</directory>
<directory>htdocs/download/</directory>
<directory>htdocs/html/</directory>
<directory>htdocs/images/</directory>
<directory>htdocs/lang/</directory>
<directory>htdocs/okapi/</directory>
<directory>htdocs/resource2/</directory>
<directory>htdocs/templates2/</directory>
<directory>htdocs/var/</directory>
<directory>htdocs/vendor/</directory>
<directory>htdocs/xml/</directory>
</exclude>
<directory>htdocs/api</directory>
<directory>htdocs/app</directory>
<directory>htdocs/bin</directory>
<directory>htdocs/src</directory>
<directory>htdocs/lib</directory>
<directory>htdocs/lib2</directory>
<directory>htdocs/okapi</directory>
<directory>htdocs/util</directory>
<directory>htdocs/util2</directory>
<directory>htdocs/xml</directory>
</whitelist>
</filter>
<php>
Expand Down
8 changes: 0 additions & 8 deletions tests/Modules/AbstractModuleTest.php
Expand Up @@ -17,12 +17,4 @@ public function __construct($name = null, array $data = [], $dataName = '')

$this->dir = __DIR__;
}

public function bootSymfonyKernel()
{
$debug = true;

$kernel = new \AppKernel('test', $debug);
$kernel->boot();
}
}
35 changes: 35 additions & 0 deletions tests/Modules/Api/Rot13Test.php
@@ -0,0 +1,35 @@
<?php

namespace OcTest\Modules\Api;

use OcTest\Modules\AbstractModuleTest;

require_once __DIR__ . '/../../../htdocs/api/rot13.php';

class Rot13Test extends AbstractModuleTest
{
// this function didn't support nested braces
public function test_hint_rot13_excludes_braces()
{
$string = 'a[123123]b';

self::assertEquals('n[123123]o', \hint_rot13($string));

$string = 'a[abcdef]b';

self::assertEquals('n[abcdef]o', \hint_rot13($string));

$string = 'abcdefghijklmnopqrstuvwxyz';
self::assertEquals('nopqrstuvwxyzabcdefghijklm', \hint_rot13($string));

$string = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
self::assertEquals('NOPQRSTUVWXYZABCDEFGHIJKLM', \hint_rot13($string));
}

public function test_hint_rot13_encrypts()
{
$string = 'abcd123efgh';

self::assertEquals('nopq123rstu', \hint_rot13($string));
}
}
65 changes: 23 additions & 42 deletions tests/Modules/Lib2/OcHTMLPurifierTest.php
Expand Up @@ -20,7 +20,7 @@ public function __construct($name = null, array $data = [], $dataName = '')

public function testAllowedHtmlTags()
{
// For backward compatibilty of editing existing cache listings, it can be
// For backward compatibility of editing existing cache listings, it can be
// CRITICAL if this test fails.

$allowed = [
Expand All @@ -37,13 +37,13 @@ public function testAllowedHtmlTags()
'<cite>test</cite>',
'<code>test</code>',
'<dl><dt>test</dt><dd>test</dd></dl>',
// includes <dt> and <dd>
// includes <dt> and <dd>
'<del cite="test">test</del>',
'<dfn>test</dfn>',
'<div>test</div>',
'<em>test</em>',
'<fieldset><legend>test</legend>test</fieldset>',
// includes <legend>
// includes <legend>
'<h1>test</h1>',
'<h2>test</h2>',
'<h3>test</h3>',
Expand All @@ -56,38 +56,30 @@ public function testAllowedHtmlTags()
'<ins cite="test">test</ins>',
'<kbd>test</kbd>',
'<map name="custom_test"><area alt="test" coords="0,0,1,1" href="test.html" shape="rect" target="_blank" /></map>',
// includes <area>
// includes <area>
'<ol type="1" compact="compact"><li>test</li></ol>',
'<p>test</p>',
'<pre>test</pre>',
'<q cite="test">test</q>',
'<samp>test</samp>',
'<small>test</small>',
'<span class="test" dir="ltr" id="custom_test" lang="de" style="display:inline;" title="test" xml:lang="de">test</span>',
// includes global attributes
// includes global attributes
'<strong>test</strong>',
'sub', '<sub>test</sub>',
'sup', '<sup>test</sup>',
'<table><caption align="left">test</caption><colgroup span="1"><col align="left" span="1" width="50" /></colgroup><thead><tr><th abbr="test" align="left" bgcolor="#FFFFFF" colspan="1" height="10" nowrap="nowrap" rowspan="1" scope="col" valign="top" width="10">test</th></tr></thead><tfoot><tr><td>test</td></tr></tfoot><tbody><tr align="left" bgcolor="#FFFFFF" valign="top"><td abbr="test" align="left" bgcolor="#FFFFFF" colspan="1" height="10" nowrap="nowrap" rowspan="1" scope="col" valign="top" width="10">test</td></tr></tbody></table>',
// includes all table child tags
// includes all table child tags
'<tt>test</tt>',
'<u>test</u>',
'<ul compact="compact"><li>test</li></ul>',
'<var>test</var>',
];

$original = '';
$purified = '';

foreach ($allowed as $html) {
$purifiedHtml = $this->htmlPurifier->purify($html);
if ($purifiedHtml != $html) {
$original .= "$html\n";
$purified .= "$purifiedHtml\n";
}
self::assertEquals($html, $purifiedHtml);
}

self::assertEquals($original, $purified);
}

public function testHtmlTagAIsAllowedAndProtectedWithNoOpener()
Expand All @@ -109,10 +101,10 @@ public function testRemovedHtmlTags()
$removed = [
'<applet code="test.class">*</applet>',
'<article><header>*</header></article>',
// includes <header>
// includes <header>
'<aside>*</aside>',
'<audio controls="controls"><source src="test.mp3" type="audio/mpeg" />*</audio>',
// includes <source>
// includes <source>
'<base href="test.html" />',
'<basefont color="#FFFFFF" />',
'<bdi>*</bdi>',
Expand All @@ -125,43 +117,43 @@ public function testRemovedHtmlTags()
'<figure><figcaption>*</figcaption></figure>',
'<footer>*</footer>',
'<form><input id="custom_s" type="submit" value="submit" /><label for="custum_s">*</label><output name="custom_o" for="custom_s"></output><textarea rows="5" cols="10"></textarea></form>',
// includes <input> <textarea> <label> <output>
// includes <input> <textarea> <label> <output>
'<frameset cols="100%"><frame src="test.html"></frame></frameset>',
// includes <frame>
// includes <frame>
'<html><head><body>*</body></html>',
// includes <head> <title> <meta> <link> <body>
// includes <head> <title> <meta> <link> <body>
'<head><title>*</title></head>',
'<iframe src="test.html"></iframe>',
'<link rel="stylesheet" type="text/css" href="theme.css" />',
'<main>*</main>',
'<mark>*</mark>',
'<menu type="context"><menuitem label="test" onclick="test"></menuitem></menu>',
// includes <menuitem>
// includes <menuitem>
'<meta charset="UTF-8" /><link rel="stylesheet" type="text/css" href="theme.css" />',
'<meter value="1" min="0" max="2">*</meter>',
'<nav><a href="test.html"></a></nav>|<a href="test.html"></a>',
// <a> only included for completeness
// <a> only included for completeness
'<noframes>*</noframes>',
'<noscript>*</noscript>',
'<object width="400" height="400" data="test.swf"><param name="custom_p" value="1" /></object>',
// includes <param>
// includes <param>
'<picture><source media="(min-width: 650px)" srcset="test.jpg" /><img src="test.jpg" alt="" /></picture>|<img src="test.jpg" alt="" />',
// includes <source>; <img> only included for completeness
// includes <source>; <img> only included for completeness
'<progress value="10" max="100"></progress>',
'<ruby>*<rt><rp>*</rp>*<rp>*</rp></rt></ruby>',
// includes <rt> <rp>
// includes <rt> <rp>
'<script>*</script>',
'<section>*</section>',
'<select><optgroup label="test"><option value="test">*</option></optgroup></select>',
// includes <optgroup> <option>
// includes <optgroup> <option>
'<style>*</style>',
'<summary>*</summary>',
'<time>*</time>',
'<title>*</title>',
'<ul><li><datalist id="test"><option value="test"></option></datalist></li></ul>|<ul><li></li></ul>',
// <ul> <li> only included for completeness
// <ul> <li> only included for completeness
'<video width="320" height="240"><track src="test.vtt" kind="subtitles" /></video>',
// includes <track>
// includes <track>
'<wbr>*</wbr>',
];

Expand All @@ -174,12 +166,9 @@ public function testRemovedHtmlTags()

$purifiedHtml = $this->htmlPurifier->purify($original);
$purifiedHtml = str_replace('*', '', $purifiedHtml);
if ($purifiedHtml != $expected) {
$purified .= "$purifiedHtml\n";
}
}

self::assertEquals('', $purified);
self::assertEquals($purifiedHtml, $expected);
}
}

public function testAllowedCss()
Expand Down Expand Up @@ -260,18 +249,10 @@ public function testAllowedCss()
'word-spacing:3px',
];

$original = '';
$purified = '';

foreach ($allowed as $style) {
$html = '<div style="' . $style . ';">*</div>';
$purifiedHtml = $this->htmlPurifier->purify($html);
if ($purifiedHtml != $html) {
$original .= "$html\n";
$purified .= "$purifiedHtml\n";
}
self::assertEquals($purifiedHtml, $html);
}

self::assertEquals($original, $purified);
}
}
23 changes: 23 additions & 0 deletions tests/Modules/Oc/GeoCache/Controller/QrCodeControllerTest.php
@@ -0,0 +1,23 @@
<?php

namespace OcTest\Modules\Oc\GeoCache\Controller;

use AppKernel;
use Oc\GeoCache\Controller\QrCodeController;
use OcTest\Modules\TestCase;
use Symfony\Component\HttpFoundation\Request;

class QrCodeControllerTest extends TestCase
{
public function test_generate_qr_code_throws_unkown_waypoint_exception()
{
/** @var QrCodeController $controller */
$controller = AppKernel::Container()->get(QrCodeController::class);

$request = new Request(['wp' => 'OC0002']);

$this->setExpectedException(\InvalidArgumentException::class);

$controller->generateQrCode($request);
}
}
20 changes: 20 additions & 0 deletions tests/Modules/OcDev/KitchenSink/Subscriber/MenuSubscriberTest.php
@@ -0,0 +1,20 @@
<?php

namespace OcTest\Modules\OcDev\KitchenSink\Subscriber;

use AppKernel;
use OcDev\KitchenSink\Subscriber\MenuSubscriber;
use OcTest\Modules\TestCase;

/**
* Class CountryEntityTest
*/
class MenuSubscriberTest extends TestCase
{
public function test_get_subscribed_events_returns_array()
{
$menuSubscriber = AppKernel::Container()->get(MenuSubscriber::class);

$this->assertInternalType('array', $menuSubscriber::getSubscribedEvents());
}
}
3 changes: 0 additions & 3 deletions tests/Modules/OcLegacy/ContainerTest.php
Expand Up @@ -13,9 +13,6 @@ class ContainerTest extends AbstractModuleTest
{
public function testIfContainerReturnServiceId()
{
$kernel = new AppKernel('prod', false);
$kernel->boot();

self::assertInstanceOf(Connection::class, AppKernel::Container()->get(Connection::class));
// cached container
self::assertInstanceOf(Connection::class, AppKernel::Container()->get(Connection::class));
Expand Down
5 changes: 0 additions & 5 deletions tests/Modules/OcLegacy/SmartyPlugins/TranslationTest.php
Expand Up @@ -8,11 +8,6 @@

class TranslationTest extends AbstractModuleTest
{
public function setUp()
{
$this->bootSymfonyKernel();
}

public function testTranslation()
{
global $opt;
Expand Down
2 changes: 0 additions & 2 deletions tests/Modules/Okapi/Integration/Services/AttrsTest.php
Expand Up @@ -75,8 +75,6 @@ public function testAttrsAttributesMethodReturnsAttribute()
self::assertArrayHasKey('A1', $response);
self::assertArrayHasKey('A2', $response);



self::assertEquals('Listed at Opencaching only', $response['A1']['name']);
}
}
3 changes: 2 additions & 1 deletion tests/Modules/Okapi/OkapiClient.php
Expand Up @@ -66,7 +66,8 @@ public function post($url, $data = [], $params = [])

protected function prepareResponse($result, $httpCode)
{
if (null === $decodedResult = json_decode($result, true)) {
$decodedResult = json_decode($result, true);
if ($decodedResult === null) {
echo "\n\n";
var_dump($result);
echo "\n\n";
Expand Down
2 changes: 1 addition & 1 deletion tests/Modules/Okapi/OkapiCredentialsTrait.php
Expand Up @@ -19,6 +19,6 @@ public function getConsumerKey()
*/
public function createOkapiClient()
{
return new OkapiClient($this->getOkapiUrl(), $this->getConsumerKey());
return new OkapiClient($this->getOkapiUrl());
}
}
7 changes: 7 additions & 0 deletions tests/bootstrap.php
Expand Up @@ -3,3 +3,10 @@
date_default_timezone_set('Europe/Berlin');

require_once __DIR__ . '/../htdocs/vendor/autoload.php';

$env = 'prod';
$debug = true;

$kernel = new AppKernel($env, $debug);
$kernel->boot();

0 comments on commit 07d500e

Please sign in to comment.