OSDN Git Service

make local plugin lookup case-sensitive
authorscribu <mail@scribu.net>
Sat, 1 Feb 2014 21:52:19 +0000 (23:52 +0200)
committerscribu <mail@scribu.net>
Sat, 1 Feb 2014 21:53:00 +0000 (23:53 +0200)
the old lookup method returned false positives on case-insensitive
filesystems

(plugin basenames are treated as case-sensitive by WordPress)

fixes #958

features/plugin.feature
php/WP_CLI/Fetchers/Plugin.php

index f198ebb..4bbd84c 100644 (file)
@@ -22,17 +22,24 @@ Feature: Manage WordPress plugins
       {PLUGIN_DIR}/plugin1
       """
 
-    When I run `wp plugin scaffold zombieland --plugin_name="Zombieland"`
+    When I run `wp plugin scaffold Zombieland`
     Then STDOUT should not be empty
-    And the {PLUGIN_DIR}/zombieland/zombieland.php file should exist
-    And the {PLUGIN_DIR}/zombieland/phpunit.xml file should exist
+    And the {PLUGIN_DIR}/Zombieland/Zombieland.php file should exist
+    And the {PLUGIN_DIR}/Zombieland/phpunit.xml file should exist
+
+    # Ensure case sensitivity
+    When I try `wp plugin status zombieLand`
+    Then STDERR should contain:
+      """
+      The 'zombieLand' plugin could not be found.
+      """
 
     # Check that the inner-plugin is not picked up
-    When I run `mv {PLUGIN_DIR}/plugin1 {PLUGIN_DIR}/zombieland/`
-    And I run `wp plugin status zombieland`
+    When I run `mv {PLUGIN_DIR}/plugin1 {PLUGIN_DIR}/Zombieland/`
+    And I run `wp plugin status Zombieland`
     Then STDOUT should contain:
       """
-      Plugin zombieland details:
+      Plugin Zombieland details:
           Name: Zombieland
           Status: Inactive
           Version: 0.1-alpha
@@ -40,10 +47,10 @@ Feature: Manage WordPress plugins
           Description: PLUGIN DESCRIPTION HERE
       """
 
-    When I run `wp plugin activate zombieland`
+    When I run `wp plugin activate Zombieland`
     Then STDOUT should not be empty
 
-    When I run `wp plugin status zombieland`
+    When I run `wp plugin status Zombieland`
     Then STDOUT should contain:
       """
           Status: Active
@@ -55,28 +62,28 @@ Feature: Manage WordPress plugins
     When I run `wp plugin list`
     Then STDOUT should be a table containing rows:
       | name       | status | update | version   |
-      | zombieland | active | none   | 0.1-alpha |
+      | Zombieland | active | none   | 0.1-alpha |
 
-    When I try `wp plugin uninstall zombieland`
+    When I try `wp plugin uninstall Zombieland`
     Then STDERR should contain:
       """
-      The 'zombieland' plugin is active.
+      The 'Zombieland' plugin is active.
       """
 
-    When I run `wp plugin deactivate zombieland`
+    When I run `wp plugin deactivate Zombieland`
     Then STDOUT should not be empty
 
-    When I run `wp plugin uninstall zombieland`
+    When I run `wp plugin uninstall Zombieland`
     Then STDOUT should contain:
       """
-      Success: Uninstalled 'zombieland' plugin.
+      Success: Uninstalled 'Zombieland' plugin.
       """
     And the {PLUGIN_DIR}/zombieland file should not exist
 
     When I try the previous command again
     Then STDERR should contain:
       """
-      The 'zombieland' plugin could not be found.
+      The 'Zombieland' plugin could not be found.
       """
 
   Scenario: Install a plugin, activate, then force install an older version of the plugin
index f596725..37f3e10 100644 (file)
@@ -7,31 +7,13 @@ class Plugin extends Base {
        protected $msg = "The '%s' plugin could not be found.";
 
        public function get( $name ) {
-               $plugins = get_plugins( '/' . $name );
-
-               // some-plugin/the-plugin.php
-               while ( !empty( $plugins ) ) {
-                       $file = key( $plugins );
-                       array_shift( $plugins );
-
-                       // ignore files inside a plugin's subdirectory (like WP does)
-                       if ( dirname( $file ) == '.' ) {
-                               return (object) array(
-                                       'name' => $name,
-                                       'file' => $name . '/' . $file
-                               );
+               foreach ( get_plugins() as $file => $_ ) {
+                       if ( $file === "$name.php" ||
+                               ( dirname( $file ) === $name && $name !== '.' ) ) {
+                               return (object) compact( 'name', 'file' );
                        }
                }
 
-               // some-plugin.php
-               $file = $name . '.php';
-
-               $plugins = get_plugins();
-
-               if ( isset( $plugins[ $file ] ) ) {
-                       return (object) compact( 'name', 'file' );
-               }
-
                return false;
        }
 }