From 37010da991b4e5d64a3dc9d3d1c9f2034a6e1d17 Mon Sep 17 00:00:00 2001 From: Nathaniel Catchpole <catch@35733.no-reply.drupal.org> Date: Mon, 22 Aug 2016 17:01:56 +0100 Subject: [PATCH] Issue #2787655: Fix \Drupal\Tests\Core\Form\FormTestBase to not have multiple namespaces --- .../Drupal/Tests/Core/Form/FormTestBase.php | 37 ++---------------- .../Core/Form/fixtures/form_base_test.inc | 38 +++++++++++++++++++ 2 files changed, 42 insertions(+), 33 deletions(-) create mode 100644 core/tests/Drupal/Tests/Core/Form/fixtures/form_base_test.inc diff --git a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php index fd88ea22dea6..078d30ed9c88 100644 --- a/core/tests/Drupal/Tests/Core/Form/FormTestBase.php +++ b/core/tests/Drupal/Tests/Core/Form/FormTestBase.php @@ -1,6 +1,6 @@ <?php -namespace Drupal\Tests\Core\Form { +namespace Drupal\Tests\Core\Form; use Drupal\Component\Utility\Html; use Drupal\Core\Form\FormBuilder; @@ -147,6 +147,9 @@ abstract class FormTestBase extends UnitTestCase { protected function setUp() { parent::setUp(); + // Add functions to the global namespace for testing. + require_once __DIR__ . '/fixtures/form_base_test.inc'; + $this->moduleHandler = $this->getMock('Drupal\Core\Extension\ModuleHandlerInterface'); $this->formCache = $this->getMock('Drupal\Core\Form\FormCacheInterface'); @@ -311,35 +314,3 @@ public function getInfo($type) { } } - -} - -namespace { - - function test_form_id() { - $form['test'] = array( - '#type' => 'textfield', - '#title' => 'Test', - ); - $form['options'] = array( - '#type' => 'radios', - '#options' => array( - 'foo' => 'foo', - 'bar' => 'bar', - ), - ); - $form['value'] = array( - '#type' => 'value', - '#value' => 'bananas', - ); - $form['actions'] = array( - '#type' => 'actions', - ); - $form['actions']['submit'] = array( - '#type' => 'submit', - '#value' => 'Submit', - ); - return $form; - } - -} diff --git a/core/tests/Drupal/Tests/Core/Form/fixtures/form_base_test.inc b/core/tests/Drupal/Tests/Core/Form/fixtures/form_base_test.inc new file mode 100644 index 000000000000..cd833946f337 --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Form/fixtures/form_base_test.inc @@ -0,0 +1,38 @@ +<?php + +/** + * @file + * Functions in the global namespace for \Drupal\Tests\Core\Form\FormTestBase. + */ + +/** + * Creates a test form. + * + * @return array + * The form array + */ +function test_form_id() { + $form['test'] = array( + '#type' => 'textfield', + '#title' => 'Test', + ); + $form['options'] = array( + '#type' => 'radios', + '#options' => array( + 'foo' => 'foo', + 'bar' => 'bar', + ), + ); + $form['value'] = array( + '#type' => 'value', + '#value' => 'bananas', + ); + $form['actions'] = array( + '#type' => 'actions', + ); + $form['actions']['submit'] = array( + '#type' => 'submit', + '#value' => 'Submit', + ); + return $form; +} -- GitLab