From c307f63e1ff5508f7d0e5eca9644544c2a5ef5ea Mon Sep 17 00:00:00 2001 From: Flavio Copes Date: Fri, 29 Jan 2016 09:54:14 +0100 Subject: [PATCH] :white_check_mark: Cleanup tests --- tests/unit/Grav/Common/AssetsTest.php | 82 +++++++++++++++---------- tests/unit/Grav/Common/BrowserTest.php | 27 ++++++-- tests/unit/Grav/Common/MarkdownTest.php | 48 +++++++++------ tests/unit/Grav/Common/UriTest.php | 31 +++++++--- tests/unit/Grav/Common/UtilsTest.php | 36 +++++++---- 5 files changed, 146 insertions(+), 78 deletions(-) diff --git a/tests/unit/Grav/Common/AssetsTest.php b/tests/unit/Grav/Common/AssetsTest.php index a034a7518..353835f2b 100644 --- a/tests/unit/Grav/Common/AssetsTest.php +++ b/tests/unit/Grav/Common/AssetsTest.php @@ -1,12 +1,20 @@ 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, '' . PHP_EOL); + $this->assertSame($js, + '' . 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, '' . PHP_EOL); $js = $this->assets->js('footer'); - $this->assertSame($js, '' . PHP_EOL); + $this->assertSame($js, + '' . 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, '' . PHP_EOL . + $this->assertSame($js, + '' . PHP_EOL . '' . 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, '' . PHP_EOL); + $this->assertSame($js, + '' . 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, '' . PHP_EOL); + $this->assertSame($js, + '' . 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. '' . PHP_EOL); + $this->assertSame($css, + PHP_EOL . '' . PHP_EOL); } public function testAddInlineJs() diff --git a/tests/unit/Grav/Common/BrowserTest.php b/tests/unit/Grav/Common/BrowserTest.php index 1825c93b1..e5aca9923 100644 --- a/tests/unit/Grav/Common/BrowserTest.php +++ b/tests/unit/Grav/Common/BrowserTest.php @@ -1,23 +1,40 @@ 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() { diff --git a/tests/unit/Grav/Common/MarkdownTest.php b/tests/unit/Grav/Common/MarkdownTest.php index d14d30cb1..ba8890aa6 100644 --- a/tests/unit/Grav/Common/MarkdownTest.php +++ b/tests/unit/Grav/Common/MarkdownTest.php @@ -1,22 +1,29 @@ 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)'), '

mailto

'); - $this->assertSame($this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'), '

xmpp

'); - $this->assertSame($this->parsedown->text('[tel](tel:123-555-12345)'), '

tel

'); - $this->assertSame($this->parsedown->text('[sms](sms:123-555-12345)'), '

sms

'); + $this->assertSame($this->parsedown->text('[mailto](mailto:user@domain.com)'), + '

mailto

'); + $this->assertSame($this->parsedown->text('[xmpp](xmpp:xyx@domain.com)'), + '

xmpp

'); + $this->assertSame($this->parsedown->text('[tel](tel:123-555-12345)'), + '

tel

'); + $this->assertSame($this->parsedown->text('[sms](sms:123-555-12345)'), + '

sms

'); } 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), '

absolute link

'); + $this->assertSame($this->parsedown->text($sample), + '

absolute link

'); $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)'), '

cnn.com

'); - $this->assertSame($this->parsedown->text('[google.com](https://www.google.com)'), '

google.com

'); + $this->assertSame($this->parsedown->text('[cnn.com](http://www.cnn.com)'), + '

cnn.com

'); + $this->assertSame($this->parsedown->text('[google.com](https://www.google.com)'), + '

google.com

'); } } diff --git a/tests/unit/Grav/Common/UriTest.php b/tests/unit/Grav/Common/UriTest.php index ed75871e2..1236ceba5 100644 --- a/tests/unit/Grav/Common/UriTest.php +++ b/tests/unit/Grav/Common/UriTest.php @@ -1,11 +1,21 @@ 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', ]; diff --git a/tests/unit/Grav/Common/UtilsTest.php b/tests/unit/Grav/Common/UtilsTest.php index 57786e952..c6dbec24e 100644 --- a/tests/unit/Grav/Common/UtilsTest.php +++ b/tests/unit/Grav/Common/UtilsTest.php @@ -1,10 +1,17 @@ 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']));