Cleanup tests

This commit is contained in:
Flavio Copes
2016-01-29 09:54:14 +01:00
parent 1494247c85
commit c307f63e1f
5 changed files with 146 additions and 78 deletions

View File

@@ -1,12 +1,20 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Assets;
/**
* Class AssetsTest
*/
class AssetsTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
/** @var Assets $assets */
protected $assets;
protected function _before()
{
$this->grav = Fixtures::get('grav');
@@ -27,11 +35,11 @@ class AssetsTest extends \Codeception\TestCase\Test
$array = $this->assets->getCss();
$this->assertSame(reset($array), [
'asset' => '/test.css',
'asset' => '/test.css',
'priority' => 10,
'order' => 0,
'order' => 0,
'pipeline' => true,
'group' => 'head'
'group' => 'head'
]);
$this->assets->add('test.js');
@@ -40,11 +48,11 @@ class AssetsTest extends \Codeception\TestCase\Test
$array = $this->assets->getCss();
$this->assertSame(reset($array), [
'asset' => '/test.css',
'asset' => '/test.css',
'priority' => 10,
'order' => 0,
'order' => 0,
'pipeline' => true,
'group' => 'head'
'group' => 'head'
]);
//test addCss(). Test adding asset to a separate group
@@ -55,11 +63,11 @@ class AssetsTest extends \Codeception\TestCase\Test
$array = $this->assets->getCss();
$this->assertSame(reset($array), [
'asset' => '/test.css',
'asset' => '/test.css',
'priority' => 10,
'order' => 0,
'order' => 0,
'pipeline' => true,
'group' => 'head'
'group' => 'head'
]);
//test addJs()
@@ -70,12 +78,12 @@ class AssetsTest extends \Codeception\TestCase\Test
$array = $this->assets->getJs();
$this->assertSame(reset($array), [
'asset' => '/test.js',
'asset' => '/test.js',
'priority' => 10,
'order' => 0,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'head'
'loading' => '',
'group' => 'head'
]);
//Test CSS Groups
@@ -88,11 +96,11 @@ class AssetsTest extends \Codeception\TestCase\Test
$array = $this->assets->getCss();
$this->assertSame(reset($array), [
'asset' => '/test.css',
'asset' => '/test.css',
'priority' => 10,
'order' => 0,
'order' => 0,
'pipeline' => true,
'group' => 'footer'
'group' => 'footer'
]);
//Test JS Groups
@@ -105,12 +113,12 @@ class AssetsTest extends \Codeception\TestCase\Test
$array = $this->assets->getJs();
$this->assertSame(reset($array), [
'asset' => '/test.js',
'asset' => '/test.js',
'priority' => 10,
'order' => 0,
'order' => 0,
'pipeline' => true,
'loading' => '',
'group' => 'footer'
'loading' => '',
'group' => 'footer'
]);
//Test async / defer
@@ -121,12 +129,12 @@ class AssetsTest extends \Codeception\TestCase\Test
$array = $this->assets->getJs();
$this->assertSame(reset($array), [
'asset' => '/test.js',
'asset' => '/test.js',
'priority' => 10,
'order' => 0,
'order' => 0,
'pipeline' => true,
'loading' => 'async',
'group' => 'head'
'loading' => 'async',
'group' => 'head'
]);
$this->assets->reset();
@@ -136,12 +144,12 @@ class AssetsTest extends \Codeception\TestCase\Test
$array = $this->assets->getJs();
$this->assertSame(reset($array), [
'asset' => '/test.js',
'asset' => '/test.js',
'priority' => 10,
'order' => 0,
'order' => 0,
'pipeline' => true,
'loading' => 'defer',
'group' => 'head'
'loading' => 'defer',
'group' => 'head'
]);
}
@@ -162,7 +170,8 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->reset();
$this->assets->addJs('jquery', ['loading' => 'async']);
$js = $this->assets->js();
$this->assertSame($js, '<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL);
$this->assertSame($js,
'<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL);
//Test priority too
$this->assets->reset();
@@ -179,7 +188,8 @@ class AssetsTest extends \Codeception\TestCase\Test
$js = $this->assets->js();
$this->assertSame($js, '<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL);
$js = $this->assets->js('footer');
$this->assertSame($js, '<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL);
$this->assertSame($js,
'<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL);
//Test adding array of assets
//Test priority too
@@ -187,7 +197,8 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->addJs(['jquery', 'test.js'], ['loading' => 'async']);
$js = $this->assets->js();
$this->assertSame($js, '<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL .
$this->assertSame($js,
'<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL .
'<script src="/test.js" type="text/javascript" async></script>' . PHP_EOL);
}
@@ -274,7 +285,8 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->reset();
$this->assets->addAsyncJs('jquery');
$js = $this->assets->js();
$this->assertSame($js, '<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL);
$this->assertSame($js,
'<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" async></script>' . PHP_EOL);
}
public function testAddDeferJs()
@@ -282,7 +294,8 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->reset();
$this->assets->addDeferJs('jquery');
$js = $this->assets->js();
$this->assertSame($js, '<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" defer></script>' . PHP_EOL);
$this->assertSame($js,
'<script src="/system/assets/jquery/jquery-2.x.min.js" type="text/javascript" defer></script>' . PHP_EOL);
}
public function testAddInlineCss()
@@ -290,7 +303,8 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->reset();
$this->assets->addInlineCss('body { color: black }');
$css = $this->assets->css();
$this->assertSame($css, PHP_EOL. '<style>' .PHP_EOL . 'body { color: black }' . PHP_EOL.PHP_EOL .'</style>' . PHP_EOL);
$this->assertSame($css,
PHP_EOL . '<style>' . PHP_EOL . 'body { color: black }' . PHP_EOL . PHP_EOL . '</style>' . PHP_EOL);
}
public function testAddInlineJs()

View File

@@ -1,23 +1,40 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
/**
* Class BrowserTest
*/
class BrowserTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
protected function _before()
{
$this->grav = Fixtures::get('grav');
$this->assets = $this->grav['assets'];
}
protected function _after()
{
}
public function testGetBrowser() { /* Already covered by PhpUserAgent tests */ }
public function testGetPlatform() { /* Already covered by PhpUserAgent tests */ }
public function testGetLongVersion() { /* Already covered by PhpUserAgent tests */ }
public function testGetVersion() { /* Already covered by PhpUserAgent tests */ }
public function testGetBrowser()
{ /* Already covered by PhpUserAgent tests */
}
public function testGetPlatform()
{ /* Already covered by PhpUserAgent tests */
}
public function testGetLongVersion()
{ /* Already covered by PhpUserAgent tests */
}
public function testGetVersion()
{ /* Already covered by PhpUserAgent tests */
}
public function testIsHuman()
{

View File

@@ -1,22 +1,29 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
/**
* Class AssetsTest
*/
class MarkdownTest extends \Codeception\TestCase\Test
{
/** @var Parsedown $parsedown */
protected $parsedown;
/** @var Grav $grav */
protected $grav;
protected function _before()
{
$this->grav = Fixtures::get('grav');
$defaults = [
'extra' => false,
'extra' => false,
'auto_line_breaks' => false,
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
'auto_url_links' => false,
'escape_markup' => false,
'special_chars' => ['>' => 'gt', '<' => 'lt'],
];
$page = new \Grav\Common\Page\Page();
@@ -27,24 +34,26 @@ class MarkdownTest extends \Codeception\TestCase\Test
{
}
public function grav()
{
$grav = Fixtures::get('grav');
return $grav;
}
/**
* @param $string
*
* @return mixed
*/
public function stripLeadingWhitespace($string)
{
return preg_replace('/^\s*(.*)/', '', $string);
}
public function testMarkdownSpecialProtocols()
{
$this->assertSame($this->parsedown->text('[mailto](mailto:user@domain.com)'), '<p><a href="mailto:user@domain.com">mailto</a></p>');
$this->assertSame($this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'), '<p><a href="xmpp:xyx@domain.com">xmpp</a></p>');
$this->assertSame($this->parsedown->text('[tel](tel:123-555-12345)'), '<p><a href="tel:123-555-12345">tel</a></p>');
$this->assertSame($this->parsedown->text('[sms](sms:123-555-12345)'), '<p><a href="sms:123-555-12345">sms</a></p>');
$this->assertSame($this->parsedown->text('[mailto](mailto:user@domain.com)'),
'<p><a href="mailto:user@domain.com">mailto</a></p>');
$this->assertSame($this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'),
'<p><a href="xmpp:xyx@domain.com">xmpp</a></p>');
$this->assertSame($this->parsedown->text('[tel](tel:123-555-12345)'),
'<p><a href="tel:123-555-12345">tel</a></p>');
$this->assertSame($this->parsedown->text('[sms](sms:123-555-12345)'),
'<p><a href="sms:123-555-12345">sms</a></p>');
}
public function testMarkdownReferenceLinks()
@@ -55,7 +64,8 @@ class MarkdownTest extends \Codeception\TestCase\Test
$sample = '[absolute link][r_absolute]
[r_absolute]: /blog/focus-and-blur#blah';
$this->assertSame($this->parsedown->text($sample), '<p><a href="/blog/focus-and-blur#blah">absolute link</a></p>');
$this->assertSame($this->parsedown->text($sample),
'<p><a href="/blog/focus-and-blur#blah">absolute link</a></p>');
$sample = '[external link][r_external]
[r_external]: http://www.cnn.com';
@@ -64,7 +74,9 @@ class MarkdownTest extends \Codeception\TestCase\Test
public function testMarkdownExternalLinks()
{
$this->assertSame($this->parsedown->text('[cnn.com](http://www.cnn.com)'), '<p><a href="http://www.cnn.com">cnn.com</a></p>');
$this->assertSame($this->parsedown->text('[google.com](https://www.google.com)'), '<p><a href="https://www.google.com">google.com</a></p>');
$this->assertSame($this->parsedown->text('[cnn.com](http://www.cnn.com)'),
'<p><a href="http://www.cnn.com">cnn.com</a></p>');
$this->assertSame($this->parsedown->text('[google.com](https://www.google.com)'),
'<p><a href="https://www.google.com">google.com</a></p>');
}
}

View File

@@ -1,11 +1,21 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Uri;
use Grav\Common\Utils;
/**
* Class UriTest
*/
class UriTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
/** @var Uri $uri */
protected $uri;
protected function _before()
{
$this->grav = Fixtures::get('grav');
@@ -71,7 +81,8 @@ class UriTest extends \Codeception\TestCase\Test
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d')->init();
$this->assertSame($this->uri->paths(), ['a', 'b', 'c', 'd']);
$this->uri->initializeWithURL('http://localhost:8080/a/b/c/d/e/f/a/b/c/d/e/f/a/b/c/d/e/f')->init();
$this->assertSame($this->uri->paths(), ['a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f']);
$this->assertSame($this->uri->paths(),
['a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f', 'a', 'b', 'c', 'd', 'e', 'f']);
}
public function testRoute()
@@ -367,20 +378,20 @@ class UriTest extends \Codeception\TestCase\Test
{
$parsed_url = [
'scheme' => 'http',
'host' => 'localhost',
'port' => '8080',
'host' => 'localhost',
'port' => '8080',
];
$this->assertSame(Uri::buildUrl($parsed_url), 'http://localhost:8080');
$parsed_url = [
'scheme' => 'http',
'host' => 'localhost',
'port' => '8080',
'user' => 'foo',
'pass' => 'bar',
'path' => '/test',
'query' => 'x=2',
'scheme' => 'http',
'host' => 'localhost',
'port' => '8080',
'user' => 'foo',
'pass' => 'bar',
'path' => '/test',
'query' => 'x=2',
'fragment' => 'xxx',
];

View File

@@ -1,10 +1,17 @@
<?php
use Codeception\Util\Fixtures;
use Grav\Common\Grav;
use Grav\Common\Utils;
/**
* Class UtilsTest
*/
class UtilsTest extends \Codeception\TestCase\Test
{
/** @var Grav $grav */
protected $grav;
protected function _before()
{
$this->grav = Fixtures::get('grav');
@@ -19,12 +26,14 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertTrue(Utils::startsWith('english', 'en'));
$this->assertTrue(Utils::startsWith('English', 'En'));
$this->assertTrue(Utils::startsWith('ENGLISH', 'EN'));
$this->assertTrue(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH', 'EN'));
$this->assertTrue(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'EN'));
$this->assertFalse(Utils::startsWith('english', 'En'));
$this->assertFalse(Utils::startsWith('English', 'EN'));
$this->assertFalse(Utils::startsWith('ENGLISH', 'en'));
$this->assertFalse(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH', 'e'));
$this->assertFalse(Utils::startsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'e'));
}
public function testEndsWith()
@@ -32,12 +41,14 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertTrue(Utils::endsWith('english', 'sh'));
$this->assertTrue(Utils::endsWith('EngliSh', 'Sh'));
$this->assertTrue(Utils::endsWith('ENGLISH', 'SH'));
$this->assertTrue(Utils::endsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH', 'ENGLISH'));
$this->assertTrue(Utils::endsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'ENGLISH'));
$this->assertFalse(Utils::endsWith('english', 'de'));
$this->assertFalse(Utils::endsWith('EngliSh', 'sh'));
$this->assertFalse(Utils::endsWith('ENGLISH', 'Sh'));
$this->assertFalse(Utils::endsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH', 'DEUSTCH'));
$this->assertFalse(Utils::endsWith('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'DEUSTCH'));
}
public function testContains()
@@ -45,11 +56,14 @@ class UtilsTest extends \Codeception\TestCase\Test
$this->assertTrue(Utils::contains('english', 'nglis'));
$this->assertTrue(Utils::contains('EngliSh', 'gliSh'));
$this->assertTrue(Utils::contains('ENGLISH', 'ENGLI'));
$this->assertTrue(Utils::contains('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH', 'ENGLISH'));
$this->assertTrue(Utils::contains('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'ENGLISH'));
$this->assertFalse(Utils::contains('EngliSh', 'GLI')); $this->assertFalse(Utils::contains('EngliSh', 'English'));
$this->assertFalse(Utils::contains('EngliSh', 'GLI'));
$this->assertFalse(Utils::contains('EngliSh', 'English'));
$this->assertFalse(Utils::contains('ENGLISH', 'SCH'));
$this->assertFalse(Utils::contains('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH', 'DEUSTCH'));
$this->assertFalse(Utils::contains('ENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISHENGLISH',
'DEUSTCH'));
}
public function testSubstrToString()
@@ -166,13 +180,13 @@ class UtilsTest extends \Codeception\TestCase\Test
public function testArrayFilterRecursive()
{
$array = [
'test' => '',
'test' => '',
'test2' => 'test2'
];
$array = Utils::arrayFilterRecursive($array, function($k, $v) {
return !(is_null($v) || $v === '');
});
$array = Utils::arrayFilterRecursive($array, function ($k, $v) {
return !(is_null($v) || $v === '');
});
$this->assertContainsOnly('string', $array);
$this->assertFalse(isset($array['test']));