sudo: false
dist: trusty
language: php
php:
    - 5.6
    - 7
    - 7.1
    - 7.2
    - nightly

env:
    global:
        - CORE_BRANCH=stable13
        - MOZ_HEADLESS=1
    matrix:
        - DB=pgsql

matrix:
    allow_failures:
        - env: DB=pgsql CORE_BRANCH=master
        - php: nightly
    include:
        - php: 7.1
          env: DB=sqlite
        - php: 7.1
          env: DB=mysql
        - php: 7.1
          env:  DB=pgsql CORE_BRANCH=master
    fast_finish: true

before_install:
    - make
    # install core
    - cd ../
    - git clone https://github.com/nextcloud/server.git --recursive --depth 1 -b $CORE_BRANCH nextcloud
    - mv news nextcloud/apps/

before_script:
    - if [[ "$DB" == 'pgsql' ]]; then psql -c "CREATE ROLE oc_autotest LOGIN PASSWORD 'oc_autotest'" -U postgres; fi
    - if [[ "$DB" == 'pgsql' ]]; then psql -c "CREATE DATABASE oc_autotest OWNER oc_autotest;" -U postgres; fi
    - if [[ "$DB" == 'mysql' ]]; then mysql -u root -e 'CREATE DATABASE oc_autotest;'; fi
    - if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "CREATE USER 'oc_autotest'@'localhost' IDENTIFIED BY 'oc_autotest';"; fi
    - if [[ "$DB" == 'mysql' ]]; then mysql -u root -e "GRANT ALL ON oc_autotest.* TO 'oc_autotest'@'localhost';"; fi
    # fill nextcloud with default configs and enable news
    - cd nextcloud
    - mkdir data
    - ./occ maintenance:install --database-name oc_autotest --database-user oc_autotest --admin-user admin --admin-pass admin --database $DB --database-pass="oc_autotest"
    - ./occ app:enable news
    - ./occ app:check-code news
    - ./occ background:cron  # enable default cron
    - php -S localhost:8080 &
    - cd apps/news

script:
    - make test

after_failure:
    - cat ../../data/nextcloud.log

addons:
    firefox: "latest-beta"
    postgresql: "9.6"

services:
    - mysql
