Task to convert tests for \Drupal\Component\Transliteration to phpunit, and also expand test coverage.

Since part of the existing tests test the core override \Drupal\Core\Transliteration\PhpTransliteration, those parts will need to be left as simpletests.

See #1938068: Convert UnitTestBase to PHPUnit.

Comments

jhedstrom’s picture

Status: Active » Needs review
StatusFileSize
new7.91 KB

This converts the unit-testable parts over to phpunit. I couldn't quite figure out how to expand coverage to the invalid byte-sequence parts of PhpTransliteration.

Status: Needs review » Needs work

The last submitted patch, transliteration-phpunit-2051467-01.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new8.06 KB
new1.49 KB

Fixes the strict warnings by just calling Random::string(), adds an additional test that gets coverage to 100%.

ParisLiakos’s picture

+++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
@@ -0,0 +1,107 @@
+    $printable = (isset($case[3])) ? $case[3] : $original;

so when $case is ever set here?

ParisLiakos’s picture

Status: Needs review » Needs work
jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new8.24 KB
new3.09 KB

The code referenced in #4 was left-over from the old simpletest test. This and other old code has been removed, plus I added an additonal test to check the new max length parameter. 100% coverage.

Status: Needs review » Needs work

The last submitted patch, transliteration-phpunit-2051467-06.patch, failed testing.

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new8.29 KB
new861 bytes
dawehner’s picture

StatusFileSize
new15.18 KB
new21.89 KB

Let's remove the need for a transliteration_test module.

Yeah, this removes a webtest!

  • Introduces the module handler on the core class and replaces the drupal_alter() call
  • Adds a core specific test, which takes care of the alter functionality.
  • Removes the transliteration_test module

I do agree that the interdiff is more confusing as helpful.

Status: Needs review » Needs work

The last submitted patch, transliteration-phpunit-2051467-9.patch, failed testing.

dawehner’s picture

Status: Needs work » Needs review
StatusFileSize
new16.26 KB
new1.53 KB

There we go.

jhedstrom’s picture

ParisLiakos’s picture

Yay for getting rid a test module:D

  1. +++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
    @@ -2,24 +2,23 @@
    + * Contains Drupal\Tests\Component\Transliteration\PhpTransliterationTest.
    

    Drupal needs a backslash in front here.. \Drupal\..

  2. +++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
    @@ -31,9 +30,40 @@ public static function getInfo() {
    +   * @dataProvider providerTestPHPTransliteration
    ...
    +   * Provides data for self::testPHPTransliteration().
    ...
    +  public static function providerTestPHPTransliteration() {
    
    +++ b/core/tests/Drupal/Tests/Core/Transliteration/PHPTransliterationTest.php
    @@ -0,0 +1,105 @@
    +  public function testPHPTransliterationWithAlter($langcode, $original, $expected, $printable = NULL) {
    ...
    +  public function providerTestPHPTransliterationWithAlter() {
    

    PHP should be only uppercase first ie: testPhpTransliteration

ParisLiakos’s picture

Status: Needs review » Needs work
jhedstrom’s picture

PHP should be only uppercase first ie: testPhpTransliteration

Does that mean this patch should fix the class being tested and change it from PHPTransliteration to PhpTransliteration?

ParisLiakos’s picture

well we should at least name correctly the newly introduced code here..fixing existing code could happen in other issue, unless it is blocking us here, which i doubt?

jhedstrom’s picture

Status: Needs work » Needs review
StatusFileSize
new1.98 KB
new8.34 KB

That makes sense. This patch also adds the appropriate groups to the test class.

ParisLiakos’s picture

thanks

wrong patch though? #11 is double size

jhedstrom’s picture

Oh, indeed it is the wrong patch.

jhedstrom’s picture

StatusFileSize
new16.25 KB
new3.69 KB

This should be the correct one.

ParisLiakos’s picture

  1. +++ b/core/lib/Drupal/Core/Transliteration/PHPTransliteration.php
    @@ -18,6 +19,29 @@
    +  public function __construct($data_directory = NULL, ModuleHandlerInterface $module_handler) {
    

    it just occured to me that the optional argument should be last, right?

  2. +++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
    @@ -74,45 +102,31 @@ public function testPHPTransliteration() {
    +      // array('zz', $two_byte, 'Z O U A O aouaohello'),
    +      // array('zz', $random, $random),
    +      // array('zz', $five_byte, 'ATh', $five_byte_printable),
    

    hmm also what about those? why commented?

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

The points of paris got adressed.

webchick’s picture

Status: Reviewed & tested by the community » Needs review

Er. They did? How?

dawehner’s picture

Oh that is embarrassing.

jhedstrom’s picture

The commented out tests were dependent on the test module removed in #9. We could re-order the constructor arguments.

ParisLiakos’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

Needs reroll and fixing #21

berdir’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new16.21 KB
new1.18 KB

Those cases were already moved to the other test class, so let's just remove them here :)

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

Thanks, looks good..just a small nit, in case this needs to be rerolled

+++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
@@ -31,9 +30,40 @@ public static function getInfo() {
+  public static function providerTestPhpTransliteration() {

does not need to be static

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: transliteration-phpunit-2051467-27.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new16.19 KB
new776 bytes

Conflicted in the removed info file, removed the static, good point.

ParisLiakos’s picture

Status: Needs review » Reviewed & tested by the community

thanks!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 30: transliteration-phpunit-2051467-30.patch, failed testing.

ParisLiakos’s picture

Drupal\system\Tests\Cache\ApcuBackendUnitTest random failure

30: transliteration-phpunit-2051467-30.patch queued for re-testing.

The last submitted patch, 30: transliteration-phpunit-2051467-30.patch, failed testing.

ParisLiakos’s picture

The last submitted patch, 30: transliteration-phpunit-2051467-30.patch, failed testing.

ParisLiakos’s picture

The last submitted patch, 30: transliteration-phpunit-2051467-30.patch, failed testing.

ParisLiakos’s picture

ParisLiakos’s picture

Status: Needs work » Reviewed & tested by the community

finally

xjm’s picture

Status: Reviewed & tested by the community » Needs work

This sadly had a merge conflict when I tried to reroll it for #2247991: [May 27] Move all module code from …/lib/Drupal/… to …/src/… for PSR-4 so it will need a closer look.

sun’s picture

Component: base system » transliteration system
Issue tags: -PHPUnit

Removing the 'phpunit' tag — let's stop to tag every issue that just happens to add or touch phpunit tests, because that makes no sense; we're not adding a tag to all issues that happen to add or touch simpletest tests either. ;)

  1. +++ b/core/lib/Drupal/Core/Transliteration/PHPTransliteration.php
    @@ -18,6 +19,29 @@
    +  public function __construct($data_directory = NULL, ModuleHandlerInterface $module_handler) {
    +    parent::__construct($data_directory);
    

    That's an edge-case of required/optional argument ordering, but due to the parent class constructor, I agree that the order is sensible here.

  2. +++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
    @@ -31,9 +30,40 @@ public static function getInfo() {
    +  public function testPhpTransliteration($langcode, $original, $expected, $unknown_character = '?', $max_length = NULL) {
    

    Normally, $expected should be taken first (especially in this case), but upon looking further, I just realized that you're trying to keep this conversion patch as small as possible.

  3. +++ b/core/tests/Drupal/Tests/Core/Transliteration/PhpTransliterationTest.php
    @@ -0,0 +1,105 @@
    + * @group Drupal
    

    s/@group Drupal/@group Transliteration/g

dawehner’s picture

Removing the 'phpunit' tag — let's stop to tag every issue that just happens to add or touch phpunit tests, because that makes no sense; we're not adding a tag to all issues that happen to add or touch simpletest tests either. ;)

It used to be a perfect tool to push the usage of phpunit by getting more reviews on those issues.

  1. +++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
    @@ -2,24 +2,23 @@
    + * @see \Drupal\Component\Transliteration\PhpTransliteration
    
    +++ b/core/tests/Drupal/Tests/Core/Transliteration/PhpTransliterationTest.php
    @@ -0,0 +1,105 @@
    + * @see \Drupal\Core\Transliteration\PhpTransliteration
    + */
    +class PhpTransliterationTest extends UnitTestCase {
    

    Let's use @coversClass

  2. +++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
    @@ -2,24 +2,23 @@
       public static function getInfo() {
         return array(
    
    +++ b/core/tests/Drupal/Tests/Core/Transliteration/PhpTransliterationTest.php
    @@ -0,0 +1,105 @@
    +  public static function getInfo() {
    +    return array(
    +      'name' => 'Transliteration functionality',
    +      'description' => 'Tests Transliteration component functionality.',
    +      'group' => 'Transliteration',
    +    );
    +  }
    +
    

    We can drop those now.

  3. +++ b/core/tests/Drupal/Tests/Component/Transliteration/PhpTransliterationTest.php
    @@ -31,9 +30,40 @@ public static function getInfo() {
    +    $random = $random_generator->String(10);
    

    it looks so wrong to use Uppercase methods.

herom’s picture

Status: Needs work » Needs review
StatusFileSize
new2.08 KB
new16.08 KB

reroll, and fix #42.3 and #43.

Status: Needs review » Needs work

The last submitted patch, 44: transliteration-phpunit-2051467-44.patch, failed testing.

herom’s picture

Status: Needs work » Needs review
StatusFileSize
new1.18 KB
new15.88 KB

bad merge.

mile23’s picture

Status: Needs review » Needs work

Patch doesn't apply.

alansaviolobo’s picture

Status: Needs work » Needs review

patch seems to apply. re running tests.

Status: Needs review » Needs work

The last submitted patch, 46: transliteration-phpunit-2051467-46.patch, failed testing.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
StatusFileSize
new14.88 KB

Rerolled and reviewed locally, looks good to go if the testbot agrees.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 51: 2051467-51.patch, failed testing.

amateescu’s picture

Status: Needs work » Needs review
StatusFileSize
new15.7 KB
new840 bytes

Looks like an easy fix.

daffie’s picture

mile23’s picture

StatusFileSize
new18.99 KB

Needed some re-roll love.

When this comes back green, I'll mark this as postponed due to the class rename issue above #2388169: Rename PHPTransliteration to PhpTransliteration. It will just need a re-roll and not much else.

mile23’s picture

Status: Needs review » Postponed
amateescu’s picture

Status: Postponed » Reviewed & tested by the community
StatusFileSize
new15.69 KB

Rerolled the patch, still looks good.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

This changes 99% test code and inject the module handler in PhpTransliteration so is not disruptive. Committed c8c1ae1 and pushed to 8.0.x. Thanks!

  • alexpott committed c8c1ae1 on 8.0.x
    Issue #2051467 by jhedstrom, dawehner, amateescu, Berdir, herom, Mile23...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.