Unverified Commit 84d4e497 authored by Dane Powell's avatar Dane Powell
Browse files

Issue rollup: major code style and testing fixes.

parent 077b13d0
Loading
Loading
Loading
Loading

.gitattributes

0 → 100644
+3 −0
Original line number Diff line number Diff line
/.gitattributes export-ignore
/ci export-ignore
/.travis.yml export-ignore
+50 −67
Original line number Diff line number Diff line
dist: precise
---
language: php

php:
  - 5.6
php: "7.2"

addons:
  chrome: stable

cache:
  timeout: 3600
  directories:
    - $HOME/.composer/cache
    - $HOME/.drush/cache

mysql:
  database: drupal
  username: root
  encoding: utf8

install:
  # Increase packet size and timeout for mysql.
  - sudo sed -i.bak "s/max_allowed_packet *= *.*/max_allowed_packet = 256M/g" /etc/mysql/my.cnf
  - sudo sed -i.bak "s/wait_timeout *= *.*/wait_timeout = 68800/g" /etc/mysql/my.cnf
  - sudo service mysql restart

  - export PATH="$HOME/.composer/vendor/bin:$PATH"

  # prestissimo allows composer to install packages in parallel.
  - composer global require "hirak/prestissimo:^0.3"
  - composer global require drush/drush:8.* --prefer-source

  # Install and configure Apache and PHP-FPM.
  - sudo apt-get install apache2 libapache2-mod-fastcgi
  - sudo cp ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf.default ~/.phpenv/versions/$(phpenv version-name)/etc/php-fpm.conf
  - sudo a2enmod rewrite actions fastcgi alias
  - echo "cgi.fix_pathinfo = 1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/php.ini
  - ~/.phpenv/versions/$(phpenv version-name)/sbin/php-fpm
  - sed -e "s,PATH,$TRAVIS_BUILD_DIR/../drupal,g" $TRAVIS_BUILD_DIR/../acquia-connector/scripts/travis/vhost.txt | sudo tee /etc/apache2/sites-available/default > /dev/null
  - sudo service apache2 restart

  # Download Drupal.
  - cd $TRAVIS_BUILD_DIR/..
  - git clone --depth 1 --branch 8.5.x http://git.drupal.org/project/drupal.git

  - echo "error_log=syslog" >> `php --ini | grep "Loaded Configuration" | awk '{print $4}'`

before_script:
  # Download all composer dependencies and install Drupal site.
  - cd $TRAVIS_BUILD_DIR/../drupal
  - composer install
  - composer require drupal/search_api:^1.8
  - composer require drupal/search_api_solr:^1.2
  - drush -v site-install testing --db-url=mysql://root:@localhost/drupal --yes
  - drush en --yes simpletest

  # Copy over the Acquia Connector repo and enable it.
  - cp -r ../acquia-connector modules/
  - drush en --yes acquia_connector
  - drush cr

script:
  # Setup DB connection for Simpletest.
  - export SIMPLETEST_DB=mysql://root:@localhost/drupal

  # Run the tests!
  - php core/scripts/run-tests.sh --verbose --color --php `which php` --url http://localhost 'Acquia connector,Acquia search' | tee /tmp/test.txt; export TEST_EXIT=${PIPESTATUS[0]}; echo $TEST_EXIT

  # Output the result and exit.
  - TEST_OUTPUT=$(! egrep -i "([1-9]+[0-9]* fails?)|([1-9]+[0-9]* exceptions?)|(fatal)" /tmp/test.txt > /dev/null)$?
  - php -i | grep 'php.ini'
  - sudo cat /var/log/apache2/error.log
  - echo $TEST_EXIT
  - echo $TEST_OUTPUT
  - if [ $TEST_EXIT -eq 0 ] && [ $TEST_OUTPUT -eq 0 ]; then exit 0; else exit 1; fi
    - "$HOME/.composer/cache"
    - "$HOME/.drush/cache"
    - "${TMPDIR:-/tmp}/phpstan/cache"

env:
  global:
    - ORCA_SUT_NAME=drupal/acquia_connector
    - ORCA_SUT_BRANCH=8.x-1.x
    - ORCA_VERSION=master
    - ORCA_TELEMETRY_ENABLE=TRUE

matrix:
  fast_finish: true
  include:
    - { name: "Static code analysis", env: ORCA_JOB=STATIC_CODE_ANALYSIS }
    - { name: "Deprecated code scan", env: ORCA_JOB=DEPRECATED_CODE_SCAN_SUT }
    - { name: "Isolated test w/ recommended package versions", env: ORCA_JOB=ISOLATED_RECOMMENDED }
    - { name: "Integrated test w/ recommended package versions", env: ORCA_JOB=INTEGRATED_RECOMMENDED }
    - { name: "Integrated test w/ recommended package versions & previous minor release of Drupal core", env: ORCA_JOB=CORE_PREVIOUS }
    - { name: "Isolated test w/ dev package versions", env: ORCA_JOB=ISOLATED_DEV }
    - { name: "Integrated test w/ dev package versions", env: ORCA_JOB=INTEGRATED_DEV }
    - { name: "Integrated test w/ dev package versions & next minor dev version of Drupal core", env: ORCA_JOB=CORE_NEXT }
  allow_failures:
    - env: ORCA_JOB=ISOLATED_DEV
    - env: ORCA_JOB=INTEGRATED_DEV
    - env: ORCA_JOB=CORE_NEXT

before_install:
  - git clone --branch ${ORCA_VERSION} --depth 1 https://github.com/acquia/orca.git ../orca
  - git -C ../orca apply /home/travis/build/acquia/acquia_connector/ci/deprecated-solarium-core-plugin.diff
  - ../orca/bin/travis/before_install.sh

install: ../orca/bin/travis/install.sh

before_script: ../orca/bin/travis/before_script.sh

script: ../orca/bin/travis/script.sh

before_cache: ../orca/bin/travis/before_cache.sh

after_success: ../orca/bin/travis/after_success.sh

after_failure: ../orca/bin/travis/after_failure.sh

after_script: ../orca/bin/travis/after_script.sh
+9 −16
Original line number Diff line number Diff line
@@ -3,26 +3,17 @@ Acquia Connector modules

Acquia Insight [1] enhances the Drupal experience by providing the support
and network services to operate a trouble-free Drupal website. Acquia Insight 
subscribers gain access to remote network services, documentation and
Acquia's subscriber forums. Premium subscriptions provide web-based support 
ticket management, as well as email and telephone support.
subscribers gain access to remote network services and documentation. Premium
subscriptions provide web-based support ticket management, as well as email and
telephone support.

These modules allow you to connect any Drupal 8.x site to Acquia Insight.

[1] http://www.acquia.com/products-services/acquia-insight-subscription
[1] https://www.acquia.com/products-services/acquia-insight-subscription

Modules in this project
--------------------------------------------------------------------------------

Acquia agent: Enables secure communication between your Drupal sites and
Acquia Insight to monitor uptime, check for updates, and collect site
information.

Acquia SPI: Automates the collection of site information -
operating system, database, webserver, and PHP versions, installed modules,
and site modifications - to speed support communication and issue resolution. 
Required for use with the Acquia Insight service.

Acquia Search: Provides integration between your Drupal site and Acquia's
hosted search service. Requires Apache Solr Search Integration module.

@@ -31,14 +22,16 @@ hosted search service. Requires Apache Solr Search Integration module.
Installation
--------------------------------------------------------------------------------

Consult the online documentation at https://docs.acquia.com/acquia-cloud/insight/install/ for installation instructions.
Consult the online documentation at
https://docs.acquia.com/acquia-cloud/insight/install/ for installation
instructions.


Maintainers
--------------------------------------------------------------------------------

These modules are maintained by developers at Acquia. For more information on
the company and our offerings, see http://acquia.com/
the company and our offerings, see https://www.acquia.com/

Issues
--------------------------------------------------------------------------------
@@ -47,4 +40,4 @@ Contact Acquia Support if you have support questions regarding your site.

If you have issues with the submodules included in the Acquia 
Connector package, you are also welcome to submit issues at
http://drupal.org/project/acquia_connector (all submitted issues are public).
https://drupal.org/project/acquia_connector (all submitted issues are public).
+8 −8
Original line number Diff line number Diff line
@@ -28,10 +28,10 @@
 *   Required format 'string' => array().
 */
function hook_acquia_connector_spi_get() {
  $data['example'] = array(
  $data['example'] = [
    'result' => TRUE,
    'value' => '9000',
  );
  ];
  return $data;
}

@@ -61,8 +61,8 @@ function hook_acquia_connector_spi_get() {
 *                the Insight score proportionally.
 */
function hook_acquia_connector_spi_test() {
  return array(
    'unique_example' => array(
  return [
    'unique_example' => [
      'description'    => 'This example test is useful.',
      'solved_message' => 'The test was successful',
      'failed_message' => 'The test has failed',
@@ -70,6 +70,6 @@ function hook_acquia_connector_spi_test() {
      'fix_details'    => 'Please resolve this issue using this fix information.',
      'category'       => 'best_practices',
      'severity'       => 0,
    ),
  );
    ],
  ];
}
+62 −53
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@
use Drupal\acquia_connector\Helper\Storage;
use Drupal\acquia_connector\Controller\TestStatusController;
use Drupal\acquia_connector\Subscription;
use Drupal\Core\StringTranslation\TranslatableMarkup;
use Drupal\Core\Url;

/**
@@ -22,7 +23,7 @@ function acquia_connector_uninstall() {
 * Implements hook_requirements().
 */
function acquia_connector_requirements($phase) {
  $requirements = array();
  $requirements = [];

  switch ($phase) {
    case 'runtime':
@@ -35,7 +36,7 @@ function acquia_connector_requirements($phase) {

      if ($has_credentials) {
        $key = sha1(Drupal::service('private_key')->get());
        $config_url = $description = $interval = '';
        $description = '';
        $ago = REQUEST_TIME - $last_sent;

        $blocked = $config->get('spi.blocked');
@@ -43,25 +44,38 @@ function acquia_connector_requirements($phase) {
        $is_acquia_hosted = \Drupal::service('acquia_connector.spi')->checkAcquiaHosted();
        $name_required = is_null($config->get('spi.site_name')) && is_null($config->get('spi.site_machine_name')) && !$is_acquia_hosted;

        $variables = [
          ':spi-send' => Url::fromRoute('acquia_connector.send', [], [
            'query' => [
              'destination' => Url::fromRoute('system.status')->toString(),
              'key' => $key,
            ],
            'absolute' => TRUE,
          ])->toString(),
        ];

        if ($blocked) {
          $severity = REQUIREMENT_WARNING;
          $config_url = Url::fromRoute('acquia_connector.environment_change')->toString();
          $description = (string) t('This site has been disabled from sending profile data to Acquia Cloud. <a href=":config-page">Enable this site</a>.');
          $variables[':config-page'] = $config_url;
          $description = (string) t('This site has been disabled from sending profile data to Acquia. <a href=":config-page">Enable this site</a>.', $variables);
        }
        elseif ($environment_change) {
          $severity = REQUIREMENT_ERROR;
          $config_url = Url::fromRoute('acquia_connector.environment_change')->toString();
          $description = (string) t('A change in your site\'s environment has been detected. SPI data cannot be submitted until this is resolved. Please <a href=":config-page">confirm the action you wish to take</a>.');
          $variables[':config-page'] = $config_url;
          $description = (string) t('A change in your site\'s environment has been detected. SPI data cannot be submitted until this is resolved. Please <a href=":config-page">confirm the action you wish to take</a>.', $variables);
        }
        elseif ($name_required) {
          $severity = REQUIREMENT_ERROR;
          $config_url = Url::fromRoute('acquia_connector.settings')->toString();
          $description = (string) t('You are not currently sending site profile data to Acquia Cloud. Please <a href=":config-page">provide a site name</a>.');
          $variables[':config-page'] = $config_url;
          $description = (string) t('You are not currently sending site profile data to Acquia. Please <a href=":config-page">provide a site name</a>.', $variables);
        }
        // 1.5 days ago.
        elseif ($ago >= 60 * 60 * 36) {
          $severity = REQUIREMENT_WARNING;
          $description = (string) t('SPI data has not been reported to the Acquia Subscription for more than a day.');
          $description = (string) t('SPI data has not been reported to Acquia for more than a day.');
          $description .= '<br/>';
        }
        else {
@@ -71,7 +85,8 @@ function acquia_connector_requirements($phase) {
        if (!$environment_change && !$blocked && !$name_required) {
          if (!$use_cron) {
            $config_url = Url::fromRoute('acquia_connector.settings')->toString();
            $description .= (string) t('You are not sending SPI data via Drupal\'s cron system. <a href=":config-page">View Acquia Subscription configuration</a> for details.');
            $variables[':config-page'] = $config_url;
            $description .= (string) t('You are not sending SPI data via Drupal\'s cron system. <a href=":config-page">View Acquia Subscription configuration</a> for details.', $variables);
            $description .= '<br/>';
          }
          else {
@@ -79,34 +94,26 @@ function acquia_connector_requirements($phase) {
            if ($config->get('cron_interval_override')) {
              $interval = $config->get('cron_interval_override');
            }
            $description .= (string) t('SPI data will be sent once every @interval minutes once cron is called.');
            $variables['@interval'] = $interval;
            $description .= (string) t('SPI data will be sent once every @interval minutes once cron is called.', $variables);
            $description .= ' ';
          }
          $description .= (string) t('You can <a href=":spi-send">manually send SPI data</a>.');
          $description .= (string) t('You can <a href=":spi-send">manually send SPI data</a>.', $variables);
        }

        if ($last_sent == 0) {
          $value = (string) t('SPI data has not been sent');
        }
        else {
          $value = (string) t('Last sent @time ago', array('@time' => \Drupal::service('date.formatter')->formatInterval($ago)));
          $value = (string) t('Last sent @time ago', ['@time' => \Drupal::service('date.formatter')->formatInterval($ago)]);
        }
        $requirements['acquia_spi'] = array(

        $requirements['acquia_spi'] = [
          'title' => t('Acquia Subscription SPI'),
          'severity' => $severity,
          'value' => $value,
          'description' => t($description, array(
            '@interval' => $interval,
            ':config-page' => $config_url,
            ':spi-send' => Url::fromRoute('acquia_connector.send', array(), array(
              'query' => array(
                'destination' => 'admin/reports/status',
                'key' => $key,
              ),
              'absolute' => TRUE,
            ))->toString(),
          )),
        );
          'value' => new TranslatableMarkup($value),
          'description' => new TranslatableMarkup($description),
        ];
      }

      // Inform users on subscription status. Either we know they are active,
@@ -114,73 +121,74 @@ function acquia_connector_requirements($phase) {
      // we have credentials but an inactive subscription (either bad
      // credentials or expired subscription).
      if ($subscription->isActive()) {
        $requirements['acquia_subscription_status'] = array(
        $requirements['acquia_subscription_status'] = [
          'title' => t('Acquia Subscription status'),
          'severity' => REQUIREMENT_OK,
          'value' => t('Active'),
          'description' => t('You can <a href=":refresh-status">manually refresh the subscription status</a>.', array(
            ':refresh-status' => Url::fromRoute('acquia_connector.refresh_status', array(), array('absolute' => TRUE))
          'description' => t('You can <a href=":refresh-status">manually refresh the subscription status</a>.', [
            ':refresh-status' => Url::fromRoute('acquia_connector.refresh_status', [], ['absolute' => TRUE])
              ->toString(),
          )),
        );
          ]),
        ];
      }
      elseif (!$has_credentials) {
        $requirements['acquia_subscription_status'] = array(
        $requirements['acquia_subscription_status'] = [
          'title' => t('Acquia Subscription status'),
          'severity' => REQUIREMENT_WARNING,
          'value' => t('Unknown'),
          'description' => t('You did not complete your signup to the Acquia Subscription. You can provide the subscription identifier and the subscription key at the <a href=":settings">Acquia settings</a> page or try to <a href=":refresh-status">manually refresh the subscription status</a>.', [':settings' => Url::fromRoute('acquia_connector.settings')->toString(), ':refresh-status' => Url::fromRoute('acquia_connector.refresh_status')->toString()]),
        );
          'description' => t('You did not complete your signup to Acquia. You can provide the subscription identifier and the subscription key at the <a href=":settings">Acquia settings</a> page or try to <a href=":refresh-status">manually refresh the subscription status</a>.', [':settings' => Url::fromRoute('acquia_connector.settings')->toString(), ':refresh-status' => Url::fromRoute('acquia_connector.refresh_status')->toString()]),
        ];
      }
      else {
        $subscription = $config->get('subscription_data');
        $href = isset($subscription['uuid']) ? 'https://cloud.acquia.com/app/develop/applications/' . $subscription['uuid'] : 'https://cloud.acquia.com';
        $requirements['acquia_subscription_status'] = array(
        $requirements['acquia_subscription_status'] = [
          'title' => t('Acquia Subscription status'),
          'severity' => REQUIREMENT_WARNING,
          'value' => t('Inactive'),
          'description' => t('Your subscription is expired or you are using an invalid identifier and key pair. You can check the subscription identifier and the subscription key at the <a href=":settings">Acquia settings</a> page. Check <a href=":acquia-network">your subscription on the Acquia Subscription</a> for further status information.', [':settings' => Url::fromRoute('acquia_connector.settings')->toString(), ':acquia-network' => $href]),
        );
        ];
      }

      // Acquia SPI custom tests status.
      $variables = array(
      $variables = [
        ':help' => Url::fromUri('base:admin/help/acquia_connector', ['absolute' => TRUE])
          ->toString(),
        ':validate' => Url::fromRoute('acquia_connector.test_validate', [], ['absolute' => TRUE])
          ->toString(),
      );
      ];

      $modules = \Drupal::moduleHandler()->getImplementations('acquia_connector_spi_test');
      if (empty($modules)) {
        $description = (string) t('No custom tests were detected in any module.') . '<br/>';
        $value       = (string) t('Not implemented (<a href=":help">more information</a>)');
        $description = t('No custom tests were detected in any module.');
        $value       = t('Not implemented (<a href=":help">more information</a>)', $variables);
        $severity    = REQUIREMENT_OK;
      }
      else {
        $status = new TestStatusController();
        $result = $status->testStatus();

        if (!empty($result)) {
          $modules = implode(', ', array_keys($result));
          $description = (string) t('Custom tests within the following module(s) have failed validation and will not be sent: %modules. <br/>Please check the error logs for more information regarding how to pass validation or <a href=":validate">perform another validation check</a>. A validation check can also be performed via the Drush command, "spi-test-validate".');
          $value       = (string) t('Failed (<a href=":help">more information</a>)');
          $variables['%modules'] = implode(', ', array_keys($result));
          $description = t('Custom tests within the following module(s) have failed validation and will not be sent: %modules. <br/>Please check the error logs for more information regarding how to pass validation or <a href=":validate">perform another validation check</a>. A validation check can also be performed via the Drush command, "spi-test-validate".', $variables);
          $value = t('Failed (<a href=":help">more information</a>)', $variables);
          $severity = REQUIREMENT_ERROR;
        }
        else {
          $modules     = implode(', ', $modules);
          $description = (string) t('Custom test data is structured properly and is sending from: %modules');
          $value       = (string) t('Passed');
          $variables['%modules'] = implode(', ', $modules);
          $description = t('Custom test data is structured properly and is sending from: %modules', $variables);
          $value = t('Passed');
          $severity = REQUIREMENT_OK;
        }

        $variables['%modules'] = $modules;
      }
      $requirements['acquia_spi_test'] = array(

      $requirements['acquia_spi_test'] = [
        'title'       => t('Acquia Subscription SPI Custom Tests'),
        'description' => t($description, $variables),
        'value'       => t($value, $variables),
        'description' => $description,
        'value'       => $value,
        'severity'    => $severity,
      );
      ];
      break;
  }

@@ -241,6 +249,8 @@ function acquia_connector_update_8004() {
}

/**
 * Move Acquia Subscription credentials into State.
 *
 * Remove Acquia Subscription credentials from the config and place it into the
 * State storage. For more info see https://www.drupal.org/node/2635138.
 */
@@ -261,7 +271,6 @@ function acquia_connector_update_8005() {
  $config->save(TRUE);
}


/**
 * Delete the spi module diff data settings.
 */
Loading