Fix: Second Contributors Affiliation not loaded (#1052) #1315
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: PHPUnit Tests | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "**" ] | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| services: | |
| mysql: | |
| image: mysql:8.0 | |
| env: | |
| MYSQL_ROOT_PASSWORD: root_password | |
| MYSQL_DATABASE: mde2-msl-test | |
| MYSQL_USER: test_user | |
| MYSQL_PASSWORD: test_password | |
| ports: | |
| - 3306:3306 | |
| options: >- | |
| --health-cmd "mysqladmin ping --silent" | |
| --health-interval 10s | |
| --health-timeout 5s | |
| --health-retries 3 | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up PHP | |
| uses: shivammathur/setup-php@v2 | |
| with: | |
| php-version: '8.5' | |
| extensions: mbstring, xml, ctype, iconv, intl, pdo_sqlite, pdo_mysql, mysqli, zip | |
| coverage: xdebug | |
| - name: Determine Composer cache directory | |
| id: composer-cache | |
| run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT | |
| - name: Cache Composer dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: ${{ steps.composer-cache.outputs.dir }} | |
| key: ${{ runner.os }}-php-8.5-composer-${{ hashFiles('**/composer.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-php-8.5-composer- | |
| ${{ runner.os }}-php-composer- | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '24' | |
| cache: 'npm' | |
| - name: Install PHP dependencies | |
| run: | | |
| composer install --prefer-dist --no-progress --no-suggest | |
| composer dump-autoload -o | |
| - name: Validate composer.json and composer.lock | |
| run: composer validate --strict | |
| - name: Install JS dependencies | |
| run: npm ci | |
| - name: Wait for MySQL to be ready | |
| run: | | |
| for i in {30..0}; do | |
| if mysqladmin ping -h127.0.0.1 --silent; then | |
| break | |
| fi | |
| echo 'Waiting for MySQL...' | |
| sleep 5 | |
| done | |
| if [ "$i" = 0 ]; then | |
| echo >&2 'MySQL did not start in time.' | |
| exit 1 | |
| fi | |
| - name: Grant privileges to test_user | |
| run: | | |
| mysql -h127.0.0.1 -uroot -proot_password -e " | |
| CREATE USER IF NOT EXISTS 'test_user'@'%' IDENTIFIED BY 'test_password'; | |
| GRANT ALL PRIVILEGES ON *.* TO 'test_user'@'%'; | |
| FLUSH PRIVILEGES; | |
| " | |
| - name: Create settings.php | |
| run: | | |
| cat <<'PHP' > settings.php | |
| <?php | |
| function connectDb() { | |
| $host = '127.0.0.1'; | |
| $username = 'test_user'; | |
| $password = 'test_password'; | |
| $database = 'mde2-msl-test'; | |
| $conn = new mysqli($host, $username, $password, $database); | |
| return $conn; | |
| } | |
| // Establish the database connection (skip in unit testing context) | |
| if (!defined('INCLUDED_FROM_TEST')) { | |
| $connection = connectDb(); | |
| } | |
| $apiKeyElmo = '1234-1234-1234-1234'; | |
| $apiKeyGoogleMaps = 'test_api_key'; | |
| $apiKeyTimezone = 'test_timezone_api_key'; | |
| $ernieUrl = ''; | |
| $ernieApiKey = ''; | |
| $ernieCacheTtl = 21600; | |
| $dataUploadUrl = getenv('DATA_UPLOAD_URL') ?: ''; | |
| $maxTitles = 2; | |
| $showMslLogo = false; | |
| $showContributorPersons = true; | |
| $showContributorInstitutions = true; | |
| $showGcmdThesauri = true; | |
| $showFreeKeywords = true; | |
| $showSpatialTemporalCoverage = true; | |
| $showRelatedWork = true; | |
| $showFundingReference = true; | |
| $showAuthorInstitution = true; | |
| $showLicense = true; | |
| $defaultLicense = 'CC-BY-4.0'; | |
| $showMslLabs = false; | |
| $mslLabsUrl = 'https://raw.githubusercontent.com/UtrechtUniversity/msl_vocabularies/main/vocabularies/labs/laboratories.json'; | |
| $showMslVocabs = false; | |
| $mslVocabsUrl = ''; | |
| $showUsedInstruments = false; | |
| $showGGMsProperties = false; | |
| $showFeedbackLink = true; | |
| $smtpHost = 'smtp.test.de'; | |
| $smtpPort = 465; | |
| $smtpUser = 'test_user'; | |
| $smtpPassword = 'test_password'; | |
| $smtpSender = '[email protected]'; | |
| $smtpSecure = ''; | |
| $smtpAuth = ''; | |
| $SIMULATE_EMAIL = true; | |
| $feedbackAddress = '[email protected]'; | |
| $xmlSubmitAddress = '[email protected]'; | |
| $instanceTitle = 'ELMO Test'; | |
| function getSettings($setting) { | |
| global $apiKeyGoogleMaps, $showMslLabs; | |
| header('Content-Type: application/json; charset=utf-8'); | |
| switch ($setting) { | |
| case 'apiKey': | |
| echo json_encode(['apiKey' => $apiKeyGoogleMaps]); | |
| break; | |
| case 'all': | |
| echo json_encode(['apiKey' => $apiKeyGoogleMaps, 'showMslLabs' => $showMslLabs]); | |
| break; | |
| default: | |
| echo json_encode(['error' => 'Unknown setting']); | |
| break; | |
| } | |
| exit; | |
| } | |
| if (isset($_GET['setting'])) { | |
| getSettings($_GET['setting']); | |
| exit; | |
| } | |
| function elmo_log($msg) { | |
| error_log('[ELMO save_data] ' . $msg); | |
| } | |
| PHP | |
| - name: Initialize database structure and lookup data | |
| run: php -r "require 'install.php'; createDatabaseStructure(\$connection); insertLookupData(\$connection);" | |
| - name: Start PHP built-in web server | |
| run: | | |
| php -S localhost:8000 -t . tests/server.php 2>&1 > server.log & | |
| echo $! > server.pid | |
| sleep 10 | |
| echo "Testing initial API endpoints:" | |
| curl -v http://localhost:8000/api/v2/general/alive | |
| echo "\nTesting licenses endpoint:" | |
| curl -v http://localhost:8000/api/v2/vocabs/licenses/all | |
| echo "\nInitial server log contents:" | |
| cat server.log | |
| echo "\nPHP error log:" | |
| if [ -f /var/log/php_errors.log ]; then | |
| cat /var/log/php_errors.log | |
| fi | |
| - name: Set PHPUnit permissions | |
| run: chmod +x vendor/bin/phpunit | |
| - name: Run PHPUnit tests | |
| env: | |
| API_BASE_URL: http://localhost:8000 | |
| run: | | |
| set -euo pipefail | |
| output_file="$(mktemp)" | |
| if ! vendor/bin/phpunit --configuration phpunit.xml 2>&1 | tee "$output_file"; then | |
| echo "PHPUnit test run failed." | |
| exit 1 | |
| fi | |
| if grep -q "No tests executed" "$output_file"; then | |
| echo "PHPUnit completed without executing tests." | |
| exit 1 | |
| fi | |
| echo "\nFinal Server Log:" | |
| cat server.log | |
| - name: Generate coverage (PHP 8.5 push builds only) | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| env: | |
| API_BASE_URL: http://localhost:8000 | |
| XDEBUG_MODE: coverage | |
| run: | | |
| echo "Checking Xdebug status:" | |
| php -m | grep -i xdebug || echo "Xdebug not found!" | |
| php -v | |
| vendor/bin/phpunit --configuration phpunit.coverage.xml | |
| echo "\nChecking clover.xml:" | |
| if [ -f clover.xml ]; then | |
| echo "clover.xml created successfully!" | |
| head -20 clover.xml | |
| else | |
| echo "ERROR: clover.xml was not created!" | |
| fi | |
| - name: Upload coverage to Codecov | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| uses: codecov/codecov-action@v5 | |
| with: | |
| token: ${{ secrets.CODECOV_TOKEN }} | |
| files: ./clover.xml | |
| flags: php | |
| name: phpunit-coverage | |
| fail_ci_if_error: true | |
| verbose: true | |
| - name: Stop PHP server | |
| if: always() | |
| run: | | |
| if [ -f server.pid ]; then | |
| kill "$(cat server.pid)" | |
| else | |
| echo "server.pid not found; PHP server was likely not started." | |
| fi |