# SEO End-to-End Tests

This directory contains comprehensive SEO validation tests for the Expertissimmo website.

## Files

- `SeoEndToEndTest.php` - Main test suite covering all SEO functionality
- `test_sitemap_urls.sh` - Quick shell script to test sitemap URLs only

## Usage

### Full Test Suite

Run complete SEO validation on staging:
```bash
php tests/SeoEndToEndTest.php --env=staging
```

Run on production:
```bash
php tests/SeoEndToEndTest.php --env=production
```

### Quick Sitemap Test

Test only sitemap URLs:
```bash
./tests/test_sitemap_urls.sh
```

## Test Coverage

### 1. Normal Pages (Should be INDEXABLE)
- Homepage, contact, services, agency pages
- Property listing pages
- All static content pages

### 2. Sitemap URL Validation
- Tests all URLs from `/sitemaps/sitemap-routes-services.xml`
- Validates HTTP 200 responses
- Converts production URLs to staging when needed

### 3. Property Status SEO Behavior
- **Available properties**: Should be indexable (no noindex)
- **Properties in option**: Should be indexable 
- **Sold properties**: Should have `meta googlebot noindex`
- **Rented properties**: Should have `meta googlebot noindex`
- Tests both recent properties from API and known examples

### 4. Error Pages
- Non-existent properties should return HTTP 410 status
- Should have comprehensive noindex meta tags
- Should include nofollow, noarchive, nosnippet directives

## Technical Details

### SEO Rules Implemented
1. **purposeStatus == 3** (sold) → `meta googlebot: noindex`
2. **purposeStatus == 4** (rented) → `meta googlebot: noindex` 
3. **displayStatusId == 3** (removed) → `meta googlebot: noindex`
4. **whiseError** (missing property) → HTTP 410 + `meta robots: noindex, nofollow, noarchive, nosnippet`

### Exit Codes
- `0` - All tests passed
- `1` - Some tests failed (suitable for CI/CD pipelines)

## Integration with CI/CD

This test suite can be integrated into deployment pipelines:

```bash
# In your deployment script
php tests/SeoEndToEndTest.php --env=staging
if [ $? -eq 0 ]; then
    echo "SEO tests passed, proceeding with deployment"
else
    echo "SEO tests failed, stopping deployment"
    exit 1
fi
```

## Sample Output

```
🧪 EXPERTISSIMMO SEO END-TO-END TESTS
=====================================
Environment: STAGING
Base URL: https://staging.expertissimmo.eu

✅ All normal pages indexable
✅ 22/22 sitemap URLs working
✅ Property status behavior correct
✅ Error pages configured properly

📊 FINAL TEST REPORT
Total Tests: 45
✅ Passed: 45
❌ Failed: 0
Success Rate: 100.0%
```

## Troubleshooting

### Common Issues

1. **Whise API Connection**: Tests will continue with reduced coverage if API is unavailable
2. **Environment URLs**: Make sure staging/production environments are accessible
3. **SSL Verification**: Tests disable SSL verification for development environments

### Adding New Tests

To add new test cases, extend the `SeoEndToEndTest` class:

```php
private function testNewFeature() {
    // Your test logic here
    $this->addResult('TEST_TYPE', $success, $message);
}
```

## Maintenance

- Update known property IDs in `testKnownProperties()` when examples become outdated
- Review test coverage when new SEO rules are implemented
- Keep sitemap path updated if sitemap structure changes