# 🧪 SEO Skills - Complete Testing Guide

**Purpose:** Test all implemented features systematically  
**Estimated Time:** 2-3 hours for full test suite  
**Prerequisites:** Python 3.8+, pip packages installed

---

## 📋 TEST OVERVIEW

| Test Group | Features | Priority | Time |
|------------|----------|----------|------|
| **Group 1:** Content Generation | Multi-channel generation | High | 30 min |
| **Group 2:** Thai Analysis | Keyword, readability, quality | High | 20 min |
| **Group 3:** Context Management | Create, manage context | Medium | 15 min |
| **Group 4:** Image Integration | Generate, edit images | Medium | 30 min |
| **Group 5:** Auto-Publish | Astro publishing | Medium | 20 min |
| **Group 6:** Analytics | GA4, GSC, DataForSEO, Umami | Low | 30 min |

---

## 🔧 PRE-TEST SETUP

### **1. Install Dependencies**

```bash
# Navigate to skills directory
cd /Users/kunthawatgreethong/Gitea/opencode-skill/skills

# Install all dependencies
pip install pythainlp pyyaml python-dotenv pandas tqdm rich \
  markdown python-frontmatter GitPython Pillow requests

# Install Google APIs (for analytics testing)
pip install google-analytics-data google-auth google-auth-oauthlib \
  google-api-python-client

# Download Thai language data
python3 -c "from pythainlp.corpus import download; download('default')"
```

### **2. Verify Installation**

```bash
# Test PyThaiNLP
python3 -c "from pythainlp import word_tokenize; print(word_tokenize('ทดสอบภาษาไทย'))"
# Expected: ['ทดสอบ', 'ภาษาไทย']

# Test YAML
python3 -c "import yaml; print('YAML OK')"

# Test requests
python3 -c "import requests; print('Requests OK')"
```

---

## 📝 GROUP 1: Content Generation Tests

### **Test 1.1: Facebook Post Generation**

```bash
cd /Users/kunthawatgreethong/Gitea/opencode-skill/skills/seo-multi-channel/scripts

python3 generate_content.py \
  --topic "บริการ podcast hosting" \
  --channels facebook \
  --language th \
  --output test-fb
```

**Expected Output:**
```
🎯 Generating content for: บริการ podcast hosting
📱 Channels: facebook
🌐 Language: th

  Generating facebook...
  [Image Generation] Would generate image for facebook
    Topic: บริการ podcast hosting, Type: social
  ... (5 times)

✅ Results saved to: output/บริการ-podcast-hosting/results.json

📊 Summary:
  Channels generated: 1
    - facebook: 5 variations
```

**Verify:**
- [ ] Output file created at `output/test-fb/results.json`
- [ ] Contains 5 Facebook variations
- [ ] Each has: primary_text, headline, cta, hashtags

---

### **Test 1.2: Multi-Channel Generation**

```bash
python3 generate_content.py \
  --topic "บริการ podcast hosting" \
  --channels facebook google_ads blog \
  --language th
```

**Expected Output:**
```
🎯 Generating content for: บริการ podcast hosting
📱 Channels: facebook, google_ads, blog
🌐 Language: th

  Generating facebook... (5 variations)
  Generating google_ads... (3 variations)
  Generating blog... (5 variations)

✅ Results saved to: output/บริการ-podcast-hosting/results.json

📊 Summary:
  Channels generated: 3
    - facebook: 5 variations
    - google_ads: 3 variations
    - blog: 5 variations
```

**Verify:**
- [ ] All 3 channels generated
- [ ] Total 13 variations
- [ ] Blog has markdown with frontmatter
- [ ] Google Ads has 15 headlines, 4 descriptions

---

### **Test 1.3: English Content**

```bash
python3 generate_content.py \
  --topic "best podcast hosting 2026" \
  --channels facebook blog \
  --language en
```

**Verify:**
- [ ] English content generated
- [ ] Different tone/formality than Thai
- [ ] Proper English grammar structure

---

## 📝 GROUP 2: Thai Analysis Tests

### **Test 2.1: Keyword Density Analysis**

```bash
cd /Users/kunthawatgreethong/Gitea/opencode-skill/skills/seo-analyzers/scripts

python3 thai_keyword_analyzer.py \
  --text "บริการ podcast hosting ที่ดีที่สุดช่วยให้คุณเผยแพร่ podcast ไปยัง Apple Podcasts, Spotify, YouTube Music ได้อย่างง่ายดาย บริการ podcast ของเราเป็นเครื่องมือที่ครบวงจรที่สุด" \
  --keyword "บริการ podcast" \
  --language th \
  --output text
```

**Expected Output:**
```
📊 Keyword Analysis Results

Keyword: บริการ podcast
Word Count: 25
Occurrences: 3
Density: 12.0% (target: 1.0-1.5%)
Status: too_high

Critical Placements:
  ✓ First 100 words: Yes
  ✓ H1 Headline: No
  ✓ Conclusion: No
  ✓ H2 Headings: 0 found

Keyword Stuffing Risk: high

💡 Recommendations:
  • ลดการใช้คำหลักลง อาจถูกมองว่า keyword stuffing
  • เพิ่มคำหลักในหัวข้อหลัก (H1)
  • เพิ่มคำหลักในบทสรุป
```

**Verify:**
- [ ] Thai word count accurate (uses PyThaiNLP)
- [ ] Density calculated correctly
- [ ] Recommendations in Thai

---

### **Test 2.2: Readability Analysis**

```bash
python3 thai_readability.py \
  --text "มาเริ่ม podcast กันเลย! ไม่ต้องรอให้พร้อม 100% แค่มีไอเดียดีๆ กับไมค์หนึ่งอัน คุณก็เริ่มต้นได้แล้ว ส่วนเรื่องเทคนิคที่เหลือ เราช่วยคุณเอง" \
  --output text
```

**Expected Output:**
```
📖 Thai Readability Analysis

Sentence Count: 3
Word Count: 28
Avg Sentence Length: 9.3 words

Grade Level: ง่าย (ม.6-ม.9)
Formality: กันเอง (Casual)

Readability Score: 75/100
```

**Verify:**
- [ ] Thai sentences counted correctly
- [ ] Formality detected (กันเอง vs เป็นทางการ)
- [ ] Grade level in Thai format

---

### **Test 2.3: Content Quality Scoring**

```bash
python3 content_quality_scorer.py \
  --text "# คู่มือ Podcast Hosting

บริการ podcast hosting เป็นสิ่งสำคัญสำหรับ podcaster ทุกคน...

[Add 500+ words of content]" \
  --keyword "podcast hosting" \
  --output text
```

**Expected Output:**
```
⭐ Content Quality Score

Overall Score: 65.0/100
Status: fair
Action: Address priority fixes

Category Scores:
  • Keyword Optimization: 15/25
  • Readability: 18/25
  • Structure: 17/25
  • Brand Voice: 15/25
```

**Verify:**
- [ ] Score between 0-100
- [ ] 4 category breakdowns
- [ ] Recommendations provided

---

## 📝 GROUP 3: Context Management Tests

### **Test 3.1: Create Context Files**

```bash
cd /Users/kunthawatgreethong/Gitea/opencode-skill/skills/seo-context/scripts

python3 context_manager.py \
  --create \
  --project "/tmp/test-website" \
  --industry "podcast" \
  --formality "normal"
```

**Expected Output:**
```
📝 Context Manager
Project: /tmp/test-website

Creating context files...
Industry: podcast
Audience: Thai audience
Formality: normal

✅ Context created successfully!

📁 Created files:
  ✓ brand-voice.md
  ✓ target-keywords.md
  ✓ seo-guidelines.md
  ✓ internal-links-map.md
  ✓ data-services.json
  ✓ style-guide.md

📍 Location: /tmp/test-website/context
```

**Verify:**
- [ ] All 6 files created in `/tmp/test-website/context/`
- [ ] brand-voice.md has Thai voice pillars
- [ ] seo-guidelines.md has Thai-specific rules
- [ ] data-services.json has all services disabled

```bash
# Verify files
ls -la /tmp/test-website/context/
cat /tmp/test-website/context/brand-voice.md | head -20
```

---

### **Test 3.2: Alternative --action Flag**

```bash
python3 context_manager.py \
  --action create \
  --project "/tmp/test-website-2" \
  --industry "ecommerce" \
  --formality "casual"
```

**Verify:**
- [ ] Works with `--action create` instead of `--create`
- [ ] Different industry reflected in content

---

## 📝 GROUP 4: Image Integration Tests

### **Test 4.1: Image Generation (Requires CHUTES_API_TOKEN)**

```bash
cd /Users/kunthawatgreethong/Gitea/opencode-skill/skills/seo-multi-channel/scripts

# Set your API token
export CHUTES_API_TOKEN="your_token_here"

python3 image_integration.py \
  --action generate \
  --topic "podcast hosting" \
  --channel facebook \
  --output-dir ./test-images
```

**Expected Output:**
```
🎨 Generating image...
  Prompt: Professional illustration of podcast hosting...
  Size: 1024x1024
  ✓ Saved: ./test-images/podcast-hosting/facebook/generated_xxx.png
```

**Verify:**
- [ ] Image file created
- [ ] Saved in correct folder structure
- [ ] Image is viewable (not corrupted)

**Note:** If no API token, test will show prompt about needing token

---

### **Test 4.2: Find Product Images**

```bash
# First, create a test website structure
mkdir -p /tmp/test-website/public/images/products
cp /path/to/any-image.jpg /tmp/test-website/public/images/products/podcast-mic.jpg

python3 image_integration.py \
  --action find \
  --product-name "podcast-mic" \
  --website-repo "/tmp/test-website"
```

**Expected Output:**
```
🔍 Looking for product images: podcast-mic
  ✓ Found 1 image(s)
  - /tmp/test-website/public/images/products/podcast-mic.jpg
```

**Verify:**
- [ ] Finds images in website repo
- [ ] Searches multiple directories
- [ ] Returns full paths

---

### **Test 4.3: Product Image Edit (Requires CHUTES_API_TOKEN)**

```bash
export CHUTES_API_TOKEN="your_token_here"

python3 image_integration.py \
  --action edit \
  --product-name "podcast-mic" \
  --website-repo "/tmp/test-website" \
  --prompt "Enhance product, professional lighting, clean background" \
  --topic "podcast-mic" \
  --channel facebook_ads \
  --output-dir ./test-images
```

**Expected Output:**
```
✏️  Editing product image...
  Base: /tmp/test-website/public/images/products/podcast-mic.jpg
  Edit: Enhance product, professional lighting...
  ✓ Saved: ./test-images/podcast-mic/facebook_ads/edited_xxx.png
```

**Verify:**
- [ ] Original image found
- [ ] Edited image created
- [ ] Saved in channel-specific folder

---

## 📝 GROUP 5: Auto-Publish Tests

### **Test 5.1: Publish Blog Post**

```bash
cd /Users/kunthawatgreethong/Gitea/opencode-skill/skills/seo-multi-channel/scripts

# Create test blog post
cat > /tmp/test-blog.md << 'EOF'
---
title: "คู่มือ Podcast Hosting ที่ดีที่สุด 2026"
description: "เปรียบเทียบบริการ podcast hosting ทั้งหมด"
keywords: ["podcast hosting", "บริการ podcast"]
slug: podcast-hosting-best-2026
lang: th
category: guides
created: 2026-03-08
---

# คู่มือ Podcast Hosting ที่ดีที่สุด 2026

บทความนี้จะเปรียบเทียบแพลตฟอร์มยอดนิยม...
EOF

# Initialize test git repo
mkdir -p /tmp/test-astro-website/src/content/blog/\(th\)
cd /tmp/test-astro-website
git init
git config user.email "test@test.com"
git config user.name "Test User"
git remote add origin https://github.com/yourusername/test-repo.git

# Publish
python3 auto_publish.py \
  --file /tmp/test-blog.md \
  --website-repo /tmp/test-astro-website
```

**Expected Output:**
```
📝 Publishing to Astro

✓ Saved: /tmp/test-astro-website/src/content/blog/(th)/podcast-hosting-best-2026.md
✓ Committed: Add blog post: podcast-hosting-best-2026 (th)
✓ Pushed to remote

✅ Published successfully!
  Slug: podcast-hosting-best-2026
  Language: th
  Path: /tmp/test-astro-website/src/content/blog/(th)/podcast-hosting-best-2026.md
```

**Verify:**
- [ ] Markdown file saved in correct language folder
- [ ] Git commit created
- [ ] Slug generated correctly from Thai title

---

### **Test 5.2: English Blog Post**

```bash
cat > /tmp/test-blog-en.md << 'EOF'
---
title: "Best Podcast Hosting 2026"
description: "Compare all podcast hosting services"
slug: best-podcast-hosting-2026
lang: en
---

# Best Podcast Hosting 2026

This article compares...
EOF

python3 auto_publish.py \
  --file /tmp/test-blog-en.md \
  --website-repo /tmp/test-astro-website
```

**Verify:**
- [ ] Saved in `(en)` folder
- [ ] Language auto-detected if not specified

---

## 📝 GROUP 6: Analytics Tests (Optional - Needs Credentials)

### **Test 6.1: Data Aggregator (No Services)**

```bash
cd /Users/kunthawatgreethong/Gitea/opencode-skill/skills/seo-data/scripts

# Create empty config
cat > /tmp/test-context/data-services.json << 'EOF'
{
  "ga4": {"enabled": false},
  "gsc": {"enabled": false},
  "dataforseo": {"enabled": false},
  "umami": {"enabled": false}
}
EOF

python3 data_aggregator.py \
  --context /tmp/test-context \
  --action performance \
  --url "https://test.com/page"
```

**Expected Output:**
```
📊 Initializing Data Service Manager...
Context: /tmp/test-context

No analytics services configured. All features will be skipped.

⚠️  No services configured. Exiting.
```

**Verify:**
- [ ] Gracefully handles no services
- [ ] No errors thrown

---

### **Test 6.2: GA4 Connector (With Credentials)**

```bash
# Only if you have GA4 credentials
python3 ga4_connector.py \
  --property-id "G-XXXXXXXXXX" \
  --credentials "/path/to/ga4-credentials.json" \
  --url "/blog/article" \
  --days 30
```

**Verify (if credentials provided):**
- [ ] Connects successfully
- [ ] Returns pageview data
- [ ] Returns engagement metrics

---

### **Test 6.3: GSC Connector (With Credentials)**

```bash
# Only if you have GSC credentials
python3 gsc_connector.py \
  --site-url "https://yoursite.com" \
  --credentials "/path/to/gsc-credentials.json" \
  --quick-wins
```

**Expected Output:**
```
🔍 Testing GSC Connector
Site: https://yoursite.com

Finding quick wins (position 11-20)...

Found 15 opportunities:

1. keyword example
   Position: 12 | Impressions: 1,234 | Priority: 85
```

**Verify (if credentials provided):**
- [ ] Connects successfully
- [ ] Returns keyword positions
- [ ] Quick wins calculated correctly

---

### **Test 6.4: DataForSEO (With Credentials)**

```bash
python3 dataforseo_client.py \
  --login "your_login" \
  --password "your_password" \
  --keyword "podcast hosting"
```

**Verify (if credentials provided):**
- [ ] Authenticates successfully
- [ ] Returns SERP data

---

### **Test 6.5: Umami (With Credentials)**

```bash
python3 umami_connector.py \
  --api-url "https://analytics.yoursite.com" \
  --api-key "your_api_key" \
  --website-id "your_website_id"
```

**Verify (if credentials provided):**
- [ ] Connects successfully
- [ ] Returns analytics data

---

## ✅ TEST CHECKLIST SUMMARY

### **High Priority (Must Test):**

- [ ] **Test 1.1:** Facebook post generation (Thai)
- [ ] **Test 1.2:** Multi-channel generation
- [ ] **Test 2.1:** Thai keyword density analysis
- [ ] **Test 2.2:** Thai readability analysis
- [ ] **Test 2.3:** Content quality scoring
- [ ] **Test 3.1:** Context file creation

### **Medium Priority (Should Test):**

- [ ] **Test 4.1:** Image generation (if have token)
- [ ] **Test 4.2:** Find product images
- [ ] **Test 5.1:** Auto-publish blog post
- [ ] **Test 1.3:** English content generation

### **Low Priority (If Have Credentials):**

- [ ] **Test 6.2:** GA4 connector
- [ ] **Test 6.3:** GSC connector
- [ ] **Test 6.4:** DataForSEO client
- [ ] **Test 6.5:** Umami connector

---

## 🐛 COMMON ISSUES & FIXES

### **Issue 1: PyThaiNLP Not Working**

**Error:** `ImportError: No module named 'pythainlp'`

**Fix:**
```bash
pip install pythainlp
python3 -c "from pythainlp.corpus import download; download('default')"
```

---

### **Issue 2: YAML Parser Errors**

**Error:** `yaml.parser.ParserError`

**Fix:** Templates already fixed. If using custom templates, ensure:
- No unquoted special characters
- Proper indentation (2 spaces)
- No `or` in values (use quotes)

---

### **Issue 3: Image Generation Fails**

**Error:** `CHUTES_API_TOKEN not set`

**Fix:** Either set token or skip image tests (core functionality still works)

```bash
export CHUTES_API_TOKEN="your_token"
```

---

### **Issue 4: Git Push Fails**

**Error:** `git push` authentication failed

**Fix:** For testing, skip remote push:
```bash
# Just test local commit
git commit -m "Test commit"
# Don't push
```

---

## 📊 TEST RESULTS TEMPLATE

After testing, fill in this template:

```markdown
## Test Results - [Date]

**Tester:** [Your name]
**Environment:** [Python version, OS]

### Group 1: Content Generation
- [ ] Test 1.1: Facebook (Thai) - PASS/FAIL
- [ ] Test 1.2: Multi-channel - PASS/FAIL
- [ ] Test 1.3: English - PASS/FAIL

### Group 2: Thai Analysis
- [ ] Test 2.1: Keyword density - PASS/FAIL
- [ ] Test 2.2: Readability - PASS/FAIL
- [ ] Test 2.3: Quality score - PASS/FAIL

### Group 3: Context
- [ ] Test 3.1: Create context - PASS/FAIL

### Group 4: Images
- [ ] Test 4.1: Generate - PASS/FAIL/SKIP
- [ ] Test 4.2: Find products - PASS/FAIL

### Group 5: Auto-Publish
- [ ] Test 5.1: Publish blog - PASS/FAIL

### Group 6: Analytics
- [ ] Test 6.x: [Service] - PASS/FAIL/SKIP (no creds)

### Bugs Found:
1. [Description]
2. [Description]

### Overall Status: [Ready/Needs Fixes]
```

---

**Happy Testing!** 🧪🎉
