The views module uses Test class members with underscored names. Some examples are big_user, web_user and admin_user, but there could be others. According to our coding conventions, these should be renamed to bigUser, webUser and adminUser. In addition, some properties are undefined but should be.

See the parent issue #1811638: [meta] Clean-up Test members - ensure property definition and use of camelCase naming convention.

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task, because this is a coding standards change.
Issue priority Not critical because coding standard changes are not critical.
Unfrozen changes Unfrozen because it only changes automated tests.
Disruption There is no disruption expected from this sort of change.

Comments

cilefen’s picture

Issue summary: View changes
cilefen’s picture

Component: color.module » views.module
Status: Needs work » Active
hussainweb’s picture

Status: Active » Needs review
StatusFileSize
new38.5 KB

Initial attempt.

mile23’s picture

Status: Needs review » Needs work

Found an underscore in Drupal\views\Tests\Handler\FieldWebTest:

  protected $column_map = array(
    'views_test_data_name' => 'name',
  );

1 out of 104 files isn't bad. :-)

Also made a video about how I did this review: http://youtu.be/H6pWz_6XoiQ :-)

tibbsa’s picture

That video ought to be added to the Contributor task: Improve patch coding standards and documentation if you ask me.

tibbsa’s picture

Status: Needs work » Needs review
StatusFileSize
new39.09 KB

One has to wonder what purpose this variable serves if this test passed with the wrong variable name in the first place, but alas...

diff --git a/core/modules/views/src/Tests/Handler/FieldWebTest.php b/core/modules/views/src/Tests/Handler/FieldWebTest.php
index cd11a52..ceb8881 100644
--- a/core/modules/views/src/Tests/Handler/FieldWebTest.php
+++ b/core/modules/views/src/Tests/Handler/FieldWebTest.php
@@ -32,7 +32,12 @@ class FieldWebTest extends HandlerTestBase {
    */
   public static $modules = ['node'];

-  protected $column_map = array(
+  /**
+   * Maps between the key in the expected result and the query result.
+   *
+   * @var array
+   */
+  protected $columnMap = array(
     'views_test_data_name' => 'name',
   );
mile23’s picture

Status: Needs review » Reviewed & tested by the community

My video above was a bit misleading on the analysis. It looks like a common pattern in the views tests to have a $column_map property on all the test classes. I'm not sure what the analysis would be on whether to keep or toss the one you just changed above. And it's out of scope to make such a change anyway. :-)

phpcs says there aren't any under_score errors any more, so RTBC. Woot.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: clean_up_views_module-2385209-6.patch, failed testing.

subhojit777’s picture

Assigned: Unassigned » subhojit777

Status: Needs work » Needs review
subhojit777’s picture

Assigned: subhojit777 » Unassigned
Status: Needs review » Reviewed & tested by the community

Patch in #6 passed test. Code looks good according to camel case coding standard. Moving this to RTBC.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 6: clean_up_views_module-2385209-6.patch, failed testing.

Status: Needs work » Needs review
mile23’s picture

Status: Needs review » Reviewed & tested by the community

Again with the fidgety testbot. RTBC from #7 for patch in #6 is renewed. Woot.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/views/src/Tests/Handler/FieldUnitTest.php
    @@ -28,9 +28,14 @@ class FieldUnitTest extends ViewUnitTestBase {
    +  protected $columnMap = [
         'views_test_data_name' => 'name',
    -  );
    +  ];
    
    +++ b/core/modules/views/src/Tests/Handler/FieldWebTest.php
    @@ -32,7 +32,12 @@ class FieldWebTest extends HandlerTestBase {
    +  protected $columnMap = array(
         'views_test_data_name' => 'name',
       );
    
    +++ b/core/modules/views/src/Tests/Handler/FilterBooleanOperatorStringTest.php
    @@ -31,11 +31,16 @@ class FilterBooleanOperatorStringTest extends ViewUnitTestBase {
    +  protected $columnMap = [
         'views_test_data_id' => 'id',
    -  );
    +  ];
    
    +++ b/core/modules/views/src/Tests/Handler/FilterBooleanOperatorTest.php
    @@ -30,11 +30,16 @@ class FilterBooleanOperatorTest extends ViewUnitTestBase {
    +  protected $columnMap = [
         'views_test_data_id' => 'id',
    -  );
    +  ];
    
    +++ b/core/modules/views/src/Tests/Handler/FilterCombineTest.php
    @@ -22,12 +22,17 @@ class FilterCombineTest extends ViewUnitTestBase {
    +  protected $columnMap = [
         'views_test_data_name' => 'name',
         'views_test_data_job' => 'job',
    -  );
    +  ];
    
    +++ b/core/modules/views/src/Tests/Handler/FilterEqualityTest.php
    @@ -24,11 +24,16 @@ class FilterEqualityTest extends ViewUnitTestBase {
    +  protected $columnMap = [
         'views_test_data_name' => 'name',
    -  );
    +  ];
    
    +++ b/core/modules/views/src/Tests/Handler/FilterInOperatorTest.php
    @@ -24,9 +24,14 @@ class FilterInOperatorTest extends ViewUnitTestBase {
    +  protected $columnMap = array(
         'views_test_data_name' => 'name',
         'views_test_data_age' => 'age',
       );
    
    +++ b/core/modules/views/src/Tests/Handler/FilterNumericTest.php
    @@ -24,12 +24,17 @@ class FilterNumericTest extends ViewUnitTestBase {
    +  protected $columnMap = [
         'views_test_data_name' => 'name',
         'views_test_data_age' => 'age',
    -  );
    +  ];
    
    +++ b/core/modules/views/src/Tests/Handler/FilterStringTest.php
    @@ -24,11 +24,16 @@ class FilterStringTest extends ViewUnitTestBase {
    +  protected $columnMap = [
         'views_test_data_name' => 'name',
    -  );
    +  ];
    

    Sometimes there is a conversion to the new array format and sometimes there is not. How come? Changing to the new format is okay in this patch since these lines are changing but let's be consistent.

  2. +++ b/core/modules/views/src/Tests/Handler/FilterInOperatorTest.php
    @@ -24,9 +24,14 @@ class FilterInOperatorTest extends ViewUnitTestBase {
    -  public static $testViews = array('test_view');
    +  public static $testViews = ['test_view'];
    
    +++ b/core/modules/views/src/Tests/Handler/FilterNumericTest.php
    @@ -24,12 +24,17 @@ class FilterNumericTest extends ViewUnitTestBase {
    -  public static $testViews = array('test_view');
    +  public static $testViews = ['test_view'];
    
    +++ b/core/modules/views/src/Tests/Handler/FilterStringTest.php
    @@ -24,11 +24,16 @@ class FilterStringTest extends ViewUnitTestBase {
    -  public static $testViews = array('test_view');
    +  public static $testViews = ['test_view'];
    

    These are out-of-scope changes.

tadityar’s picture

Status: Needs work » Needs review
StatusFileSize
new39.68 KB
new5.44 KB

Applied suggested change from #15.

Status: Needs review » Needs work

The last submitted patch, 16: clean_up_views_module-2385209-16.patch, failed testing.

tadityar’s picture

Status: Needs work » Needs review
StatusFileSize
new39.68 KB
new5.44 KB

er.. forgot to add ;

Status: Needs review » Needs work

The last submitted patch, 18: clean_up_views_module-2385209-18.patch, failed testing.

subhojit777’s picture

This kind of array syntax sometimes fails, I guess something is wrong with testbot. alexpott has mentioned to keep the syntax consistent in #15, isn't it?

I think we should use array() everywhere else. Rest of the child issues have this same syntax. See cilefen's comment here #2394419: Clean-up file module test members - ensure property definition and use of camelCase naming convention (comment)

tadityar’s picture

Status: Needs work » Needs review
StatusFileSize
new38.4 KB
new6.18 KB

reverted array style change.

tadityar’s picture

Status: Needs review » Needs work

The last submitted patch, 21: clean_up_views_module-2385209-21.patch, failed testing.

hussainweb’s picture

Status: Needs work » Needs review
StatusFileSize
new7.7 KB
new38.87 KB

Reverting all array syntax changes and found one more variable without a declaration.

mile23’s picture

Status: Needs review » Reviewed & tested by the community

Tests pass and phpcs can't find any improper underscore names.

Thanks for removing the array changes.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
Issue tags: +Needs reroll

clean_up_views_module-2385209-24.patch no longer applies.

error: patch failed: core/modules/views/src/Tests/Wizard/TaggedWithTest.php:23
error: core/modules/views/src/Tests/Wizard/TaggedWithTest.php: patch does not apply

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new38.81 KB

reroll

Status: Needs review » Needs work

The last submitted patch, 27: clean_up_views_module-2385209-27.patch, failed testing.

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new38.87 KB
mile23’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs reroll

Thanks for the reroll.

I still can't find any class property underscore errors in the tests.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/modules/views/src/Tests/Plugin/AccessTest.php
@@ -33,6 +33,34 @@ class AccessTest extends PluginTestBase {
+  /**
+   * Role id of a web user.
+   *
+   * @var string
+   */
+  protected $webRole;
...
+  /**
+   * Role id of a normal user.
+   *
+   * @var string
+   */
+  protected $normalRole;

Not necessary to by class properties since afaics they are not used. We should still add the role to the user.

cilefen’s picture

Status: Needs work » Needs review
StatusFileSize
new1.3 KB
new38.6 KB

subhojit777’s picture

I would have marked it RTBC but there are some commented code in ViewStorageTest.php, it can be out of scope. The code looks ok and egrep -rl '\$this\->[a-z]+_[a-z_]+' core/modules/views/src/Tests/ returned no output.

mile23’s picture

Status: Needs review » Reviewed & tested by the community
Related issues: +#2413217: ViewStorageTest::displayMethodTests() needs @todo love.

Just added this for the commented code: #2413217: ViewStorageTest::displayMethodTests() needs @todo love.

I think we can agree this is RTBC. :-)

subhojit777’s picture

Then its okay. RTBC +1 :)

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/views/src/Tests/DefaultViewsTest.php
    @@ -40,13 +40,20 @@ class DefaultViewsTest extends ViewTestBase {
    +  /**
    +   * Name of a field for testing.
    +   *
    +   * @var string
    +   */
    +  protected $fieldName;
    

    Does not need to be a property.

  2. +++ b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php
    @@ -25,9 +25,9 @@
       /**
    -   * @var \Drupal\user\Entity\User
    +   * @var \Drupal\user\UserInterface
        */
    -  protected $root_user;
    +  protected $rootUser;
    

    Does not need to be a property.

ardnet’s picture

Assigned: Unassigned » ardnet
ardnet’s picture

Status: Needs work » Needs review
ardnet’s picture

StatusFileSize
new2.22 KB
ardnet’s picture

StatusFileSize
new37.5 KB
cilefen’s picture

Assigned: ardnet » Unassigned
Status: Needs review » Needs work

@ardnet Good work on your first patch! Here are some changes to make:

  1. +++ b/core/modules/views/src/Tests/DefaultViewsTest.php
    @@ -40,13 +40,20 @@ class DefaultViewsTest extends ViewTestBase {
    +  /**
    +   * Name of a field for testing.
    +   *
    +   * @var string
    +   */
    +  protected $field_name;
    +
    

    This should be removed completely.

  2. +++ b/core/modules/views/src/Tests/DefaultViewsTest.php
    @@ -65,9 +65,9 @@
    +    $this->field_name = Unicode::strtolower($this->randomMachineName());
    

    References to $this->field_name should be simply $field_name because we are changing this to a variable in this function's scope.

  3. +++ b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php
    @@ -39,8 +39,8 @@
    +    $this->root_user = entity_create('user', array('name' => $this->randomMachineName()));
    

    References to $this->root_user in this method should be simply $root_user. Also remove the $root_user class property and its comment.

hussainweb’s picture

@ardnet: I think there was some confusion. @alexpott didn't say to revert those property names like you have done in the interdiff. The properties are apparently not necessary at all and you can remove them, and their usage can be changed to local variable assignments.

The last submitted patch, 41: clean_up_views_module-2385209-39.patch, failed testing.

ardnet’s picture

Status: Needs work » Needs review
StatusFileSize
new38.32 KB
cilefen’s picture

Status: Needs review » Needs work

@ardnet - It will be good if you keep posting interdiffs with your patches. Don't worry about it this time.

  1. +++ b/core/modules/views/src/Tests/DefaultViewsTest.php
    @@ -40,13 +40,20 @@ class DefaultViewsTest extends ViewTestBase {
    +  /**
    +   * Name of a field for testing.
    +   *
    +   * @var string
    +   */
    +  protected $field_name;
    +
    

    Remove this now-unused declaration.

  2. +++ b/core/modules/views/src/Tests/DefaultViewsTest.php
    @@ -55,25 +62,24 @@ protected function setUp() {
    -    $this->field_name = Unicode::strtolower($this->randomMachineName());
    

    I am not sure why you removed this. It will cause an error. Replace $this->field_name with $field_name instead.

  3. +++ b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php
    @@ -39,8 +39,7 @@ protected function setUpFixtures() {
    -    $this->root_user = entity_create('user', array('name' => $this->randomMachineName()));
    

    Why did you remove this? You should replace $this->root_user with $root_user instead.

The last submitted patch, 45: clean_up_views_module-2385209-44.patch, failed testing.

ajits’s picture

Assigned: Unassigned » ajits
Issue tags: +#DCM2015

Assigning to myself

ajits’s picture

Status: Needs work » Needs review
StatusFileSize
new38.34 KB
new2.55 KB

Attaching a patch as per @Alex's comment #37.

mile23’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/views/src/Tests/DefaultViewsTest.php
    @@ -55,25 +55,25 @@ protected function setUp() {
         // Create a field.
    -    $this->field_name = Unicode::strtolower($this->randomMachineName());
    +    $fieldName = Unicode::strtolower($this->randomMachineName());
    

    +1 on making it a local variable, but -1 on leaving it as camelCase. It should be underscored, like this: $field_name

  2. +++ b/core/modules/views/src/Tests/Plugin/RelationshipJoinTestBase.php
    @@ -39,8 +34,8 @@ protected function setUpFixtures() {
         // Create a record for uid 1.
         $this->installSchema('system', 'sequences');
    -    $this->root_user = entity_create('user', array('name' => $this->randomMachineName()));
    -    $this->root_user->save();
    +    $rootUser = entity_create('user', array('name' => $this->randomMachineName()));
    +    $rootUser->save();
    

    Same deal here. Change $rootUser to $root_user.

ajits’s picture

Status: Needs work » Needs review
StatusFileSize
new38.34 KB

Done!

mile23’s picture

Status: Needs review » Reviewed & tested by the community

Great. :-)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 51: clean_up_views_module-2385209-51.patch, failed testing.

hussainweb’s picture

Status: Needs work » Reviewed & tested by the community

And I thought this would be a reroll. :)

I am not sure if this is a random fail but it is strange that it passed earlier and suddenly started failing. Retesting it. Should go back to RTBC as per #52.

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Committed 23a2db2 and pushed to 8.0.x. Thanks!

Thanks for adding the beta evaluation to the issue summary.

  • alexpott committed 23a2db2 on 8.0.x
    Issue #2385209 by tadityar, cilefen, ardnet, hussainweb, AjitS, tibbsa:...
ajits’s picture

Assigned: ajits » Unassigned

Cool!

Status: Fixed » Closed (fixed)

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