<commit_before>Feature: Install WordPress plugins

  Scenario: Branch names should be removed from Github projects
    Given a WP install

    When I run `wp plugin install https://github.com/runcommand/one-time-login/archive/master.zip --activate`
    Then STDOUT should contain:
      """
      Downloading install package from https://github.com/runcommand/one-time-login/archive/master.zip
      """
    And STDOUT should contain:
      """
      Renamed Github-based project from 'one-time-login-master' to 'one-time-login'.
      """
    And STDOUT should contain:
      """
      Plugin installed successfully.
      """
    And STDERR should be empty
    And the wp-content/plugins/one-time-login directory should exist
    And the wp-content/plugins/one-time-login-master directory should not exist

    When I try `wp plugin install https://github.com/runcommand/one-time-login/archive/master.zip`
    Then STDERR should contain:
      """
      Warning: Destination folder already exists
      """
    And the wp-content/plugins/one-time-login directory should exist
    And the wp-content/plugins/one-time-login-master directory should not exist

    When I run `wp plugin install https://github.com/runcommand/one-time-login/archive/master.zip --force`
    Then STDOUT should contain:
      """
      Plugin updated successfully.
      """
    And the wp-content/plugins/one-time-login directory should exist
    And the wp-content/plugins/one-time-login-master directory should not exist

  Scenario: Don't attempt to rename ZIPs uploaded to GitHub's releases page
    Given a WP install

    When I run `wp plugin install https://github.com/danielbachhuber/one-time-login/releases/download/v0.1.2/one-time-login.0.1.2.zip`
    Then STDOUT should contain:
      """
      Plugin installed successfully.
      """
    And STDOUT should not contain:
      """
      Renamed Github-based project from
      """
    And STDERR should be empty
    And the wp-content/plugins/one-time-login directory should exist

  Scenario: Installing respects WP_PROXY_HOST and WP_PROXY_PORT
    Given a WP install
    And a invalid-proxy-details.php file:
      """
      <?php
      define( 'WP_PROXY_HOST', 'https://wp-cli.org' );
      define( 'WP_PROXY_PORT', '443' );
      """

    When I try `wp --require=invalid-proxy-details.php plugin install edit-flow`
    Then STDERR should contain:
      """<commit_msg>added test for installing a plugin from a raw github source<commit_after>Feature: Install WordPress plugins

  Scenario: Branch names should be removed from Github projects
    Given a WP install

    When I run `wp plugin install https://github.com/runcommand/one-time-login/archive/master.zip --activate`
    Then STDOUT should contain:
      """
      Downloading install package from https://github.com/runcommand/one-time-login/archive/master.zip
      """
    And STDOUT should contain:
      """
      Renamed Github-based project from 'one-time-login-master' to 'one-time-login'.
      """
    And STDOUT should contain:
      """
      Plugin installed successfully.
      """
    And STDERR should be empty
    And the wp-content/plugins/one-time-login directory should exist
    And the wp-content/plugins/one-time-login-master directory should not exist

    When I try `wp plugin install https://github.com/runcommand/one-time-login/archive/master.zip`
    Then STDERR should contain:
      """
      Warning: Destination folder already exists
      """
    And the wp-content/plugins/one-time-login directory should exist
    And the wp-content/plugins/one-time-login-master directory should not exist

    When I run `wp plugin install https://github.com/runcommand/one-time-login/archive/master.zip --force`
    Then STDOUT should contain:
      """
      Plugin updated successfully.
      """
    And the wp-content/plugins/one-time-login directory should exist
    And the wp-content/plugins/one-time-login-master directory should not exist

  Scenario: Don't attempt to rename ZIPs uploaded to GitHub's releases page
    Given a WP install

    When I run `wp plugin install https://github.com/danielbachhuber/one-time-login/releases/download/v0.1.2/one-time-login.0.1.2.zip`
    Then STDOUT should contain:
      """
      Plugin installed successfully.
      """
    And STDOUT should not contain:
      """
      Renamed Github-based project from
      """
    And STDERR should be empty
    And the wp-content/plugins/one-time-login directory should exist

  Scenario: Don't attempt to rename ZIPs coming from a GitHub raw source
    Given a WP install

    When I run `wp plugin install https://github.com/Miller-Media/modern-wordpress/raw/master/builds/modern-framework-stable.zip`
    Then STDOUT should contain:
      """
      Plugin installed successfully.
      """
    And STDOUT should not contain:
      """
      Renamed Github-based project from
      """
    And STDERR should be empty
    And the wp-content/plugins/modern-framework directory should exist

  Scenario: Installing respects WP_PROXY_HOST and WP_PROXY_PORT
    Given a WP install
    And a invalid-proxy-details.php file:
      """
      <?php
      define( 'WP_PROXY_HOST', 'https://wp-cli.org' );
      define( 'WP_PROXY_PORT', '443' );
      """

    When I try `wp --require=invalid-proxy-details.php plugin install edit-flow`
    Then STDERR should contain:
      """
{'fraction_non_alphanumeric': 0.09409799554565701, 'fraction_numerical': 0.0033407572383073497, 'mean_word_length': 2.8138711960368012, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 13, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5693520', 'n_tokens_mistral': 1557, 'n_tokens_neox': 1507, 'n_words': 478}