param( [Parameter(Mandatory)][string]$Env ) . "$PSScriptRoot\common.ps1" $environment = Get-TestLabEnvironment -Name $Env Write-ComposeFile -Environment $environment $result = [ordered]@{ environment = $environment.name wordpressImage = $environment.wordpressImage dbImage = $environment.dbImage hostPort = $environment.hostPort startedAt = (Get-Date).ToString('o') checks = @() } function Add-Check { param([string]$Name, [bool]$Passed, [string]$Detail = '') $script:result.checks += [ordered]@{ name = $Name; passed = $Passed; detail = $Detail } if ($Passed) { Write-Host "[PASS] $Name $Detail" } else { Write-Host "[FAIL] $Name $Detail" throw "Check failed: $Name $Detail" } } try { Invoke-Compose $environment @('up', '-d') | Out-Host $wpCli = 'if ! command -v wp >/dev/null 2>&1; then curl -fsSL https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar -o /usr/local/bin/wp && chmod +x /usr/local/bin/wp; fi' Invoke-WpCliRoot $environment $wpCli | Out-Host Add-Check 'wp-cli available' $true if ($environment.PSObject.Properties.Name -contains 'wordpressVersion' -and $environment.wordpressVersion) { Invoke-WpCli $environment "wp core download --version=$($environment.wordpressVersion) --force --path=/var/www/html" | Out-Host Add-Check 'wordpress core version prepared' $true "target=$($environment.wordpressVersion)" } $installScript = @' #!/usr/bin/env bash set -e for i in $(seq 1 40); do if wp core is-installed --path=/var/www/html >/dev/null 2>&1; then exit 0 fi if wp core install --path=/var/www/html --url=http://localhost:__HOST_PORT__ --title=PluginTest --admin_user=admin --admin_password=adminpass --admin_email=admin@example.test --skip-email; then exit 0 fi sleep 3 done exit 1 '@ -replace '__HOST_PORT__', [string]$environment.hostPort Write-ContainerTextFile $environment '/tmp/brt-install.sh' $installScript '0755' Invoke-WpCli $environment 'bash /tmp/brt-install.sh' | Out-Host $installed = (Invoke-WpCli $environment 'wp core is-installed --path=/var/www/html && echo installed' | Out-String).Trim() Add-Check 'wordpress installed' ($installed -eq 'installed') $installed $phpVersion = (Invoke-WpCliRoot $environment "php -r 'echo PHP_VERSION;'" | Out-String).Trim() $wpVersion = (Invoke-WpCli $environment 'wp core version --path=/var/www/html' | Out-String).Trim() Add-Check 'runtime versions' $true "WP=$wpVersion PHP=$phpVersion" $result.phpVersion = $phpVersion $result.wordpressVersion = $wpVersion Invoke-WpCli $environment "wp plugin activate $PluginSlug --path=/var/www/html" | Out-Host Add-Check 'plugin activated' $true $pluginVersion = (Invoke-WpCli $environment "wp plugin get $PluginSlug --field=version --path=/var/www/html" | Out-String).Trim() Add-Check 'plugin version detected' ($pluginVersion -eq $ExpectedPluginVersion) "version=$pluginVersion" $result.pluginVersion = $pluginVersion $tablePhp = @' get_var($wpdb->prepare('SHOW TABLES LIKE %s', $wpdb->prefix . 'brt_verses')); '@ Write-ContainerPhpFile $environment '/tmp/brt-table.php' $tablePhp $tableExists = (Invoke-WpCli $environment 'wp eval-file /tmp/brt-table.php --path=/var/www/html' | Out-String).Trim() Add-Check 'verse table created' ($tableExists -eq 'wp_brt_verses') $tableExists $translationsToImport = @('WEB', 'KJV', 'ASV', 'YLT') foreach ($translationCode in $translationsToImport) { $importPhp = @" getMethod('import_vpl_translation'); `$m->setAccessible(true); `$count = `$m->invoke(`$plugin, '$translationCode', false); echo `$count; "@ Write-ContainerPhpFile $environment '/tmp/brt-import.php' $importPhp $imported = (Invoke-WpCli $environment 'wp eval-file /tmp/brt-import.php --path=/var/www/html' | Out-String).Trim() $importNumberText = [regex]::Match($imported, '[\d,]+').Value -replace ',', '' $importNumber = if ($importNumberText) { [int]$importNumberText } else { 0 } Add-Check "$translationCode import completed" ($importNumber -gt 30000) $imported } Invoke-WpCli $environment "wp option patch update brt_settings translation WEB --path=/var/www/html" | Out-Host $countPhp = @' get_results('SELECT translation, COUNT(*) row_count FROM ' . $wpdb->prefix . 'brt_verses GROUP BY translation ORDER BY translation', ARRAY_A); echo json_encode($rows); '@ Write-ContainerPhpFile $environment '/tmp/brt-count.php' $countPhp $rowCount = (Invoke-WpCli $environment 'wp eval-file /tmp/brt-count.php --path=/var/www/html' | Out-String).Trim() Add-Check 'translation rows stored' ($rowCount -match 'WEB' -and $rowCount -match 'KJV' -and $rowCount -match 'ASV' -and $rowCount -match 'YLT') $rowCount $bookCoveragePhp = @' get_col($wpdb->prepare('SELECT DISTINCT book FROM ' . $wpdb->prefix . 'brt_verses WHERE translation = %s', $translation)); $diff = array_values(array_diff($expected, $found)); if ($diff) $missing[$translation] = $diff; } echo $missing ? json_encode($missing) : 'ok'; '@ Write-ContainerPhpFile $environment '/tmp/brt-book-coverage.php' $bookCoveragePhp $bookCoverage = (Invoke-WpCli $environment 'wp eval-file /tmp/brt-book-coverage.php --path=/var/www/html' | Out-String).Trim() Add-Check 'canonical book coverage' ($bookCoverage -eq 'ok') $bookCoverage $refs = @('John 3:16', 'John 3.16', 'Jn3:16', 'Romans 8:28', 'James 1:5', 'Mark 10:45', 'Mark10:45', 'Mk 10:45', 'Ezekiel 36:26', 'Eze 36:26', '2 John 1:6', '2Jn1:6', '2 Jo 1:6') foreach ($ref in $refs) { $lookupPhp = @" set_param('ref', '$ref'); `$request->set_param('translation', 'WEB'); `$response = rest_do_request(`$request); `$data = `$response->get_data(); echo (!empty(`$data['ok']) && !empty(`$data['verses'])) ? 'ok' : json_encode(`$data); "@ Write-ContainerPhpFile $environment '/tmp/brt-lookup.php' $lookupPhp $lookupResult = (Invoke-WpCli $environment 'wp eval-file /tmp/brt-lookup.php --path=/var/www/html' | Out-String).Trim() Add-Check "REST lookup $ref" ($lookupResult -eq 'ok') $lookupResult } Invoke-WpCli $environment "wp post create --post_type=post --post_status=publish --post_title='Bible Reference Tooltip Smoke Test' --post_content='John 3:16 Romans 8:28 James 1:5' --path=/var/www/html" | Out-Host Add-Check 'test post created' $true $result.completedAt = (Get-Date).ToString('o') $result.passed = $true } catch { $result.completedAt = (Get-Date).ToString('o') $result.passed = $false $result.error = $_.Exception.Message throw } finally { Ensure-TestLabDirectories $result | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath (Get-ResultFile -Name $environment.name) -Encoding UTF8 }