Commit 3c42666b authored by catch's avatar catch

Issue #2787577 by alexpott, dawehner: When tests use multiple namespaces they...

Issue #2787577 by alexpott, dawehner: When tests use multiple namespaces they should do so in a coding standards compliant way
parent 37010da9
<?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 @@ public function testSettingsForm() {
}
}
// @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() {}
}
<?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 @@ protected function getMockNode($has_field, $comment_status, $form_location, $com
}
}
namespace Drupal\comment;
namespace {
if (!function_exists('history_read')) {
function history_read() {
return 0;
}
if (!function_exists('history_read')) {
function history_read() {
return 0;
}
}
<?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 @@ public function providerTestDomain() {
}
}
// @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 '/';
}
}
......@@ -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 @@ public function providerTestGetPhpunitTestSuite() {
}
}
namespace Drupal\simpletest\Tests {
namespace Drupal\simpletest\Tests;
use Drupal\simpletest\WebTestBase;
......@@ -426,5 +424,3 @@ public function providerTestGetPhpunitTestSuite() {
*/
class ExampleSimpleTest extends WebTestBase {
}
}
<?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 @@ protected function assertViewResultCommand(ViewAjaxResponse $response, $position
}
}
}
......@@ -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 @@ public function setKey($key, $value) {
}
}
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);
}
}
<?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 @@ public function testBuildFailed() {
}
}
// @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() {
}
}
......@@ -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 @@ public function setLinkGenerator(LinkGeneratorInterface $link_generator) {
}
}
}
// @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 '/';
}
}
<?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 @@ public function testRenderWithoutDestination() {
}
}
}
<?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 @@ public function testHandleWithArgumentsOnOverriddenRouteWithUpcasting() {
}
}
// @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() {
}
}
......@@ -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 @@ public function providerTestHandleUnresolvedArgument() {
$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) {
}
<?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 @@ function testRenderInvalidType() {
}
}
/**
* 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);
}
}
<?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 @@ function testTypeExternal() {
}
}
/**
* 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;
}
}
<?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 @@ public function getMockEntity(array $values = array(), $methods = array()) {
}
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);
}
......@@ -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 @@ public function testSetRouteOptionsWithStandardRoute($controller) {
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 @@ public function testSetRouteOptionsWithStandardRouteWithArgument($controller) {
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 @@ public function testSetRouteOptionsWithContentController($controller) {
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 @@ public function testSetRouteOptionsWithEntityTypeNoUpcasting($controller) {
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 @@ public function testSetRouteOptionsWithEntityTypeUpcasting($controller) {
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 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
}
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_with_argument($argument) {
}
function test_function_controller_no_upcasting($entity_test) {
}
function test_function_controller_no_upcasting($entity_test) {
}
function test_function_controller_entity_upcasting(EntityInterface $entity_test) {
}
function test_function_controller_entity_upcasting(EntityInterface $entity_test) {
}
<?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 @@ public function getMockEntity($class = 'Drupal\Core\Entity\Entity', array $argum
}
}
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);
}
<?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 @@ public function testGetDefinitions() {
$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 @@ public function testGetDefinition() {
$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 @@ public function testGetDefinitionWithUnknownID() {
$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'),
);
}
}
<?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 @@ public function testProcessMachineName() {
}
}
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);
}
}
<?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 @@ public function testGenerateNoCache() {
}
}
namespace {
namespace Drupal\Core\Session;
// @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) {