Issue #2787577 by alexpott, dawehner: When tests use multiple namespaces they should do so in a coding standards compliant way

8.3.x
Nathaniel Catchpole 2016-08-22 17:10:39 +01:00
parent 37010da991
commit 3c42666bfc
20 changed files with 205 additions and 223 deletions

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\aggregator\Unit\Plugin {
namespace Drupal\Tests\aggregator\Unit\Plugin;
use Drupal\aggregator\Form\SettingsForm;
use Drupal\Core\Form\FormState;
@ -105,11 +105,9 @@ class AggregatorPluginSettingsBaseTest extends UnitTestCase {
}
}
// @todo Delete after https://www.drupal.org/node/2278383 is in.
namespace Drupal\Core\Form;
namespace {
// @todo Delete after https://www.drupal.org/node/1858196 is in.
if (!function_exists('drupal_set_message')) {
function drupal_set_message() {}
}
if (!function_exists('drupal_set_message')) {
function drupal_set_message() {}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\comment\Unit {
namespace Drupal\Tests\comment\Unit;
use Drupal\comment\CommentLinkBuilder;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
@ -319,12 +319,10 @@ class CommentLinkBuilderTest extends UnitTestCase {
}
}
namespace Drupal\comment;
namespace {
if (!function_exists('history_read')) {
function history_read() {
return 0;
}
if (!function_exists('history_read')) {
function history_read() {
return 0;
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\language\Unit {
namespace Drupal\Tests\language\Unit;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\LanguageInterface;
@ -252,13 +252,11 @@ class LanguageNegotiationUrlTest extends UnitTestCase {
}
}
// @todo Remove as part of https://www.drupal.org/node/2481833.
namespace {
if (!function_exists('base_path')) {
function base_path() {
return '/';
}
namespace Drupal\language\Plugin\LanguageNegotiation;
if (!function_exists('base_path')) {
function base_path() {
return '/';
}
}

View File

@ -5,7 +5,7 @@
* Contains \Drupal\Tests\simpletest\Unit\TestInfoParsingTest.
*/
namespace Drupal\Tests\simpletest\Unit {
namespace Drupal\Tests\simpletest\Unit;
use Composer\Autoload\ClassLoader;
use Drupal\Core\Extension\Extension;
@ -413,9 +413,7 @@ class TestTestDiscovery extends TestDiscovery {
}
}
namespace Drupal\simpletest\Tests {
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
@ -426,5 +424,3 @@ use Drupal\simpletest\WebTestBase;
*/
class ExampleSimpleTest extends WebTestBase {
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\views\Unit\Controller {
namespace Drupal\Tests\views\Unit\Controller;
use Drupal\Core\Render\RenderContext;
use Drupal\Tests\UnitTestCase;
@ -358,5 +358,3 @@ class ViewAjaxControllerTest extends UnitTestCase {
}
}
}

View File

@ -5,7 +5,7 @@
* Contains \Drupal\Tests\views\Unit\EntityViewsDataTest.
*/
namespace Drupal\Tests\views\Unit {
namespace Drupal\Tests\views\Unit;
use Drupal\Core\Config\Entity\ConfigEntityType;
use Drupal\Core\Entity\ContentEntityType;
@ -1100,12 +1100,10 @@ class TestEntityType extends EntityType {
}
}
namespace Drupal\entity_test\Entity;
namespace Drupal\entity_test\Entity {
if (!function_exists('t')) {
function t($string, array $args = []) {
return strtr($string, $args);
}
if (!function_exists('t')) {
function t($string, array $args = []) {
return strtr($string, $args);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\views\Unit\Plugin\Block {
namespace Drupal\Tests\views\Unit\Plugin\Block;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase;
@ -198,13 +198,11 @@ class ViewsBlockTest extends UnitTestCase {
}
}
// @todo https://www.drupal.org/node/2571679 replace
// views_add_contextual_links().
namespace Drupal\views\Plugin\Block;
namespace {
// @todo https://www.drupal.org/node/2571679 replace
// views_add_contextual_links().
if (!function_exists('views_add_contextual_links')) {
function views_add_contextual_links() {
}
if (!function_exists('views_add_contextual_links')) {
function views_add_contextual_links() {
}
}

View File

@ -5,7 +5,7 @@
* Contains \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTest.
*/
namespace Drupal\Tests\views\Unit\Plugin\field {
namespace Drupal\Tests\views\Unit\Plugin\field;
use Drupal\Core\GeneratedUrl;
use Drupal\Core\Language\Language;
@ -692,12 +692,12 @@ class FieldPluginBaseTestField extends FieldPluginBase {
}
}
}
// @todo Remove as part of https://www.drupal.org/node/2529170.
namespace {
if (!function_exists('base_path')) {
function base_path() {
return '/';
}
namespace Drupal\views\Plugin\views\field;
if (!function_exists('base_path')) {
function base_path() {
return '/';
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\views\Unit\Plugin\views\field {
namespace Drupal\Tests\views\Unit\Plugin\views\field;
use Drupal\Tests\UnitTestCase;
use Drupal\views\Plugin\views\field\EntityOperations;
@ -165,5 +165,3 @@ class EntityOperationsUnitTest extends UnitTestCase {
}
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\views\Unit\Routing {
namespace Drupal\Tests\views\Unit\Routing;
use Drupal\Core\Routing\RouteMatch;
use Drupal\Tests\UnitTestCase;
@ -177,13 +177,11 @@ class ViewPageControllerTest extends UnitTestCase {
}
}
// @todo https://www.drupal.org/node/2571679 replace
// views_add_contextual_links().
namespace Drupal\views\Routing;
namespace {
// @todo https://www.drupal.org/node/2571679 replace
// views_add_contextual_links()
if (!function_exists('views_add_contextual_links')) {
function views_add_contextual_links() {
}
if (!function_exists('views_add_contextual_links')) {
function views_add_contextual_links() {
}
}

View File

@ -5,7 +5,7 @@
* Contains \Drupal\Tests\Component\Utility\ArgumentsResolverTest.
*/
namespace Drupal\Tests\Component\Utility {
namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\ArgumentsResolver;
use Drupal\Tests\UnitTestCase;
@ -187,7 +187,7 @@ class ArgumentsResolverTest extends UnitTestCase {
$data = [];
$data[] = [function($foo) {}];
$data[] = [[new TestClass(), 'access']];
$data[] = ['test_access_arguments_resolver_access'];
$data[] = ['Drupal\Tests\Component\Utility\test_access_arguments_resolver_access'];
return $data;
}
@ -214,9 +214,5 @@ interface TestInterface1 {
interface TestInterface2 {
}
}
namespace {
function test_access_arguments_resolver_access($foo) {
}
function test_access_arguments_resolver_access($foo) {
}

View File

@ -1,41 +1,6 @@
<?php
namespace {
/**
* CssCollectionRenderer uses file_create_url() & file_url_transform_relative(),
* which *are* available when using the Simpletest test runner, but not when
* using the PHPUnit test runner; hence this hack.
*/
if (!function_exists('file_create_url')) {
/**
* Temporary mock for file_create_url(), until that is moved into
* Component/Utility.
*/
function file_create_url($uri) {
return 'file_create_url:' . $uri;
}
}
if (!function_exists('file_url_transform_relative')) {
/**
* Temporary mock of file_url_transform_relative, until that is moved into
* Component/Utility.
*/
function file_url_transform_relative($uri) {
return 'file_url_transform_relative:' . $uri;
}
}
}
namespace Drupal\Tests\Core\Asset {
namespace Drupal\Tests\Core\Asset;
use Drupal\Core\Asset\CssCollectionRenderer;
use Drupal\Tests\UnitTestCase;
@ -502,4 +467,53 @@ class CssCollectionRendererUnitTest extends UnitTestCase {
}
}
/**
* Temporary mock for file_create_url(), until that is moved into
* Component/Utility.
*/
if (!function_exists('Drupal\Tests\Core\Asset\file_create_url')) {
function file_create_url($uri) {
return 'file_create_url:' . $uri;
}
}
/**
* Temporary mock of file_url_transform_relative, until that is moved into
* Component/Utility.
*/
if (!function_exists('Drupal\Tests\Core\Asset\file_url_transform_relative')) {
function file_url_transform_relative($uri) {
return 'file_url_transform_relative:' . $uri;
}
}
/**
* CssCollectionRenderer uses file_create_url() & file_url_transform_relative(),
* which *are* available when using the Simpletest test runner, but not when
* using the PHPUnit test runner; hence this hack.
*/
namespace Drupal\Core\Asset;
if (!function_exists('Drupal\Core\Asset\file_create_url')) {
/**
* Temporary mock for file_create_url(), until that is moved into
* Component/Utility.
*/
function file_create_url($uri) {
return \Drupal\Tests\Core\Asset\file_create_url($uri);
}
}
if (!function_exists('Drupal\Core\Asset\file_url_transform_relative')) {
/**
* Temporary mock of file_url_transform_relative, until that is moved into
* Component/Utility.
*/
function file_url_transform_relative($uri) {
return \Drupal\Tests\Core\Asset\file_url_transform_relative($uri);
}
}

View File

@ -1,48 +1,6 @@
<?php
namespace {
/**
* CssOptimizer uses file_create_url(), file_uri_scheme() and
* file_url_transform_relative(), which *are* available when using the
* Simpletest test runner, but not when using the PHPUnit test runner; hence
* this hack.
*/
if (!function_exists('file_create_url')) {
/**
* Temporary mock for file_create_url(), until that is moved into
* Component/Utility.
*/
function file_create_url($uri) {
return 'file_create_url:' . $uri;
}
}
if (!function_exists('file_uri_scheme')) {
function file_uri_scheme($uri) {
return FALSE;
}
}
if (!function_exists('file_url_transform_relative')) {
/**
* Temporary mock of file_url_transform_relative, until that is moved into
* Component/Utility.
*/
function file_url_transform_relative($uri) {
return 'file_url_transform_relative:' . $uri;
}
}
}
namespace Drupal\Tests\Core\Asset {
namespace Drupal\Tests\Core\Asset;
use Drupal\Core\Asset\CssOptimizer;
use Drupal\Tests\UnitTestCase;
@ -292,4 +250,60 @@ class CssOptimizerUnitTest extends UnitTestCase {
}
}
/**
* Temporary mock for file_create_url(), until that is moved into
* Component/Utility.
*/
if (!function_exists('Drupal\Tests\Core\Asset\file_create_url')) {
function file_create_url($uri) {
return 'file_create_url:' . $uri;
}
}
/**
* Temporary mock of file_url_transform_relative, until that is moved into
* Component/Utility.
*/
if (!function_exists('Drupal\Tests\Core\Asset\file_url_transform_relative')) {
function file_url_transform_relative($uri) {
return 'file_url_transform_relative:' . $uri;
}
}
/**
* CssCollectionRenderer uses file_create_url() & file_url_transform_relative(),
* which *are* available when using the Simpletest test runner, but not when
* using the PHPUnit test runner; hence this hack.
*/
namespace Drupal\Core\Asset;
if (!function_exists('Drupal\Core\Asset\file_create_url')) {
/**
* Temporary mock for file_create_url(), until that is moved into
* Component/Utility.
*/
function file_create_url($uri) {
return \Drupal\Tests\Core\Asset\file_create_url($uri);
}
}
if (!function_exists('Drupal\Core\Asset\file_url_transform_relative')) {
/**
* Temporary mock of file_url_transform_relative, until that is moved into
* Component/Utility.
*/
function file_url_transform_relative($uri) {
return \Drupal\Tests\Core\Asset\file_url_transform_relative($uri);
}
}
if (!function_exists('Drupal\Core\Asset\file_uri_scheme')) {
function file_uri_scheme($uri) {
return FALSE;
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\Core\Config\Entity {
namespace Drupal\Tests\Core\Config\Entity;
use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
@ -941,12 +941,11 @@ class ConfigEntityStorageTest extends UnitTestCase {
}
namespace Drupal\Core\Config\Entity;
if (!defined('SAVED_NEW')) {
define('SAVED_NEW', 1);
}
namespace {
if (!defined('SAVED_NEW')) {
define('SAVED_NEW', 1);
}
if (!defined('SAVED_UPDATED')) {
define('SAVED_UPDATED', 2);
}
if (!defined('SAVED_UPDATED')) {
define('SAVED_UPDATED', 2);
}

View File

@ -5,7 +5,7 @@
* Contains \Drupal\Tests\Core\Entity\EntityResolverManagerTest.
*/
namespace Drupal\Tests\Core\Entity {
namespace Drupal\Tests\Core\Entity;
use Drupal\Core\Entity\Entity;
use Drupal\Core\Entity\EntityInterface;
@ -90,7 +90,7 @@ class EntityResolverManagerTest extends UnitTestCase {
public function providerTestSetRouteOptionsWithStandardRoute() {
return array(
array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethod'),
array('test_function_controller'),
array('Drupal\Tests\Core\Entity\test_function_controller'),
);
}
@ -120,7 +120,7 @@ class EntityResolverManagerTest extends UnitTestCase {
public function providerTestSetRouteOptionsWithStandardRouteWithArgument() {
return array(
array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethodWithArgument'),
array('test_function_controller_with_argument'),
array('Drupal\Tests\Core\Entity\test_function_controller_with_argument'),
);
}
@ -150,7 +150,7 @@ class EntityResolverManagerTest extends UnitTestCase {
public function providerTestSetRouteOptionsWithContentController() {
return array(
array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethodWithArgument'),
array('test_function_controller_with_argument'),
array('Drupal\Tests\Core\Entity\test_function_controller_with_argument'),
);
}
@ -183,7 +183,7 @@ class EntityResolverManagerTest extends UnitTestCase {
public function providerTestSetRouteOptionsWithEntityTypeNoUpcasting() {
return array(
array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerWithEntityNoUpcasting'),
array('test_function_controller_no_upcasting'),
array('Drupal\Tests\Core\Entity\test_function_controller_no_upcasting'),
);
}
@ -217,7 +217,7 @@ class EntityResolverManagerTest extends UnitTestCase {
public function providerTestSetRouteOptionsWithEntityTypeUpcasting() {
return array(
array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerWithEntityUpcasting'),
array('test_function_controller_entity_upcasting'),
array('Drupal\Tests\Core\Entity\test_function_controller_entity_upcasting'),
);
}
@ -547,21 +547,14 @@ class BasicFormNoContainerInjectionInterface implements FormInterface {
}
function test_function_controller() {
}
namespace {
use Drupal\Core\Entity\EntityInterface;
function test_function_controller() {
}
function test_function_controller_with_argument($argument) {
}
function test_function_controller_no_upcasting($entity_test) {
}
function test_function_controller_entity_upcasting(EntityInterface $entity_test) {
}
function test_function_controller_with_argument($argument) {
}
function test_function_controller_no_upcasting($entity_test) {
}
function test_function_controller_entity_upcasting(EntityInterface $entity_test) {
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\Core\Entity\KeyValueStore {
namespace Drupal\Tests\Core\Entity\KeyValueStore;
use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
@ -696,13 +696,11 @@ class KeyValueEntityStorageTest extends UnitTestCase {
}
}
namespace Drupal\Core\Entity\KeyValueStore;
namespace {
if (!defined('SAVED_NEW')) {
define('SAVED_NEW', 1);
}
if (!defined('SAVED_UPDATED')) {
define('SAVED_UPDATED', 2);
}
if (!defined('SAVED_NEW')) {
define('SAVED_NEW', 1);
}
if (!defined('SAVED_UPDATED')) {
define('SAVED_UPDATED', 2);
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\Core\Plugin\Discovery {
namespace Drupal\Tests\Core\Plugin\Discovery;
use Drupal\Core\Plugin\Discovery\HookDiscovery;
use Drupal\Tests\UnitTestCase;
@ -61,11 +61,11 @@ class HookDiscoveryTest extends UnitTestCase {
$this->moduleHandler->expects($this->at(1))
->method('invoke')
->with('hook_discovery_test', 'test_plugin')
->will($this->returnValue(hook_discovery_test_test_plugin()));
->will($this->returnValue($this->hookDiscoveryTestTestPlugin()));
$this->moduleHandler->expects($this->at(2))
->method('invoke')
->with('hook_discovery_test2', 'test_plugin')
->will($this->returnValue(hook_discovery_test2_test_plugin()));
->will($this->returnValue($this->hookDiscoveryTest2TestPlugin()));
$definitions = $this->hookDiscovery->getDefinitions();
@ -94,8 +94,8 @@ class HookDiscoveryTest extends UnitTestCase {
$this->moduleHandler->expects($this->any())
->method('invoke')
->will($this->returnValueMap(array(
array('hook_discovery_test', 'test_plugin', array(), hook_discovery_test_test_plugin()),
array('hook_discovery_test2', 'test_plugin', array(), hook_discovery_test2_test_plugin()),
array('hook_discovery_test', 'test_plugin', array(), $this->hookDiscoveryTestTestPlugin()),
array('hook_discovery_test2', 'test_plugin', array(), $this->hookDiscoveryTest2TestPlugin()),
)
));
@ -129,20 +129,16 @@ class HookDiscoveryTest extends UnitTestCase {
$this->hookDiscovery->getDefinition('test_non_existant', TRUE);
}
}
}
namespace {
function hook_discovery_test_test_plugin() {
protected function hookDiscoveryTestTestPlugin() {
return array(
'test_id_1' => array('class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Apple'),
'test_id_2' => array('class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Orange'),
);
}
function hook_discovery_test2_test_plugin() {
protected function hookDiscoveryTest2TestPlugin() {
return array(
'test_id_3' => array('class' => 'Drupal\plugin_test\Plugin\plugin_test\fruit\Cherry'),
);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\Core\Render\Element {
namespace Drupal\Tests\Core\Render\Element;
use Drupal\Core\Form\FormState;
use Drupal\Core\Form\FormStateInterface;
@ -103,12 +103,10 @@ class MachineNameTest extends UnitTestCase {
}
}
namespace Drupal\Core\Render\Element;
namespace Drupal\Core\Render\Element {
if (!function_exists('t')) {
function t($string, array $args = []) {
return strtr($string, $args);
}
if (!function_exists('t')) {
function t($string, array $args = []) {
return strtr($string, $args);
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\Core\Session {
namespace Drupal\Tests\Core\Session;
use Drupal\Component\Utility\Crypt;
use Drupal\Core\Session\PermissionsHashGenerator;
@ -246,19 +246,15 @@ class PermissionsHashGeneratorTest extends UnitTestCase {
}
}
namespace Drupal\Core\Session;
namespace {
// @todo remove once user_role_permissions() can be injected.
if (!function_exists('user_role_permissions')) {
function user_role_permissions(array $roles) {
$role_permissions = array();
foreach ($roles as $rid) {
$role_permissions[$rid] = array();
}
return $role_permissions;
// @todo remove once user_role_permissions() can be injected.
if (!function_exists('user_role_permissions')) {
function user_role_permissions(array $roles) {
$role_permissions = array();
foreach ($roles as $rid) {
$role_permissions[$rid] = array();
}
return $role_permissions;
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Drupal\Tests\Core\Utility {
namespace Drupal\Tests\Core\Utility;
use Drupal\Component\Render\MarkupInterface;
use Drupal\Core\GeneratedNoLink;
@ -596,5 +596,3 @@ class LinkGeneratorTest extends UnitTestCase {
}
}
}