|
| 1 | +name: Test Plugin |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + test: |
| 11 | + runs-on: ubuntu-latest |
| 12 | + |
| 13 | + steps: |
| 14 | + - name: Checkout code |
| 15 | + uses: actions/checkout@v4 |
| 16 | + |
| 17 | + - name: Setup Node.js |
| 18 | + uses: actions/setup-node@v4 |
| 19 | + with: |
| 20 | + node-version: '20' |
| 21 | + |
| 22 | + - name: Setup PHP (for composer build) |
| 23 | + uses: shivammathur/setup-php@v2 |
| 24 | + with: |
| 25 | + php-version: '8.1' |
| 26 | + tools: composer |
| 27 | + |
| 28 | + - name: Install composer dependencies |
| 29 | + run: composer install --optimize-autoloader |
| 30 | + |
| 31 | + - name: Build prefixed vendor |
| 32 | + run: composer run build |
| 33 | + |
| 34 | + - name: Install wp-playground CLI |
| 35 | + run: npm install -g @wp-playground/cli |
| 36 | + |
| 37 | + |
| 38 | + - name: Start wp-playground with blueprint |
| 39 | + run: | |
| 40 | + echo "Starting wp-playground server in background..." |
| 41 | + PLUGIN_PATH=$(realpath .) |
| 42 | + echo "Plugin path: $PLUGIN_PATH" |
| 43 | + npx @wp-playground/cli server --mount="$PLUGIN_PATH:/wordpress/wp-content/plugins/post-content-to-markdown" --blueprint=blueprint.json & |
| 44 | + WP_PID=$! |
| 45 | + echo $WP_PID > wp-playground.pid |
| 46 | + echo "Started with PID: $WP_PID" |
| 47 | +
|
| 48 | + # Wait for wp-playground to be ready |
| 49 | + echo "Waiting for wp-playground to start..." |
| 50 | + for i in {1..30}; do |
| 51 | + if curl -s http://localhost:9400 > /dev/null; then |
| 52 | + echo "wp-playground is ready!" |
| 53 | + break |
| 54 | + fi |
| 55 | + echo "Waiting... ($i/30)" |
| 56 | + sleep 2 |
| 57 | + done |
| 58 | +
|
| 59 | + - name: Wait for WordPress |
| 60 | + run: | |
| 61 | + # Wait for WordPress to be ready |
| 62 | + sleep 10 |
| 63 | +
|
| 64 | + - name: Test single post markdown output |
| 65 | + run: | |
| 66 | + echo "Testing single post with ?format=markdown" |
| 67 | +
|
| 68 | + # Check if server is responding |
| 69 | + echo "Checking server status..." |
| 70 | + curl -v "http://localhost:9400/" || echo "Server not responding" |
| 71 | +
|
| 72 | + echo "Testing markdown endpoint..." |
| 73 | + response=$(curl -s "http://localhost:9400/hello-world/?format=markdown") |
| 74 | + echo "Response received: $response" |
| 75 | +
|
| 76 | + if [[ "$response" == *"# Hello world"* ]] && [[ "$response" == *"WordPress"* ]]; then |
| 77 | + echo "✅ Single post markdown query parameter test passed" |
| 78 | + else |
| 79 | + echo "❌ Single post markdown query parameter test failed" |
| 80 | + exit 1 |
| 81 | + fi |
| 82 | +
|
| 83 | + - name: Test single post with Accept header |
| 84 | + run: | |
| 85 | + echo "Testing single post with Accept: text/markdown header" |
| 86 | + response=$(curl -s -H "Accept: text/markdown" "http://localhost:9400/hello-world/") |
| 87 | +
|
| 88 | + if [[ "$response" == *"# Hello world"* ]] && [[ "$response" == *"WordPress"* ]]; then |
| 89 | + echo "✅ Single post Accept header test passed" |
| 90 | + else |
| 91 | + echo "❌ Single post Accept header test failed" |
| 92 | + exit 1 |
| 93 | + fi |
| 94 | +
|
| 95 | + - name: Test main feed markdown |
| 96 | + run: | |
| 97 | + echo "Testing main feed with ?format=markdown" |
| 98 | + response=$(curl -s "http://localhost:9400/feed/?format=markdown") |
| 99 | +
|
| 100 | + if [[ "$response" == *"Markdown Feed"* ]] && [[ "$response" == *"Hello world"* ]]; then |
| 101 | + echo "✅ Main feed markdown test passed" |
| 102 | + else |
| 103 | + echo "❌ Main feed markdown test failed" |
| 104 | + exit 1 |
| 105 | + fi |
| 106 | +
|
| 107 | + - name: Test dedicated markdown feed |
| 108 | + run: | |
| 109 | + echo "Testing dedicated /feed/markdown/ endpoint" |
| 110 | + response=$(curl -s "http://localhost:9400/feed/markdown/") |
| 111 | +
|
| 112 | + if [[ "$response" == *"Markdown Feed"* ]] && [[ "$response" == *"Hello world"* ]]; then |
| 113 | + echo "✅ Dedicated markdown feed test passed" |
| 114 | + else |
| 115 | + echo "❌ Dedicated markdown feed test failed" |
| 116 | + exit 1 |
| 117 | + fi |
| 118 | +
|
| 119 | + - name: Test content type headers |
| 120 | + run: | |
| 121 | + echo "Testing Content-Type headers" |
| 122 | + content_type=$(curl -s -I "http://localhost:9400/hello-world/?format=markdown" | grep -i "content-type") |
| 123 | +
|
| 124 | + if [[ "$content_type" == *"text/markdown"* ]]; then |
| 125 | + echo "✅ Content-Type header test passed" |
| 126 | + else |
| 127 | + echo "❌ Content-Type header test failed" |
| 128 | + exit 1 |
| 129 | + fi |
| 130 | +
|
| 131 | + - name: Cleanup |
| 132 | + if: always() |
| 133 | + run: | |
| 134 | + if [ -f wp-playground.pid ]; then |
| 135 | + kill $(cat wp-playground.pid) || true |
| 136 | + fi |
0 commit comments