Commit c17a82f9 authored by alexpott's avatar alexpott

Issue #2490388 by hussainweb, Ankit Agrawal, joelpittet, dawehner:...

Issue #2490388 by hussainweb, Ankit Agrawal, joelpittet, dawehner: InfoParserUnitTest web test classes mislabeled as unit tests
parent 65d17485
<?php
/**
* @file
* Contains \Drupal\system\Tests\Extension\InfoParserUnitTest.
*/
namespace Drupal\system\Tests\Extension;
use Drupal\simpletest\KernelTestBase;
use Drupal\Core\Extension\InfoParser;
use Drupal\Core\Extension\InfoParserException;
use Drupal\Core\Updater\Updater;
/**
* Tests InfoParser class and exception.
*
* Files for this test are stored in core/modules/system/tests/fixtures and end
* with .info.txt instead of info.yml in order not not be considered as real
* extensions.
*
* @group Extension
*/
class InfoParserUnitTest extends KernelTestBase {
/**
* The InfoParser object.
*
* @var \Drupal\Core\Extension\InfoParser
*/
protected $infoParser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->infoParser = new InfoParser();
}
/**
* Tests the functionality of the infoParser object.
*/
public function testInfoParser() {
$info = $this->infoParser->parse('core/modules/system/tests/fixtures/does_not_exist.info.txt');
$this->assertTrue(empty($info), 'Non existing info.yml returns empty array.');
// Test that invalid YAML throws an exception and that message contains the
// filename that caused it.
$filename = 'core/modules/system/tests/fixtures/broken.info.txt';
try {
$this->infoParser->parse($filename);
$this->fail('Expected InfoParserException not thrown when reading broken.info.txt');
}
catch (InfoParserException $e) {
$this->assertTrue(strpos($e->getMessage(), $filename) !== FALSE, 'Exception message contains info.yml filename.');
}
// Tests that missing required keys are detected.
$filename = 'core/modules/system/tests/fixtures/missing_keys.info.txt';
try {
$this->infoParser->parse($filename);
$this->fail('Expected InfoParserException not thrown when reading missing_keys.info.txt');
}
catch (InfoParserException $e) {
$expected_message = "Missing required keys (type, core, name) in $filename.";
$this->assertEqual($e->getMessage(), $expected_message);
}
// Tests that a single missing required key is detected.
$filename = 'core/modules/system/tests/fixtures/missing_key.info.txt';
try {
$this->infoParser->parse($filename);
$this->fail('Expected InfoParserException not thrown when reading missing_key.info.txt');
}
catch (InfoParserException $e) {
$expected_message = "Missing required keys (type) in $filename.";
$this->assertEqual($e->getMessage(), $expected_message);
}
$info_values = $this->infoParser->parse('core/modules/system/tests/fixtures/common_test.info.txt');
$this->assertEqual($info_values['simple_string'], 'A simple string', 'Simple string value was parsed correctly.', 'System');
$this->assertEqual($info_values['version'], \Drupal::VERSION, 'Constant value was parsed correctly.', 'System');
$this->assertEqual($info_values['double_colon'], 'dummyClassName::', 'Value containing double-colon was parsed correctly.', 'System');
}
/**
* Tests project and child project showing correct title.
*
* @see https://drupal.org/node/2409515
*/
public function testGetProjectTitleWithChild() {
// Get the project title from it's directory. If it can't find the title
// it will choose the first project title in the directory.
$directory = \Drupal::root() . '/core/modules/system/tests/modules/module_handler_test_multiple';
$title = Updater::getProjectTitle($directory);
$this->assertEqual('module handler test multiple', $title);
}
}
<?php
/**
* @file
* Contains \Drupal\system\Tests\Extension\UpdaterTest.
*/
namespace Drupal\system\Tests\Extension;
use Drupal\simpletest\KernelTestBase;
use Drupal\Core\Updater\Updater;
/**
* Tests InfoParser class and exception.
*
* Files for this test are stored in core/modules/system/tests/fixtures and end
* with .info.txt instead of info.yml in order not not be considered as real
* extensions.
*
* @group Extension
*/
class UpdaterTest extends KernelTestBase {
/**
* Tests project and child project showing correct title.
*
* @see https://drupal.org/node/2409515
*/
public function testGetProjectTitleWithChild() {
// Get the project title from it's directory. If it can't find the title
// it will choose the first project title in the directory.
$directory = \Drupal::root() . '/core/modules/system/tests/modules/module_handler_test_multiple';
$title = Updater::getProjectTitle($directory);
$this->assertEqual('module handler test multiple', $title);
}
}
# info.yml for testing broken YAML parsing exception handling.
name: File
type: module
description: 'Defines a file field type.'
package: Core
version: VERSION
core: 8.x
dependencies::;;
- field
core: 8.x
name: common_test
type: module
description: 'testing info file parsing'
simple_string: 'A simple string'
version: "VERSION"
double_colon: dummyClassName::
# info.yml for testing missing type key.
name: File
description: 'Defines a file field type.'
package: Core
version: VERSION
core: 8.x
dependencies:
- field
# info.yml for testing missing name, description, and type keys.
package: Core
version: VERSION
dependencies:
- field
<?php
/**
* @file
* Contains \Drupal\system\Tests\Extension\InfoParserUnitTest.
*/
namespace Drupal\Tests\Core\Extension;
use Drupal\Core\Extension\InfoParser;
use Drupal\Tests\UnitTestCase;
use org\bovigo\vfs\vfsStream;
/**
* Tests InfoParser class and exception.
*
* Files for this test are stored in core/modules/system/tests/fixtures and end
* with .info.txt instead of info.yml in order not not be considered as real
* extensions.
*
* @coversDefaultClass \Drupal\Core\Extension\InfoParser
*
* @group Extension
*/
class InfoParserUnitTest extends UnitTestCase {
/**
* The InfoParser object.
*
* @var \Drupal\Core\Extension\InfoParser
*/
protected $infoParser;
/**
* {@inheritdoc}
*/
protected function setUp() {
parent::setUp();
$this->infoParser = new InfoParser();
}
/**
* Tests the functionality of the infoParser object.
*
* @covers ::parse
*/
public function testInfoParserNonExisting() {
vfsStream::setup('modules');
$info = $this->infoParser->parse(vfsStream::url('modules') . '/does_not_exist.info.txt');
$this->assertTrue(empty($info), 'Non existing info.yml returns empty array.');
}
/**
* Test if correct exception is thrown for a broken info file.
*
* @covers ::parse
*
* @expectedException \Drupal\Core\Extension\InfoParserException
* @expectedExceptionMessageRegExp #broken\.info\.txt#
*/
public function testInfoParserBroken() {
$broken_info = <<<BROKEN_INFO
# info.yml for testing broken YAML parsing exception handling.
name: File
type: module
description: 'Defines a file field type.'
package: Core
version: VERSION
core: 8.x
dependencies::;;
- field
BROKEN_INFO;
vfsStream::setup('modules');
vfsStream::create([
'fixtures' => [
'broken.info.txt' => $broken_info,
],
]);
$filename = vfsStream::url('modules/fixtures/broken.info.txt');
$this->infoParser->parse($filename);
}
/**
* Tests that missing required keys are detected.
*
* @covers ::parse
*
* @expectedException \Drupal\Core\Extension\InfoParserException
* @expectedExceptionMessageRegExp #Missing required keys \(type, core, name\) in .+?missing_keys\.info\.txt#
*/
public function testInfoParserMissingKeys() {
$missing_keys = <<<MISSINGKEYS
# info.yml for testing missing name, description, and type keys.
package: Core
version: VERSION
dependencies:
- field
MISSINGKEYS;
vfsStream::setup('modules');
vfsStream::create([
'fixtures' => [
'missing_keys.info.txt' => $missing_keys,
],
]);
$filename = vfsStream::url('modules/fixtures/missing_keys.info.txt');
$this->infoParser->parse($filename);
}
/**
* Tests that missing required key is detected.
*
* @covers ::parse
*
* @expectedException \Drupal\Core\Extension\InfoParserException
* @expectedExceptionMessageRegExp #Missing required keys \(type\) in .+?missing_key\.info\.txt#
*/
public function testInfoParserMissingKey() {
$missing_key = <<<MISSINGKEY
# info.yml for testing missing type key.
name: File
description: 'Defines a file field type.'
package: Core
version: VERSION
core: 8.x
dependencies:
- field
MISSINGKEY;
vfsStream::setup('modules');
vfsStream::create([
'fixtures' => [
'missing_key.info.txt' => $missing_key,
],
]);
$filename = vfsStream::url('modules/fixtures/missing_key.info.txt');
$this->infoParser->parse($filename);
}
/**
* Tests common info file.
*
* @covers ::parse
*/
public function testInfoParserCommonInfo() {
$common = <<<COMMONTEST
core: 8.x
name: common_test
type: module
description: 'testing info file parsing'
simple_string: 'A simple string'
version: "VERSION"
double_colon: dummyClassName::
COMMONTEST;
vfsStream::setup('modules');
vfsStream::create([
'fixtures' => [
'common_test.info.txt' => $common,
],
]);
$info_values = $this->infoParser->parse(vfsStream::url('modules/fixtures/common_test.info.txt'));
$this->assertEquals($info_values['simple_string'], 'A simple string', 'Simple string value was parsed correctly.');
$this->assertEquals($info_values['version'], \Drupal::VERSION, 'Constant value was parsed correctly.');
$this->assertEquals($info_values['double_colon'], 'dummyClassName::', 'Value containing double-colon was parsed correctly.');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment