Problem/Motivation

When the Updater::findInfoFile() method parses, it's checking against '.info' files with 5 characters instead of '.info.yml' which is 9.

When installing Devel, it can't find a match and it picks the last one and displays "Devel Kint" as the project name on install through the UI on /admin/modules/install

Proposed resolution

Change the length it searches for.

Remaining tasks

User interface changes

API changes

Beta phase evaluation

Reference: https://www.drupal.org/core/beta-changes
Issue category Task
Issue priority Follow-up of a major issue
Unfrozen changes Unfrozen because it only changes tests
Prioritized changes Not prioritized.
Disruption Non-disruptive because it includes only test additions
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

joelpittet’s picture

Issue summary: View changes
Status: Active » Needs review
Issue tags: +Novice
FileSize
653 bytes
lakshminp’s picture

Status: Needs review » Reviewed & tested by the community
webchick’s picture

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

Since this is a bug fix, seems like we need automated tests for this.

Palashvijay4O’s picture

Assigned: Unassigned » Palashvijay4O

Trying ......

Palashvijay4O’s picture

Assigned: Palashvijay4O » Unassigned
Issue tags: +SprintWeekend2015

Tagging the issue and unassigning the issue.

mark.labrecque’s picture

Assigned: Unassigned » mark.labrecque
joshi.rohit100’s picture

Where are the tests located for this ?

joelpittet’s picture

Assigned: mark.labrecque » joelpittet

I think @mark.labrecque has some, I'll get them from him tomorrow and try to nail this one down.

joelpittet’s picture

@joshi.rohit100 unless you want to tackle this? Please take it from me:)

joelpittet’s picture

Assigned: joelpittet » Unassigned
Status: Needs work » Needs review
Issue tags: -Novice, -Needs tests
FileSize
2.99 KB
3.63 KB

My ability to write tests is poor but this should do the trick. I'm trying to write a unit test but ran into two problems and I'm sure there is someone out there that knows a more elegant solution.

Problem 1. Had to include file.inc in the method because Updater breaks encapsulation by using file_scan_directory() in it's method.

Problem 2. I had to add InfoParser to a new container because the container and the service is NULL. This one is the one I think would be easier to solve as I bet there is a way to get that in setUp or something better.

The last submitted patch, 10: module_install_name-2409515-10-tests-only.patch, failed testing.

joelpittet’s picture

Status: Needs review » Needs work
  1. +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
    @@ -511,4 +514,23 @@ public function testGetModuleDirectories() {
    +    // Load the info parser onto the container for the Updater to use.
    +    $container = new ContainerBuilder();
    +    $container->set('info_parser', new InfoParser());
    +    \Drupal::setContainer($container);
    

    Is there a better place and method of doing this?

  2. +++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
    @@ -511,4 +514,23 @@ public function testGetModuleDirectories() {
    +    // Include file.inc for Updater because it uses file_scan_directory().
    +    include_once $this->root . '/core/includes/file.inc';
    

    Don't like this, breaks encapsulation. Ideas?

  3. +++ b/core/tests/Drupal/Tests/Core/Extension/modules/module_handler_test_multiple/module_handler_test_multiple_child/module_handler_test_multiple_child.info.yml
    @@ -0,0 +1,7 @@
    +core: 8.x
    ...
    \ No newline at end of file
    

    Whoops, easy fix;)

benjy’s picture

+++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
@@ -511,4 +514,23 @@ public function testGetModuleDirectories() {
+    // Load the info parser onto the container for the Updater to use.
+    $container = new ContainerBuilder();
+    $container->set('info_parser', new InfoParser());
+    \Drupal::setContainer($container);

You can just do the following: Also, maybe move it to containerBuild().
$this->container->set(...)

+++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
@@ -511,4 +514,23 @@ public function testGetModuleDirectories() {
+    include_once $this->root . '/core/includes/file.inc';

I guess you could do $this->kernel->loadLegacyIncludes() but that only does the same thing, and includes a heap of extra files.

benjy’s picture

As discussed in IRC, my last comment was wrong, I thought we were talking about Drupal\system\Tests\Extension\ModuleHandlerTest and not Drupal\Tests\Core\Extension\ModuleHandlerTest

I think your current approach is correct when extending UnitTestBase.

joelpittet’s picture

Status: Needs work » Needs review
FileSize
3.6 KB

Ok fixing the EOF newline, and moving a line under the comment it belongs. I think this is probably the best MVC we can do from @benjy's comment.

joelpittet’s picture

Manuel Garcia’s picture

Issue summary: View changes
lauriii’s picture

Status: Needs review » Reviewed & tested by the community
FileSize
89.49 KB

Tested this and seems to fix the problem described in the issue summary. Steps to reproduce this:
-on /admin/modules/install set "Install from URL" to http://ftp.drupal.org/files/projects/devel-8.x-1.x-dev.tar.gz
-Submit and you should see error message "Devel Kint is already installed.". After this patch it should be "Devel is already installed."

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 15: module_install_name-2409515-15.patch, failed testing.

The last submitted patch, 15: module_install_name-2409515-15.patch, failed testing.

joelpittet’s picture

Assigned: Unassigned » webchick

Dang, don't know what changed in head:(

+++ b/core/tests/Drupal/Tests/Core/Extension/ModuleHandlerTest.php
@@ -511,4 +514,24 @@ public function testGetModuleDirectories() {
+    include_once $this->root . '/core/includes/file.inc';

Now needs 'file_system' service on the container... this test seems to be balooning out of control for a 1 character fix...

@webchick save me from this.

webchick’s picture

Title: Module install name incorrectly chosen and parsed by Updater::findInfoFile() » Updater::findInfoFile() lacks test coverage
Issue tags: +Needs tests

Fair enough. Since this issue indirectly holds up a critical issue (#2352637: Remove the UI for installing/updating modules from update module if it is not fixed in time for release), and since the actual problem here amounts to something we won't break again unless we decide to rename .info.yml to .info.yaml or something (which wouldn't happen until D9), I think it is OK to just commit the fix for now, and continue working on tests.

Committed and pushed #1 to 8.0.x. Thanks!

I was going to spin off a sub-issue for the tests, but I don't want the people who've already done work here to accidentally lose credit. So just changing the issue title/tags to represent what's left.

webchick’s picture

Assigned: webchick » Unassigned

  • webchick committed 96b7b02 on 8.0.x
    Issue #2409515 by joelpittet: Updater::findInfoFile() lacks test...

  • webchick committed 402bfd9 on 8.0.x
    Revert "Issue #2409515 by joelpittet: Updater::findInfoFile() lacks test...
joelpittet’s picture

I think this needs a kernel test or something to avoid that type of include in the test.

joelpittet’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests
FileSize
9.16 KB
8.52 KB
lauriii’s picture

Status: Needs review » Needs work
+++ b/core/modules/system/tests/modules/module_handler_test_multiple/module_handler_test_multiple_child/module_handler_test_multiple_child.info.yml
@@ -0,0 +1,7 @@
\ No newline at end of file

Just a nit..

lauriii’s picture

Status: Needs work » Needs review
FileSize
8.49 KB

fixing joels oopsie

The last submitted patch, 28: updater_findinfofile-2409515-28-fail.patch, failed testing.

joelpittet’s picture

  1. +++ b/core/modules/system/src/Tests/Extension/InfoParserTest.php
    @@ -0,0 +1,102 @@
    + * Contains \Drupal\system\Tests\Extension\InfoParserTest.
    
    +++ /dev/null
    @@ -1,87 +0,0 @@
    - * Contains \Drupal\system\Tests\Extension\InfoParserUnitTest.
    

    Poorly named class because it's not a unit test.

  2. +++ b/core/modules/system/src/Tests/Extension/InfoParserTest.php
    @@ -0,0 +1,102 @@
    +use Drupal\Core\Updater\Updater;
    ...
    +  /**
    +   * Tests loading a project with a child project will display the correct
    +   * project title.
    +   *
    +   * @see https://drupal.org/node/2409515
    +   */
    +  public function testGetProjectTitleWithChild() {
    +    // Get the project title from it's directory. If it can't find the title
    +    // it will choose the last project title in the directory.
    +    $directory = \Drupal::root() . '/core/modules/system/tests/modules/module_handler_test_multiple';
    +    $title = Updater::getProjectTitle($directory);
    +    $this->assertEqual('module handler test multiple', $title);
    +  }
    

    Only additions to this file.

joelpittet’s picture

I'll be nicer here. The rename is moved here #2490388: InfoParserUnitTest web test classes mislabeled as unit tests which has a meta for that cause.

dawehner’s picture

index 767e0a1..05139e5 100644
--- a/core/modules/system/src/Tests/Extension/InfoParserUnitTest.php

--- a/core/modules/system/src/Tests/Extension/InfoParserUnitTest.php
+++ b/core/modules/system/src/Tests/Extension/InfoParserUnitTest.php

I guess we should move this then maybe to system/src/Tests/Updater/UpdaterKernelTest?

joelpittet’s picture

@dawehner the move is over here #2490388: InfoParserUnitTest web test classes mislabeled as unit tests so this patch is easy to read.

lauriii’s picture

Status: Needs review » Needs work

Overall is good and patch still applies

+++ b/core/modules/system/src/Tests/Extension/InfoParserUnitTest.php
@@ -84,4 +85,18 @@ public function testInfoParser() {
+   * Tests loading a project with a child project will display the correct
+   * project title.

This should be only on one line

joelpittet’s picture

Status: Needs work » Needs review
FileSize
2.53 KB
743 bytes

Thanks for the review @lauriii

lauriii’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community
lauriii’s picture

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

Oops didn't mean to RTBC yet

lauriii’s picture

Category: Bug report » Task
Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

Ok talked this quickly with Joel on IRC and the bug fix is already in the HEAD because webchick reverted it twice. So this is only about adding test coverage to it. Patch looks good anyway.

joelpittet’s picture

It's now taking the first project not the last as it did before. Minor comment fix in test.

lauriii’s picture

Still rtbc!

alexpott’s picture

Status: Reviewed & tested by the community » Fixed

More tests++

Committed 9a7b71a and pushed to 8.0.x. Thanks!

  • alexpott committed 9a7b71a on 8.0.x
    Issue #2409515 by joelpittet, lauriii: Updater::findInfoFile() lacks...

Status: Fixed » Closed (fixed)

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