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 <?php
namespace Drupal\Tests\aggregator\Unit\Plugin { namespace Drupal\Tests\aggregator\Unit\Plugin;
use Drupal\aggregator\Form\SettingsForm; use Drupal\aggregator\Form\SettingsForm;
use Drupal\Core\Form\FormState; use Drupal\Core\Form\FormState;
...@@ -105,11 +105,9 @@ public function testSettingsForm() { ...@@ -105,11 +105,9 @@ public function testSettingsForm() {
} }
} // @todo Delete after https://www.drupal.org/node/2278383 is in.
namespace Drupal\Core\Form;
namespace { if (!function_exists('drupal_set_message')) {
// @todo Delete after https://www.drupal.org/node/1858196 is in. function drupal_set_message() {}
if (!function_exists('drupal_set_message')) {
function drupal_set_message() {}
}
} }
<?php <?php
namespace Drupal\Tests\comment\Unit { namespace Drupal\Tests\comment\Unit;
use Drupal\comment\CommentLinkBuilder; use Drupal\comment\CommentLinkBuilder;
use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface; use Drupal\comment\Plugin\Field\FieldType\CommentItemInterface;
...@@ -319,12 +319,10 @@ protected function getMockNode($has_field, $comment_status, $form_location, $com ...@@ -319,12 +319,10 @@ protected function getMockNode($has_field, $comment_status, $form_location, $com
} }
} namespace Drupal\comment;
namespace { if (!function_exists('history_read')) {
if (!function_exists('history_read')) { function history_read() {
function history_read() { return 0;
return 0;
}
} }
} }
<?php <?php
namespace Drupal\Tests\language\Unit { namespace Drupal\Tests\language\Unit;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Language\LanguageInterface; use Drupal\Core\Language\LanguageInterface;
...@@ -252,13 +252,11 @@ public function providerTestDomain() { ...@@ -252,13 +252,11 @@ public function providerTestDomain() {
} }
}
// @todo Remove as part of https://www.drupal.org/node/2481833. // @todo Remove as part of https://www.drupal.org/node/2481833.
namespace { namespace Drupal\language\Plugin\LanguageNegotiation;
if (!function_exists('base_path')) {
function base_path() { if (!function_exists('base_path')) {
return '/'; function base_path() {
} return '/';
} }
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\simpletest\Unit\TestInfoParsingTest. * Contains \Drupal\Tests\simpletest\Unit\TestInfoParsingTest.
*/ */
namespace Drupal\Tests\simpletest\Unit { namespace Drupal\Tests\simpletest\Unit;
use Composer\Autoload\ClassLoader; use Composer\Autoload\ClassLoader;
use Drupal\Core\Extension\Extension; use Drupal\Core\Extension\Extension;
...@@ -413,9 +413,7 @@ public function providerTestGetPhpunitTestSuite() { ...@@ -413,9 +413,7 @@ public function providerTestGetPhpunitTestSuite() {
} }
} namespace Drupal\simpletest\Tests;
namespace Drupal\simpletest\Tests {
use Drupal\simpletest\WebTestBase; use Drupal\simpletest\WebTestBase;
...@@ -426,5 +424,3 @@ public function providerTestGetPhpunitTestSuite() { ...@@ -426,5 +424,3 @@ public function providerTestGetPhpunitTestSuite() {
*/ */
class ExampleSimpleTest extends WebTestBase { class ExampleSimpleTest extends WebTestBase {
} }
}
<?php <?php
namespace Drupal\Tests\views\Unit\Controller { namespace Drupal\Tests\views\Unit\Controller;
use Drupal\Core\Render\RenderContext; use Drupal\Core\Render\RenderContext;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
...@@ -358,5 +358,3 @@ protected function assertViewResultCommand(ViewAjaxResponse $response, $position ...@@ -358,5 +358,3 @@ protected function assertViewResultCommand(ViewAjaxResponse $response, $position
} }
} }
}
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\views\Unit\EntityViewsDataTest. * 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\Config\Entity\ConfigEntityType;
use Drupal\Core\Entity\ContentEntityType; use Drupal\Core\Entity\ContentEntityType;
...@@ -1100,12 +1100,10 @@ public function setKey($key, $value) { ...@@ -1100,12 +1100,10 @@ public function setKey($key, $value) {
} }
} namespace Drupal\entity_test\Entity;
namespace Drupal\entity_test\Entity { if (!function_exists('t')) {
if (!function_exists('t')) { function t($string, array $args = []) {
function t($string, array $args = []) { return strtr($string, $args);
return strtr($string, $args);
}
} }
} }
<?php <?php
namespace Drupal\Tests\views\Unit\Plugin\Block { namespace Drupal\Tests\views\Unit\Plugin\Block;
use Drupal\Core\DependencyInjection\ContainerBuilder; use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
...@@ -198,13 +198,11 @@ public function testBuildFailed() { ...@@ -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 { if (!function_exists('views_add_contextual_links')) {
// @todo https://www.drupal.org/node/2571679 replace function views_add_contextual_links() {
// views_add_contextual_links().
if (!function_exists('views_add_contextual_links')) {
function views_add_contextual_links() {
}
} }
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\views\Unit\Plugin\field\FieldPluginBaseTest. * 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\GeneratedUrl;
use Drupal\Core\Language\Language; use Drupal\Core\Language\Language;
...@@ -692,12 +692,12 @@ public function setLinkGenerator(LinkGeneratorInterface $link_generator) { ...@@ -692,12 +692,12 @@ public function setLinkGenerator(LinkGeneratorInterface $link_generator) {
} }
} }
}
// @todo Remove as part of https://www.drupal.org/node/2529170. // @todo Remove as part of https://www.drupal.org/node/2529170.
namespace { namespace Drupal\views\Plugin\views\field;
if (!function_exists('base_path')) {
function base_path() { if (!function_exists('base_path')) {
return '/'; function base_path() {
} return '/';
} }
} }
<?php <?php
namespace Drupal\Tests\views\Unit\Plugin\views\field { namespace Drupal\Tests\views\Unit\Plugin\views\field;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
use Drupal\views\Plugin\views\field\EntityOperations; use Drupal\views\Plugin\views\field\EntityOperations;
...@@ -165,5 +165,3 @@ public function testRenderWithoutDestination() { ...@@ -165,5 +165,3 @@ public function testRenderWithoutDestination() {
} }
} }
}
<?php <?php
namespace Drupal\Tests\views\Unit\Routing { namespace Drupal\Tests\views\Unit\Routing;
use Drupal\Core\Routing\RouteMatch; use Drupal\Core\Routing\RouteMatch;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
...@@ -177,13 +177,11 @@ public function testHandleWithArgumentsOnOverriddenRouteWithUpcasting() { ...@@ -177,13 +177,11 @@ public function testHandleWithArgumentsOnOverriddenRouteWithUpcasting() {
} }
} // @todo https://www.drupal.org/node/2571679 replace
// views_add_contextual_links().
namespace Drupal\views\Routing;
namespace { if (!function_exists('views_add_contextual_links')) {
// @todo https://www.drupal.org/node/2571679 replace function views_add_contextual_links() {
// views_add_contextual_links()
if (!function_exists('views_add_contextual_links')) {
function views_add_contextual_links() {
}
} }
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\Component\Utility\ArgumentsResolverTest. * Contains \Drupal\Tests\Component\Utility\ArgumentsResolverTest.
*/ */
namespace Drupal\Tests\Component\Utility { namespace Drupal\Tests\Component\Utility;
use Drupal\Component\Utility\ArgumentsResolver; use Drupal\Component\Utility\ArgumentsResolver;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
...@@ -187,7 +187,7 @@ public function providerTestHandleUnresolvedArgument() { ...@@ -187,7 +187,7 @@ public function providerTestHandleUnresolvedArgument() {
$data = []; $data = [];
$data[] = [function($foo) {}]; $data[] = [function($foo) {}];
$data[] = [[new TestClass(), 'access']]; $data[] = [[new TestClass(), 'access']];
$data[] = ['test_access_arguments_resolver_access']; $data[] = ['Drupal\Tests\Component\Utility\test_access_arguments_resolver_access'];
return $data; return $data;
} }
...@@ -214,9 +214,5 @@ interface TestInterface1 { ...@@ -214,9 +214,5 @@ interface TestInterface1 {
interface TestInterface2 { interface TestInterface2 {
} }
} function test_access_arguments_resolver_access($foo) {
namespace {
function test_access_arguments_resolver_access($foo) {
}
} }
<?php <?php
namespace { namespace Drupal\Tests\Core\Asset;
/**
* 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 {
use Drupal\Core\Asset\CssCollectionRenderer; use Drupal\Core\Asset\CssCollectionRenderer;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
...@@ -502,4 +467,53 @@ function testRenderInvalidType() { ...@@ -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 <?php
namespace { namespace Drupal\Tests\Core\Asset;
/**
* 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 {
use Drupal\Core\Asset\CssOptimizer; use Drupal\Core\Asset\CssOptimizer;
use Drupal\Tests\UnitTestCase; use Drupal\Tests\UnitTestCase;
...@@ -292,4 +250,60 @@ function testTypeExternal() { ...@@ -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 <?php
namespace Drupal\Tests\Core\Config\Entity { namespace Drupal\Tests\Core\Config\Entity;
use Drupal\Core\Cache\Cache; use Drupal\Core\Cache\Cache;
use Drupal\Core\Config\Entity\ConfigEntityInterface; use Drupal\Core\Config\Entity\ConfigEntityInterface;
...@@ -941,12 +941,11 @@ public function getMockEntity(array $values = array(), $methods = array()) { ...@@ -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_UPDATED')) {
if (!defined('SAVED_NEW')) { define('SAVED_UPDATED', 2);
define('SAVED_NEW', 1);
}
if (!defined('SAVED_UPDATED')) {
define('SAVED_UPDATED', 2);
}
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* Contains \Drupal\Tests\Core\Entity\EntityResolverManagerTest. * 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\Entity;
use Drupal\Core\Entity\EntityInterface; use Drupal\Core\Entity\EntityInterface;
...@@ -90,7 +90,7 @@ public function testSetRouteOptionsWithStandardRoute($controller) { ...@@ -90,7 +90,7 @@ public function testSetRouteOptionsWithStandardRoute($controller) {
public function providerTestSetRouteOptionsWithStandardRoute() { public function providerTestSetRouteOptionsWithStandardRoute() {
return array( return array(
array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethod'), 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) { ...@@ -120,7 +120,7 @@ public function testSetRouteOptionsWithStandardRouteWithArgument($controller) {
public function providerTestSetRouteOptionsWithStandardRouteWithArgument() { public function providerTestSetRouteOptionsWithStandardRouteWithArgument() {
return array( return array(
array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethodWithArgument'), 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) { ...@@ -150,7 +150,7 @@ public function testSetRouteOptionsWithContentController($controller) {
public function providerTestSetRouteOptionsWithContentController() { public function providerTestSetRouteOptionsWithContentController() {
return array( return array(
array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerMethodWithArgument'), 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) { ...@@ -183,7 +183,7 @@ public function testSetRouteOptionsWithEntityTypeNoUpcasting($controller) {
public function providerTestSetRouteOptionsWithEntityTypeNoUpcasting() { public function providerTestSetRouteOptionsWithEntityTypeNoUpcasting() {
return array( return array(
array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerWithEntityNoUpcasting'), 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) { ...@@ -217,7 +217,7 @@ public function testSetRouteOptionsWithEntityTypeUpcasting($controller) {
public function providerTestSetRouteOptionsWithEntityTypeUpcasting() { public function providerTestSetRouteOptionsWithEntityTypeUpcasting() {
return array( return array(
array('Drupal\Tests\Core\Entity\BasicControllerClass::exampleControllerWithEntityUpcasting'), 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) { ...@@ -547,21 +547,14 @@ public function submitForm(array &$form, FormStateInterface $form_state) {
} }
function test_function_controller() {
} }
namespace { function test_function_controller_with_argument($argument) {
}
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_no_upcasting($entity_test) {
} }
function test_function_controller_entity_upcasting(EntityInterface $entity_test) { function test_function_controller_entity_upcasting(EntityInterface $entity_test) {