summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDries2013-05-24 19:10:51 (GMT)
committer Dries2013-05-24 19:10:51 (GMT)
commitfeab614d1bc3bd85ab114b688a9b15ebe7335cce (patch)
tree29a60246b349f0371d19dd5a6979caeaafffbc95
parent4f6113f56639caf2881188f2a6f5144273ae1399 (diff)
Issue #1991078 by alexpott: Convert MachineNameControllerTest to PHPUnit.
-rw-r--r--core/modules/system/lib/Drupal/system/MachineNameController.php3
-rw-r--r--core/modules/system/lib/Drupal/system/Tests/Transliteration/MachineNameControllerTest.php74
-rw-r--r--core/modules/system/tests/Drupal/system/Tests/Transliteration/MachineNameControllerTest.php83
3 files changed, 85 insertions, 75 deletions
diff --git a/core/modules/system/lib/Drupal/system/MachineNameController.php b/core/modules/system/lib/Drupal/system/MachineNameController.php
index c3c7087..f0db24c 100644
--- a/core/modules/system/lib/Drupal/system/MachineNameController.php
+++ b/core/modules/system/lib/Drupal/system/MachineNameController.php
@@ -8,6 +8,7 @@
namespace Drupal\system;
use Drupal\Component\Transliteration\TransliterationInterface;
+use Drupal\Component\Utility\Unicode;
use Drupal\Core\ControllerInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
@@ -63,7 +64,7 @@ class MachineNameController implements ControllerInterface {
$transliterated = $this->transliteration->transliterate($text, $langcode, '_');
if($lowercase) {
- $transliterated = drupal_strtolower($transliterated);
+ $transliterated = Unicode::strtolower($transliterated);
}
if(isset($replace_pattern) && isset($replace)) {
$transliterated = preg_replace('@' . $replace_pattern . '@', $replace, $transliterated);
diff --git a/core/modules/system/lib/Drupal/system/Tests/Transliteration/MachineNameControllerTest.php b/core/modules/system/lib/Drupal/system/Tests/Transliteration/MachineNameControllerTest.php
deleted file mode 100644
index 2c689bf..0000000
--- a/core/modules/system/lib/Drupal/system/Tests/Transliteration/MachineNameControllerTest.php
+++ /dev/null
@@ -1,74 +0,0 @@
-<?php
-
-/**
- * @file
- * Contains \Drupal\system\Tests\Transliteration\MachineNameControllerTest.
- */
-
-namespace Drupal\system\Tests\Transliteration;
-
-use Drupal\Core\DependencyInjection\ContainerBuilder;
-use Drupal\Component\Transliteration\PHPTransliteration;
-use Drupal\simpletest\DrupalUnitTestBase;
-use Drupal\system\MachineNameController;
-use Symfony\Component\HttpFoundation\Request;
-
-/**
- * Tests machine name controller's transliteration functionality.
- */
-class MachineNameControllerTest extends DrupalUnitTestBase {
-
- /**
- * The machine name controller.
- *
- * @var \Drupal\system\MachineNameController
- */
- protected $machineNameController;
-
- public static function getInfo() {
- return array(
- 'name' => 'Machine name controller tests',
- 'description' => 'Tests that the machine name controller can transliterate strings as expected.',
- 'group' => 'Transliteration',
- );
- }
-
- public function setUp() {
- parent::setUp();
- // Create the machine name controller.
- $this->machineNameController = new MachineNameController(new PHPTransliteration());
- }
-
- /**
- * Tests machine name controller's transliteration functionality.
- *
- * @see \Drupal\system\MachineNameController::transliterate()
- */
- public function testMachineNameController() {
- $request = Request::create('', 'GET', array('text' => 'Bob', 'langcode' => 'en'));
- $json = $this->machineNameController->transliterate($request);
- $this->assertEqual('"Bob"', $json->getContent());
-
- $request = Request::create('', 'GET', array('text' => 'Bob', 'langcode' => 'en', 'lowercase' => TRUE));
- $json = $this->machineNameController->transliterate($request);
- $this->assertEqual('"bob"', $json->getContent());
-
- $request = Request::create('', 'GET', array('text' => 'Bob', 'langcode' => 'en', 'replace' => 'Alice', 'replace_pattern' => 'Bob'));
- $json = $this->machineNameController->transliterate($request);
- $this->assertEqual('"Alice"', $json->getContent());
-
- $request = Request::create('', 'GET', array('text' => 'Bob', 'langcode' => 'en', 'replace' => 'Alice', 'replace_pattern' => 'Tom'));
- $json = $this->machineNameController->transliterate($request);
- $this->assertEqual('"Bob"', $json->getContent());
-
- $request = Request::create('', 'GET', array('text' => 'Äwesome', 'langcode' => 'en', 'lowercase' => TRUE));
- $json = $this->machineNameController->transliterate($request);
- $this->assertEqual('"awesome"', $json->getContent());
-
- $request = Request::create('', 'GET', array('text' => 'Äwesome', 'langcode' => 'de', 'lowercase' => TRUE));
- $json = $this->machineNameController->transliterate($request);
- $this->assertEqual('"aewesome"', $json->getContent());
-
- }
-
-}
diff --git a/core/modules/system/tests/Drupal/system/Tests/Transliteration/MachineNameControllerTest.php b/core/modules/system/tests/Drupal/system/Tests/Transliteration/MachineNameControllerTest.php
new file mode 100644
index 0000000..8eb2592
--- /dev/null
+++ b/core/modules/system/tests/Drupal/system/Tests/Transliteration/MachineNameControllerTest.php
@@ -0,0 +1,83 @@
+<?php
+
+/**
+ * @file
+ * Contains \Drupal\system\Tests\Transliteration\MachineNameControllerTest.
+ */
+
+namespace Drupal\system\Tests\Transliteration;
+
+use Drupal\Tests\UnitTestCase;
+use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Component\Transliteration\PHPTransliteration;
+use Drupal\system\MachineNameController;
+use Symfony\Component\HttpFoundation\Request;
+
+/**
+ * Tests machine name controller's transliteration functionality.
+ *
+ * @group System
+ */
+class MachineNameControllerTest extends UnitTestCase {
+
+ /**
+ * The machine name controller.
+ *
+ * @var \Drupal\system\MachineNameController
+ */
+ protected $machineNameController;
+
+ public static function getInfo() {
+ return array(
+ 'name' => 'Machine name controller tests',
+ 'description' => 'Tests that the machine name controller can transliterate strings as expected.',
+ 'group' => 'Transliteration',
+ );
+ }
+
+ public function setUp() {
+ parent::setUp();
+ // Create the machine name controller.
+ $this->machineNameController = new MachineNameController(new PHPTransliteration());
+ }
+
+ /**
+ * Data provider for testMachineNameController().
+ *
+ * @see testMachineNameController()
+ *
+ * @return array
+ * An array containing:
+ * - An array of request parameters.
+ * - The expected content of the JSONresponse.
+ */
+ public function providerTestMachineNameController() {
+ return array(
+ array(array('text' => 'Bob', 'langcode' => 'en'), '"Bob"'),
+ array(array('text' => 'Bob', 'langcode' => 'en', 'lowercase' => TRUE), '"bob"'),
+ array(array('text' => 'Bob', 'langcode' => 'en', 'replace' => 'Alice', 'replace_pattern' => 'Bob'), '"Alice"'),
+ array(array('text' => 'Bob', 'langcode' => 'en', 'replace' => 'Alice', 'replace_pattern' => 'Tom'), '"Bob"'),
+ array(array('text' => 'Äwesome', 'langcode' => 'en', 'lowercase' => TRUE), '"awesome"'),
+ array(array('text' => 'Äwesome', 'langcode' => 'de', 'lowercase' => TRUE), '"aewesome"'),
+ );
+ }
+
+ /**
+ * Tests machine name controller's transliteration functionality.
+ *
+ * @param array $request_params
+ * An array of request parameters.
+ * @param $expected_content
+ * The expected content of the JSONresponse.
+ *
+ * @see \Drupal\system\MachineNameController::transliterate()
+ *
+ * @dataProvider providerTestMachineNameController
+ */
+ public function testMachineNameController(array $request_params, $expected_content) {
+ $request = Request::create('', 'GET', $request_params);
+ $json = $this->machineNameController->transliterate($request);
+ $this->assertEquals($expected_content, $json->getContent());
+ }
+
+}