Part of meta-issue #2002650: [meta, no patch] improve maintainability by removing unused local variables

File /core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayTest.php

Line 123: Unused local variable $path_prefix

File /core/modules/views_ui/lib/Drupal/views_ui/Tests/ViewsUITourTest.php

Line 55: Unused local variable $view_path

Comments

manu4543’s picture

Status: Active » Needs review
StatusFileSize
new848 bytes
sergeypavlenko’s picture

Status: Needs review » Needs work

"warning: 1 line adds whitespace errors."

Please delete unneeded spaces from a string 124.

giammi’s picture

Status: Needs work » Needs review
StatusFileSize
new0 bytes
new842 bytes
Anonymous’s picture

#3 applies, however I don't believe the variable $path_prefix is supposed to be unused, I think there's a line missing. The code is as follows:

    $view = $this->randomView($view);
    $path_prefix = 'admin/structure/views/view/' . $view['id'] .'/edit';

    $this->clickLink(t('Reorder displays'));

Should be:

    $view = $this->randomView($view);
    $path_prefix = 'admin/structure/views/view/' . $view['id'] .'/edit';

    $this->drupalGet($path_prefix);
    $this->clickLink(t('Reorder displays'));
Anonymous’s picture

StatusFileSize
new715 bytes

Here's a patch for my suggestion in #4

Anonymous’s picture

StatusFileSize
new840 bytes

For the sake of consistency in code I've re-rolled the above patch so the blank line appears in the same place as in rest of the code

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

Yeah this makes more sense.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work

Hmmm.... does it?

  /**
   * A helper method which creates a random view.
   */
  public function randomView(array $view = array()) {
    // Create a new view in the UI.
    $default = array();
    $default['label'] = $this->randomName(16);
    $default['id'] = strtolower($this->randomName(16));
    $default['description'] = $this->randomName(16);
    $default['page[create]'] = TRUE;
    $default['page[path]'] = $default['id'];

    $view += $default;

    $this->drupalPostForm('admin/structure/views/add', $view, t('Save and edit'));

    return $default;
  }

The drupalPostForm() here means that we should be on the view edit page. Doing $this->drupalGet($path_prefix); means that we need to make yet another request via the simpletest browser. I'd like to see this patch remove the unnecessary $this->drupalGet($path_prefix); from the other tests.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new1.68 KB
new1.68 KB

Ah, yes, I see. Thanks!

Anonymous’s picture

Status: Needs review » Needs work

Hm, I missed some out.

Anonymous’s picture

Status: Needs work » Needs review
StatusFileSize
new2.07 KB

Ok, I think this is the right combination of removing unused variables and unused extra test calls.

parthipanramesh’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

applied without any issues

webchick’s picture

Assigned: manu4543 » alexpott

Back to alexpott for review.

xjm’s picture

Title: Remove Unused local variable $path_prefix from /core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayTest.php » Remove unused local variables from the Views UI module
Assigned: alexpott » Unassigned
Priority: Normal » Minor
Status: Reviewed & tested by the community » Needs review

Please confirm that all other unused local variables are also removed from the Views UI module. Thanks!

Anonymous’s picture

Issue summary: View changes
StatusFileSize
new2.77 KB
new1.35 KB

Having worked on this issue I saw the update wrt is this the last unused variable so thought I'd check - I didn't notice at the time it was already assigned!

First I checked through #2002650: [meta, no patch] improve maintainability by removing unused local variables for all issues affecting 'views_ui' and found the following which I checked each one and they had all been committed:

#2081193: Remove Unused local variable $display from /core/modules/views_ui/views_ui.module
#2080047: Remove Unused local variable from views_ui module
#2080033: Remove Unused local variable $section from /core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Display.php
#2062755: Remove Unused local variable $view from /core/modules/views_ui/lib/Drupal/views_ui/Tests/RowUITest.php
#2062179: Remove Unused local variable $view from /core/modules/views_ui/lib/Drupal/views_ui/Tests/StyleUITest.php
#2080413: Remove Unused local variable $view from /core/modules/views_ui/lib/Drupal/views_ui/Tests/RedirectTest.php
#2080035: Remove Unused local variable $name from /core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/RearrangeFilter.php
#2079891: Remove Unused local variable $name from /core/modules/views_ui/lib/Drupal/views_ui/Form/Ajax/Rearrange.php
#2079881: Remove Unused local variable $stack from /core/modules/views_ui/lib/Drupal/views_ui/ViewUI.php
#2080079: Remove Unused local variable $display_title from /core/modules/views_ui/lib/Drupal/views_ui/ViewEditFormController.php

Then I applied patch the latest patch from this issue #2061397-11: Remove unused local variables from the Views UI module and used PHPStorm's code inspection to check for any unused variables.

I found two further unused variables, one in a Tour test case so potentially been introduced since these issues were originally created, and another caused by this patch - it removed a variable which was using $view so when that was removed $view became unused too.

I've attached a re-rolled patch with these two new issues - I see a lot of merging has been going on so didn't create new issues however I shall update the summary to reflect these additions.

Now code inspection says no unused variables in views_ui module directory.

The last submitted patch, 15: core-remove-unused-variable-2061397-15.patch, failed testing.

Anonymous’s picture

Many apologies, please ignore previous - forgot to test locally and of course $view is needed in the test even though not 'used'. The other unused variable is indeed not used so attached is re-rolled patch from #11 with that in and the used $view variable back in again. Summary also updated.

Anonymous’s picture

StatusFileSize
new681 bytes

Attached 2 patches instead of patch and interdiff, here's the interdiff.

parthipanramesh’s picture

Status: Needs review » Reviewed & tested by the community

Looks fine to me!

webchick’s picture

Cool, thanks. One thing...

+++ b/core/modules/views_ui/lib/Drupal/views_ui/Tests/DisplayTest.php
@@ -197,9 +194,7 @@ public function testCloneDisplay() {
   public function testDisableDisplay() {
     $view = $this->randomView();
-    $path_prefix = 'admin/structure/views/view/' . $view['id'] .'/edit';
 
-    $this->drupalGet($path_prefix);
     $this->assertFalse($this->xpath('//div[contains(@class, :class)]', array(':class' => 'views-display-disabled')), 'Make sure the disabled display css class does not appear after initial adding of a view.');
 

While this passes, it's only coincidentally so. The assertFalse() down below is making sure that the disabled class it not appearing, which of course it's not, because $this->xpath() is most likely being passed into it a blank string since we haven't actually retrieved an HTML page for it to check. :)

So I think those two need to be removed, but the rest looks fine.

webchick’s picture

Status: Reviewed & tested by the community » Needs work
Anonymous’s picture

I've read this again and again but I'm still not sure what needs to be done. I understand the issue with the coincidental working of the test but unsure how to fix.

martin107’s picture

@stevepurkiss what she means is please delete the two lines ( prefixed with '-' )
and the patch is good to go...

- $path_prefix = 'admin/structure/views/view/' . $view['id'] .'/edit';
- $this->drupalGet($path_prefix);

I hope this helps, I assume that you want to do this .. if not, I will lurk on this issue, and sort it out in about a week.

PS the patch still applies

drupalninja99’s picture

Status: Needs work » Needs review
StatusFileSize
new3.24 KB
new833 bytes

Taking a crack at it..

Status: Needs review » Needs work

The last submitted patch, 24: core-remove-unused-variable-2061397-24.patch, failed testing.

Anonymous’s picture

I don't think that is the issue, those lines were taken out already, the patch in #24 erroneously removes in the test remove display function where it is needed.

[edit: hm, not sure why it has file flagged as deleted, wasn't me...!]

drupalninja99’s picture

ACK! thx

baisong’s picture

Hi, I was just told to look at this issue in core mentoring hours on #drupal IRC.

Patch attached.

baisong’s picture

Status: Needs work » Needs review
jayeshanandani’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me! RTBC!

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 28: core-remove-unused-variable-2061397-28.patch, failed testing.

gokulnk’s picture

Status: Needs work » Needs review
dawehner’s picture

Status: Needs review » Reviewed & tested by the community

back to RTBC

webchick’s picture

Status: Reviewed & tested by the community » Fixed

All right, let's get this one in.

Committed and pushed to 8.x. Thanks!

Status: Fixed » Closed (fixed)

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