Updated unit tests

This commit is contained in:
Matias Griese
2020-12-04 20:01:28 +02:00
parent 7c0ba80530
commit f25ea8f056
8 changed files with 732 additions and 1630 deletions

View File

@@ -1,4 +1,5 @@
actor: Tester actor: Tester
bootstrap: _bootstrap.php
paths: paths:
tests: tests tests: tests
log: tests/_output log: tests/_output
@@ -6,7 +7,6 @@ paths:
support: tests/_support support: tests/_support
envs: tests/_envs envs: tests/_envs
settings: settings:
bootstrap: _bootstrap.php
colors: true colors: true
memory_limit: 1024M memory_limit: 1024M
extensions: extensions:

View File

@@ -61,12 +61,13 @@
"symfony/http-client": "^4.4" "symfony/http-client": "^4.4"
}, },
"require-dev": { "require-dev": {
"codeception/codeception": "^2.5", "codeception/codeception": "^4.1",
"phpstan/phpstan": "^0.11", "phpstan/phpstan": "^0.11",
"phpstan/phpstan-deprecation-rules": "^0.11", "phpstan/phpstan-deprecation-rules": "^0.11",
"phpunit/php-code-coverage": "~6.1", "phpunit/php-code-coverage": "~9.2",
"fzaninotto/faker": "^1.9", "fzaninotto/faker": "^1.9",
"victorjonsson/markdowndocs": "dev-master" "victorjonsson/markdowndocs": "dev-master",
"codeception/module-asserts": "^1.3"
}, },
"suggest": { "suggest": {
"ext-mbstring": "Recommended for better performance", "ext-mbstring": "Recommended for better performance",

2253
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@@ -40,16 +40,16 @@ class AssetsTest extends \Codeception\TestCase\Test
$item = reset($array); $item = reset($array);
$actual = json_encode($item); $actual = json_encode($item);
$expected = ' $expected = '
{ {
"type":"css", "type":"css",
"elements":{ "elements":{
"asset":"\/test.css", "asset":"\/test.css",
"asset_type":"css", "asset_type":"css",
"order":0, "order":0,
"group":"head", "group":"head",
"position":"pipeline", "position":"pipeline",
"priority":10, "priority":10,
"attributes":{ "attributes":{
"type":"text\/css", "type":"text\/css",
"rel":"stylesheet" "rel":"stylesheet"
}, },
@@ -69,17 +69,17 @@ class AssetsTest extends \Codeception\TestCase\Test
$item = reset($array); $item = reset($array);
$actual = json_encode($item); $actual = json_encode($item);
$expected = ' $expected = '
{ {
"type":"js", "type":"js",
"elements":{ "elements":{
"asset":"\/test.js", "asset":"\/test.js",
"asset_type":"js", "asset_type":"js",
"order":0, "order":0,
"group":"head", "group":"head",
"position":"pipeline", "position":"pipeline",
"priority":10, "priority":10,
"attributes":[ "attributes":[
], ],
"modified":false, "modified":false,
"query":"" "query":""
@@ -98,16 +98,16 @@ class AssetsTest extends \Codeception\TestCase\Test
$item = reset($array); $item = reset($array);
$actual = json_encode($item); $actual = json_encode($item);
$expected = ' $expected = '
{ {
"type":"css", "type":"css",
"elements":{ "elements":{
"asset":"\/test.css", "asset":"\/test.css",
"asset_type":"css", "asset_type":"css",
"order":0, "order":0,
"group":"head", "group":"head",
"position":"pipeline", "position":"pipeline",
"priority":10, "priority":10,
"attributes":{ "attributes":{
"type":"text\/css", "type":"text\/css",
"rel":"stylesheet" "rel":"stylesheet"
}, },
@@ -128,16 +128,16 @@ class AssetsTest extends \Codeception\TestCase\Test
$item = reset($array); $item = reset($array);
$actual = json_encode($item); $actual = json_encode($item);
$expected = ' $expected = '
{ {
"type":"css", "type":"css",
"elements":{ "elements":{
"asset":"http:\/\/www.somesite.com\/test.css", "asset":"http:\/\/www.somesite.com\/test.css",
"asset_type":"css", "asset_type":"css",
"order":0, "order":0,
"group":"head", "group":"head",
"position":"pipeline", "position":"pipeline",
"priority":10, "priority":10,
"attributes":{ "attributes":{
"type":"text\/css", "type":"text\/css",
"rel":"stylesheet" "rel":"stylesheet"
}, },
@@ -163,9 +163,9 @@ class AssetsTest extends \Codeception\TestCase\Test
$item = reset($array); $item = reset($array);
$actual = json_encode($item); $actual = json_encode($item);
$expected = ' $expected = '
{ {
"type":"js", "type":"js",
"elements":{ "elements":{
"asset":"\/test.js", "asset":"\/test.js",
"asset_type":"js", "asset_type":"js",
"order":0, "order":0,
@@ -303,19 +303,19 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->setJsPipeline(true); $this->assets->setJsPipeline(true);
$this->assets->addJs('/system/assets/jquery/jquery-3.x.min.js'); $this->assets->addJs('/system/assets/jquery/jquery-3.x.min.js');
$js = $this->assets->js('head', ['loading' => 'inline']); $js = $this->assets->js('head', ['loading' => 'inline']);
$this->assertContains('"jquery",[],function()', $js); $this->assertStringContainsString('"jquery",[],function()', $js);
$this->assets->reset(); $this->assets->reset();
$this->assets->setCssPipeline(true); $this->assets->setCssPipeline(true);
$this->assets->addCss('/system/assets/debugger/phpdebugbar.css'); $this->assets->addCss('/system/assets/debugger/phpdebugbar.css');
$css = $this->assets->css('head', ['loading' => 'inline']); $css = $this->assets->css('head', ['loading' => 'inline']);
$this->assertContains('div.phpdebugbar', $css); $this->assertStringContainsString('div.phpdebugbar', $css);
$this->assets->reset(); $this->assets->reset();
$this->assets->setCssPipeline(true); $this->assets->setCssPipeline(true);
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto'); $this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto');
$css = $this->assets->css('head', ['loading' => 'inline']); $css = $this->assets->css('head', ['loading' => 'inline']);
$this->assertContains('font-family:\'Roboto\';', $css); $this->assertStringContainsString('font-family:\'Roboto\';', $css);
//Test adding media queries //Test adding media queries
$this->assets->reset(); $this->assets->reset();
@@ -383,16 +383,16 @@ class AssetsTest extends \Codeception\TestCase\Test
$item = reset($array); $item = reset($array);
$actual = json_encode($item); $actual = json_encode($item);
$expected = ' $expected = '
{ {
"type":"css", "type":"css",
"elements":{ "elements":{
"asset":"\/test.css", "asset":"\/test.css",
"asset_type":"css", "asset_type":"css",
"order":0, "order":0,
"group":"bottom", "group":"bottom",
"position":"pipeline", "position":"pipeline",
"priority":15, "priority":15,
"attributes":{ "attributes":{
"type":"text\/css", "type":"text\/css",
"rel":"stylesheet", "rel":"stylesheet",
"loading":"async" "loading":"async"
@@ -546,8 +546,8 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', ['loading' => 'inline']); $this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', ['loading' => 'inline']);
$this->assets->addCss('/system/assets/debugger/phpdebugbar.css', ['loading' => 'inline']); $this->assets->addCss('/system/assets/debugger/phpdebugbar.css', ['loading' => 'inline']);
$css = $this->assets->css(); $css = $this->assets->css();
$this->assertContains('font-family: \'Roboto\';', $css); $this->assertStringContainsString('font-family: \'Roboto\';', $css);
$this->assertContains('div.phpdebugbar-header', $css); $this->assertStringContainsString('div.phpdebugbar-header', $css);
} }
public function testInlinePipeline() public function testInlinePipeline()
@@ -564,8 +564,8 @@ class AssetsTest extends \Codeception\TestCase\Test
$this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', null, true); $this->assets->addCss('https://fonts.googleapis.com/css?family=Roboto', null, true);
$this->assets->add('/system/assets/debugger/phpdebugbar.css', null, true); $this->assets->add('/system/assets/debugger/phpdebugbar.css', null, true);
$css = $this->assets->css('head', ['loading' => 'inline']); $css = $this->assets->css('head', ['loading' => 'inline']);
$this->assertContains('font-family:\'Roboto\';', $css); $this->assertStringContainsString('font-family:\'Roboto\';', $css);
$this->assertContains('div.phpdebugbar', $css); $this->assertStringContainsString('div.phpdebugbar', $css);
} }
public function testAddAsyncJs() public function testAddAsyncJs()
@@ -661,7 +661,7 @@ class AssetsTest extends \Codeception\TestCase\Test
public function testGetCollections() public function testGetCollections()
{ {
$this->assertInternalType('array', $this->assets->getCollections()); $this->assertIsArray($this->assets->getCollections());
$this->assertContains('jquery', array_keys($this->assets->getCollections())); $this->assertContains('jquery', array_keys($this->assets->getCollections()));
$this->assertContains('system://assets/jquery/jquery-2.x.min.js', $this->assets->getCollections()); $this->assertContains('system://assets/jquery/jquery-2.x.min.js', $this->assets->getCollections());
} }
@@ -724,50 +724,50 @@ class AssetsTest extends \Codeception\TestCase\Test
{ {
$this->assets->addDirCss('/system'); $this->assets->addDirCss('/system');
$this->assertInternalType('array', $this->assets->getCss()); $this->assertIsArray($this->assets->getCss());
$this->assertGreaterThan(0, (array) $this->assets->getCss()); $this->assertGreaterThan(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs()); $this->assertIsArray($this->assets->getJs());
$this->assertCount(0, (array) $this->assets->getJs()); $this->assertCount(0, (array) $this->assets->getJs());
$this->assets->reset(); $this->assets->reset();
$this->assets->addDirCss('/system/assets'); $this->assets->addDirCss('/system/assets');
$this->assertInternalType('array', $this->assets->getCss()); $this->assertIsArray($this->assets->getCss());
$this->assertGreaterThan(0, (array) $this->assets->getCss()); $this->assertGreaterThan(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs()); $this->assertIsArray($this->assets->getJs());
$this->assertCount(0, (array) $this->assets->getJs()); $this->assertCount(0, (array) $this->assets->getJs());
$this->assets->reset(); $this->assets->reset();
$this->assets->addDirJs('/system'); $this->assets->addDirJs('/system');
$this->assertInternalType('array', $this->assets->getCss()); $this->assertIsArray($this->assets->getCss());
$this->assertCount(0, (array) $this->assets->getCss()); $this->assertCount(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs()); $this->assertIsArray($this->assets->getJs());
$this->assertGreaterThan(0, (array) $this->assets->getJs()); $this->assertGreaterThan(0, (array) $this->assets->getJs());
$this->assets->reset(); $this->assets->reset();
$this->assets->addDirJs('/system/assets'); $this->assets->addDirJs('/system/assets');
$this->assertInternalType('array', $this->assets->getCss()); $this->assertIsArray($this->assets->getCss());
$this->assertCount(0, (array) $this->assets->getCss()); $this->assertCount(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs()); $this->assertIsArray($this->assets->getJs());
$this->assertGreaterThan(0, (array) $this->assets->getJs()); $this->assertGreaterThan(0, (array) $this->assets->getJs());
$this->assets->reset(); $this->assets->reset();
$this->assets->addDir('/system/assets'); $this->assets->addDir('/system/assets');
$this->assertInternalType('array', $this->assets->getCss()); $this->assertIsArray($this->assets->getCss());
$this->assertGreaterThan(0, (array) $this->assets->getCss()); $this->assertGreaterThan(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs()); $this->assertIsArray($this->assets->getJs());
$this->assertGreaterThan(0, (array) $this->assets->getJs()); $this->assertGreaterThan(0, (array) $this->assets->getJs());
//Use streams //Use streams
$this->assets->reset(); $this->assets->reset();
$this->assets->addDir('system://assets'); $this->assets->addDir('system://assets');
$this->assertInternalType('array', $this->assets->getCss()); $this->assertIsArray($this->assets->getCss());
$this->assertGreaterThan(0, (array) $this->assets->getCss()); $this->assertGreaterThan(0, (array) $this->assets->getCss());
$this->assertInternalType('array', $this->assets->getJs()); $this->assertIsArray($this->assets->getJs());
$this->assertGreaterThan(0, (array) $this->assets->getJs()); $this->assertGreaterThan(0, (array) $this->assets->getJs());
} }
} }

View File

@@ -16,14 +16,14 @@ class ComposerTest extends \Codeception\TestCase\Test
public function testGetComposerLocation() public function testGetComposerLocation()
{ {
$composerLocation = Composer::getComposerLocation(); $composerLocation = Composer::getComposerLocation();
$this->assertInternalType('string', $composerLocation); $this->assertIsString($composerLocation);
$this->assertSame('/', $composerLocation[0]); $this->assertSame('/', $composerLocation[0]);
} }
public function testGetComposerExecutor() public function testGetComposerExecutor()
{ {
$composerExecutor = Composer::getComposerExecutor(); $composerExecutor = Composer::getComposerExecutor();
$this->assertInternalType('string', $composerExecutor); $this->assertIsString($composerExecutor);
$this->assertSame('/', $composerExecutor[0]); $this->assertSame('/', $composerExecutor[0]);
$this->assertNotNull(strstr($composerExecutor, 'php')); $this->assertNotNull(strstr($composerExecutor, 'php'));
$this->assertNotNull(strstr($composerExecutor, 'composer')); $this->assertNotNull(strstr($composerExecutor, 'composer'));

View File

@@ -20,12 +20,12 @@ class BlueprintTest extends \Codeception\TestCase\Test
/** /**
* @depends testValidateStrict * @depends testValidateStrict
* @expectedException Grav\Common\Data\ValidationException
*/ */
public function testValidateStrictRequired() public function testValidateStrictRequired()
{ {
$blueprint = $this->loadBlueprint('strict'); $blueprint = $this->loadBlueprint('strict');
$this->expectException(\Grav\Common\Data\ValidationException::class);
$blueprint->validate([]); $blueprint->validate([]);
} }
@@ -41,7 +41,6 @@ class BlueprintTest extends \Codeception\TestCase\Test
/** /**
* @depends testValidateStrict * @depends testValidateStrict
* @expectedException Grav\Common\Data\ValidationException
*/ */
public function testValidateStrictExtraException() public function testValidateStrictExtraException()
{ {
@@ -52,6 +51,7 @@ class BlueprintTest extends \Codeception\TestCase\Test
$var = 'system.strict_mode.blueprint_strict_compat'; $var = 'system.strict_mode.blueprint_strict_compat';
$config->set($var, false); $config->set($var, false);
$this->expectException(\Grav\Common\Data\ValidationException::class);
$blueprint->validate(['test' => 'string', 'wrong' => 'field']); $blueprint->validate(['test' => 'string', 'wrong' => 'field']);
$config->set($var, true); $config->set($var, true);

View File

@@ -79,7 +79,7 @@ class GpmTest extends \Codeception\TestCase\Test
$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages); $dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertInternalType('array', $dependencies); $this->assertIsArray($dependencies);
$this->assertCount(5, $dependencies); $this->assertCount(5, $dependencies);
$this->assertSame('>=1.0.10', $dependencies['grav']); $this->assertSame('>=1.0.10', $dependencies['grav']);
@@ -92,7 +92,7 @@ class GpmTest extends \Codeception\TestCase\Test
$packages = ['admin', 'form']; $packages = ['admin', 'form'];
$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages); $dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertInternalType('array', $dependencies); $this->assertIsArray($dependencies);
$this->assertCount(5, $dependencies); $this->assertCount(5, $dependencies);
$this->assertSame('>=3.2', $dependencies['errors']); $this->assertSame('>=3.2', $dependencies['errors']);
@@ -123,7 +123,7 @@ class GpmTest extends \Codeception\TestCase\Test
$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages); $dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertInternalType('array', $dependencies); $this->assertIsArray($dependencies);
$this->assertCount(1, $dependencies); $this->assertCount(1, $dependencies);
$this->assertSame('>=4.0', $dependencies['errors']); $this->assertSame('>=4.0', $dependencies['errors']);
@@ -252,7 +252,7 @@ class GpmTest extends \Codeception\TestCase\Test
$dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages); $dependencies = $this->gpm->calculateMergedDependenciesOfPackages($packages);
$this->assertInternalType('array', $dependencies); $this->assertIsArray($dependencies);
$this->assertCount(7, $dependencies); $this->assertCount(7, $dependencies);
$this->assertSame('>=1.0.10', $dependencies['grav']); $this->assertSame('>=1.0.10', $dependencies['grav']);

View File

@@ -138,7 +138,7 @@ class UtilsTest extends \Codeception\TestCase\Test
public function testDateFormats() public function testDateFormats()
{ {
$dateFormats = Utils::dateFormats(); $dateFormats = Utils::dateFormats();
$this->assertInternalType('array', $dateFormats); $this->assertIsArray($dateFormats);
$this->assertContainsOnly('string', $dateFormats); $this->assertContainsOnly('string', $dateFormats);
$default_format = $this->grav['config']->get('system.pages.dateformat.default'); $default_format = $this->grav['config']->get('system.pages.dateformat.default');
@@ -270,7 +270,7 @@ class UtilsTest extends \Codeception\TestCase\Test
{ {
$timezones = Utils::timezones(); $timezones = Utils::timezones();
$this->assertInternalType('array', $timezones); $this->assertIsArray($timezones);
$this->assertContainsOnly('string', $timezones); $this->assertContainsOnly('string', $timezones);
} }
@@ -382,8 +382,8 @@ class UtilsTest extends \Codeception\TestCase\Test
public function testGetNonce() public function testGetNonce()
{ {
$this->assertInternalType('string', Utils::getNonce('test-action')); $this->assertIsString(Utils::getNonce('test-action'));
$this->assertInternalType('string', Utils::getNonce('test-action', true)); $this->assertIsString(Utils::getNonce('test-action', true));
$this->assertSame(Utils::getNonce('test-action'), Utils::getNonce('test-action')); $this->assertSame(Utils::getNonce('test-action'), Utils::getNonce('test-action'));
$this->assertNotSame(Utils::getNonce('test-action'), Utils::getNonce('test-action2')); $this->assertNotSame(Utils::getNonce('test-action'), Utils::getNonce('test-action2'));
} }