language: php

# Solr 6.x doesn't work with the Java versions included in "xenial" or "bionic".
dist: trusty

php:
  - 7.1
  - 7.3
  - 7.4

env:
  - SOLR_VERSION=8.4.1 DRUPAL_BRANCH=9.0.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
  - SOLR_VERSION=8.4.1 DRUPAL_BRANCH=9.0.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
  - SOLR_VERSION=8.4.1 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
  - SOLR_VERSION=8.4.1 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
  - SOLR_VERSION=8.4.1 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
  - SOLR_VERSION=8.4.1 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
  - SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
  - SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
  - SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
  - SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
  - SOLR_VERSION=6.6.6 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
  - SOLR_VERSION=6.6.6 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
  - SOLR_VERSION=6.6.6 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
  - SOLR_VERSION=6.6.6 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false

git:
  # The depth needs to be increased. The default of 50 leads to fatal: reference
  # repository '/home/travis/.cache/composer/vcs/-home-travis-build-mkalkbrenner
  # -search-api-solr/' is shallow.
  depth: 10000

cache:
  directories:
    - $HOME/.composer/cache
    - solr_downloads

services:
  - mysql

before_install:
  - phpenv config-rm xdebug.ini || true
  - composer global require "hirak/prestissimo:^0.3"
  - ls solr_downloads/
  - wget -nc --continue -v --tries=3 --directory-prefix=solr_downloads "http://archive.apache.org/dist/lucene/solr/${SOLR_VERSION}/solr-${SOLR_VERSION}.tgz"
  - tar -xzf solr_downloads/solr-${SOLR_VERSION}.tgz
  - mysql -e 'CREATE DATABASE drupal;'
  - patch -p1 < tests/travis_no_deps.patch
  - git commit -m 'no deps' search_api_solr.info.yml
  - git tag 3.99

install:
  # Make sure we don't fail when checking out projects.
  - echo -e "Host github.com\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
  - echo -e "Host git.drupal.org\n\tStrictHostKeyChecking no\n" >> ~/.ssh/config
  # Set sendmail so drush doesn't throw an error during site install.
  - echo "sendmail_path='true'" >> `php --ini | grep "Loaded Configuration" | awk '{print $4}'`
  # Forward the errors to the syslog so we can print them
  - echo "error_log=syslog" >> `php --ini | grep "Loaded Configuration" | awk '{print $4}'`
  # Get the Drupal core.
  - cd $TRAVIS_BUILD_DIR/..
  - git clone --depth=1 --branch $DRUPAL_BRANCH https://git.drupal.org/project/drupal.git
  - cd $TRAVIS_BUILD_DIR/../drupal
  - composer install
  - composer config repositories.search_api_solr vcs $TRAVIS_BUILD_DIR
  - |
    if [ ${DRUPAL_BRANCH} != "9.0.x" ]; then
      composer require --no-suggest symfony/event-dispatcher:"4.3.4 as 3.4.99"
    fi
  - composer require solarium/solarium:"dev-master as 5.1.99" drupal/search_api:1.x-dev drupal/search_api_autocomplete:1.x-dev drupal/search_api_solr:3.99 drupal/search_api_location:1.x-dev drupal/facets:1.x-dev drupal/geofield:1.x-dev drupal/composer_deploy drush/drush:$DRUSH_VERSION drupal/drush_language:1.x-dev drupal/devel monolog/monolog
  - |
    if [ ${DRUPAL_BRANCH} == "8.7.x" ]; then
      composer run-script drupal-phpunit-upgrade
    fi
  # Patch template.
  #########################################
  # to be removed once #2824932 is resolved
  #- cd modules/contrib/search_api
  #- curl https://www.drupal.org/files/issues/2018-12-20/3021717.patch | patch -p1
  #- cd $TRAVIS_BUILD_DIR/../drupal
  #########################################
  - cp $TRAVIS_BUILD_DIR/tests/travis.phpunit.xml $TRAVIS_BUILD_DIR/../drupal/core/phpunit.xml.dist

before_script:
  - export SOLR_INDEX_WAIT=4
  - export SYMFONY_DEPRECATIONS_HELPER=disabled
  # Start the built-in php web server (mysql is already started) and suppress
  # web server access logs output.
  - php -S localhost:8888 >& /dev/null &
  # Install the site.
  - ./vendor/bin/drush -v site-install minimal --db-url=mysql://root:@localhost/drupal --yes
  - ./vendor/bin/drush en --yes drush_language
  - ./vendor/bin/drush language-add ar
  - ./vendor/bin/drush language-add bg
  - ./vendor/bin/drush language-add ca
  - ./vendor/bin/drush language-add cs
  - ./vendor/bin/drush language-add da
  - ./vendor/bin/drush language-add de
  - ./vendor/bin/drush language-add el
  - ./vendor/bin/drush language-add es
  - ./vendor/bin/drush language-add et
  - ./vendor/bin/drush language-add fa
  - ./vendor/bin/drush language-add fi
  - ./vendor/bin/drush language-add fr
  - ./vendor/bin/drush language-add ga
  - ./vendor/bin/drush language-add hi
  - ./vendor/bin/drush language-add hr
  - ./vendor/bin/drush language-add id
  - ./vendor/bin/drush language-add it
  - ./vendor/bin/drush language-add ja
  - ./vendor/bin/drush language-add lv
  - ./vendor/bin/drush language-add nb
  - ./vendor/bin/drush language-add nl
  - ./vendor/bin/drush language-add nn
  - ./vendor/bin/drush language-add no
  - ./vendor/bin/drush language-add pl
  - ./vendor/bin/drush language-add pt-pt
  - ./vendor/bin/drush language-add pt-br
  - ./vendor/bin/drush language-add ro
  - ./vendor/bin/drush language-add ru
  - ./vendor/bin/drush language-add sk
  - ./vendor/bin/drush language-add sr
  - ./vendor/bin/drush language-add sv
  - ./vendor/bin/drush language-add th
  - ./vendor/bin/drush language-add tr
  - ./vendor/bin/drush language-add uk
  - ./vendor/bin/drush language-add zh-hans
  - ./vendor/bin/drush language-add zh-hant
  # Let dev versions fulfill module version dependencies.
  - ./vendor/bin/drush en composer_deploy --yes
  # Generate a multilingual Solr configuration. Therefore we have to install the
  # test modules before the tests.
  - cp -a core/modules/system/tests/modules/entity_test core/modules/system/entity_test
  - cp -a modules/contrib/search_api/tests/search_api_test_example_content modules/contrib/search_api/search_api_test_example_content
  - cp -a modules/contrib/search_api_solr/tests/modules/search_api_solr_test modules/contrib/search_api_solr/search_api_solr_test
  - ./vendor/bin/drush en --yes search_api_solr_test
  - |
      if [ ${SOLR_CLOUD} == "true" ]; then
        ./vendor/bin/drush -v solr-gsc solr_search_server_cloud conf.zip $SOLR_VERSION
      else
        ./vendor/bin/drush -v solr-gsc solr_search_server conf.zip $SOLR_VERSION
      fi
  - rm -rf core/modules/system/entity_test modules/contrib/search_api/search_api_test_example_content modules/contrib/search_api_solr/search_api_solr_test
  - mkdir $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/server/solr/d8
  - mkdir $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/server/solr/d8/conf
  - unzip -o conf.zip -d $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/server/solr/d8/conf
  # - ls -lh $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/server/solr/d8/conf
  # - cat $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/server/solr/d8/conf/solrconfig_extra.xml
  - |
    if [ ${SOLR_CLOUD} == "true" ]; then
       $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/bin/solr start -e cloud -noprompt || travis_terminate 1;
       $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/bin/solr delete -c gettingstarted || travis_terminate 1;
       $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/bin/solr create -c techproducts -s 2 -rf 2 -d $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/server/solr/configsets/sample_techproducts_configs/conf -n sample_techproducts_configs || travis_terminate 1;
       $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/bin/post -c techproducts $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/example/exampledocs/*.xml || travis_terminate 1;
       $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/bin/solr create -c d8 -s 2 -rf 2 -d $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/server/solr/d8/conf -n d8 || travis_terminate 1;
       $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/bin/solr create -c checkpoints -s 1 -rf 2 || travis_terminate 1;
    else
       $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/bin/solr start -e techproducts || travis_terminate 1;
       $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/bin/solr create -c d8 -d $TRAVIS_BUILD_DIR/solr-${SOLR_VERSION}/server/solr/d8/conf || travis_terminate 1;
    fi

script:
  # Run the tests within the drupal directory.
  - cd $TRAVIS_BUILD_DIR/../drupal
  - vendor/bin/phpunit -c core --group search_api_solr modules/contrib/search_api_solr

after_script:
  - |
    if [ -f $TRAVIS_BUILD_DIR/solr.error.log ]; then
        cat $TRAVIS_BUILD_DIR/solr.error.log;
    fi

matrix:
  exclude:
    - php: 7.1
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=9.0.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.1
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=9.0.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
    - php: 7.1
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.1
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
    - php: 7.1
      env: SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.1
      env: SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
    - php: 7.4
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.4
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
    - php: 7.4
      env: SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.4
      env: SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
    - php: 7.4
      env: SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.4
      env: SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
    - php: 7.4
      env: SOLR_VERSION=7.7.2 DRUPAL_BRANCH=8.6.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
    - php: 7.4
      env: SOLR_VERSION=6.6.6 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.4
      env: SOLR_VERSION=6.6.6 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
    - php: 7.4
      env: SOLR_VERSION=6.6.6 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.4
      env: SOLR_VERSION=6.6.6 DRUPAL_BRANCH=8.7.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
  allow_failures:
    - php: 7.3
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=9.0.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.3
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=9.0.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
    - php: 7.4
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=9.0.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.4
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=9.0.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
    - php: 7.4
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=true
    - php: 7.4
      env: SOLR_VERSION=8.4.1 DRUPAL_BRANCH=8.8.x DRUSH_VERSION=~10.1.0 SOLR_CLOUD=false
