language: php

sudo: required
dist: bionic

php:
  - 7.1
  - 7.2
  - 7.3
  - 7.4

addons:
  chrome: stable

services:
  - mysql
  - xvfb

mysql:
  database: drupal
  username: root
  encoding: utf8

before_install:
  - export CHROME_BIN=chromium-browser
  - export DISPLAY=:99.0
  - wget http://chromedriver.storage.googleapis.com/83.0.4103.39/chromedriver_linux64.zip && unzip chromedriver_linux64.zip && sudo mv chromedriver /usr/bin

install:
  # Set unlimited memory_limit.
  - INI_FILE=~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
  - echo "memory_limit = -1" >> "${INI_FILE}"

  # Remove xdebug for the moment. We aren't generating code coverage, and it slows us down.
  - mv ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini /tmp/xdebug.ini

before_script:
  # Create drupal database.
  - mysql -u root -e "CREATE DATABASE drupal;"
  # Set up DB user.
  - mysql -uroot -e "CREATE USER drupal@localhost IDENTIFIED BY 'drupal';"
  - mysql -uroot -e "GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER, CREATE TEMPORARY TABLES ON drupal.* TO 'drupal'@'localhost' IDENTIFIED BY 'drupal';"

  # Set github access token for composer if available.
  - if [[ $GITHUB_OAUTH_TOKEN ]]; then git config --global github.accesstoken $GITHUB_OAUTH_TOKEN; fi
  # Copy module to tmp dir for later use.
  - mkdir /tmp/bee; cp -r * /tmp/bee
  # Update composer.
  - composer -n self-update

  # Install drush.
  - export PATH="$HOME/.composer/vendor/bin:$PATH"
  - composer -n global require drush/drush:8.*
  # Install code sniffer.
  - composer -n global require drupal/coder
  # Register Drupal coding standards.
  - phpcs --config-set installed_paths ~/.composer/vendor/drupal/coder/coder_sniffer
  # Don't display warnings.
  - phpcs --config-set show_warnings 0

  # Make the site.
  - cd $TRAVIS_BUILD_DIR
  - drush make test/project.make bee

  # Copy the bee module into the Drupal site.
  - mkdir -p bee/sites/all/modules/bee
  - mv /tmp/bee bee/sites/all/modules/bee

  # Install BAT library.
  - cd $TRAVIS_BUILD_DIR/bee
  - composer require "roomify/bat"
  # Install RRULE library.
  - composer require "rlanvin/php-rrule"

  - php -d sendmail_path=$(which true) ~/.composer/vendor/bin/drush.php --yes site-install --db-url=mysql://drupal:drupal@127.0.0.1/drupal --account-name=admin --account-pass=test --site-mail=webmaster@roomify.us --site-name="bee"
  # Following step with -y should also run composer install.
  - drush -y en bat bat_api bat_calendar_reference bat_event bat_event_ui bat_facets bat_fullcalendar bat_unit bee bee_webform
  - drush cr all --yes

script:
  - if [ "${TRAVIS_PHP_VERSION}" == '7.3' ]; then composer global require mglaman/drupal-check; fi;

  # Run drupal-check
  - cd $TRAVIS_BUILD_DIR/bee/sites/all/modules/bee/bee
  - if [ "${TRAVIS_PHP_VERSION}" == '7.3' ]; then drupal-check -ad bee.module; fi;
  - if [ "${TRAVIS_PHP_VERSION}" == '7.3' ]; then drupal-check -ad bee.install; fi;
  - if [ "${TRAVIS_PHP_VERSION}" == '7.3' ]; then drupal-check -ad src; fi;
  - if [ "${TRAVIS_PHP_VERSION}" == '7.3' ]; then drupal-check -ad modules; fi;

  # Check coding standards.
  - phpcs --standard=Drupal --exclude=Drupal.Arrays.Array,Drupal.Commenting.FunctionComment,Drupal.Commenting.DocComment,Drupal.Commenting.FileComment,Drupal.NamingConventions.ValidFunctionName,Drupal.NamingConventions.ValidVariableName,Drupal.InfoFiles.AutoAddedKeys,Drupal.InfoFiles.ClassFiles --report-width=74 --extensions=php,module,inc,install,test,profile,theme,info,txt,md,yml --ignore=test $TRAVIS_BUILD_DIR/bee/sites/all/modules/bee

# Cache composer/drush files
cache:
  directories:
    - $HOME/.cache
    - $HOME/.composer/cache
    - vendor
    - $HOME/.drush/cache
