T.ME/BIBIL_0DAY
CasperSecurity


Server : Apache/2
System : Linux server-15-235-50-60 5.15.0-164-generic #174-Ubuntu SMP Fri Nov 14 20:25:16 UTC 2025 x86_64
User : gositeme ( 1004)
PHP Version : 8.2.29
Disable Function : exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Directory :  /home/gositeme/backups/lavocat.quebec/backup-20250730-021618/scripts/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/gositeme/backups/lavocat.quebec/backup-20250730-021618/scripts/test-howto-schema.js
const puppeteer = require('puppeteer');
const fs = require('fs');
const path = require('path');

async function testHowToSchema() {
  console.log('๐Ÿงช Testing HowTo Schema Implementation...\n');
  
  const browser = await puppeteer.launch({ headless: true });
  const page = await browser.newPage();
  
  const baseUrl = process.env.NEXT_PUBLIC_APP_URL || 'http://localhost:3000';
  const testPages = [
    {
      url: '/class-action',
      name: 'Class Action Page',
      expectedSteps: 5
    },
    {
      url: '/hire/new-case',
      name: 'New Case Creation Page',
      expectedSteps: 9
    }
  ];
  
  let allTestsPassed = true;
  
  for (const testPage of testPages) {
    console.log(`๐Ÿ“‹ Testing ${testPage.name}...`);
    
    try {
      await page.goto(`${baseUrl}${testPage.url}`, { waitUntil: 'networkidle0' });
      
      // Check for HowTo structured data
      const howToSchema = await page.evaluate(() => {
        const scripts = document.querySelectorAll('script[type="application/ld+json"]');
        for (const script of scripts) {
          try {
            const data = JSON.parse(script.textContent);
            if (data['@type'] === 'HowTo') {
              return data;
            }
          } catch (e) {
            // Skip invalid JSON
          }
        }
        return null;
      });
      
      if (!howToSchema) {
        console.log(`โŒ FAIL: No HowTo schema found on ${testPage.name}`);
        allTestsPassed = false;
        continue;
      }
      
      // Validate HowTo schema structure
      const validation = validateHowToSchema(howToSchema, testPage);
      
      if (validation.isValid) {
        console.log(`โœ… PASS: ${testPage.name} - ${validation.stepCount} steps found`);
        console.log(`   ๐Ÿ“ Name: ${howToSchema.name}`);
        console.log(`   โฑ๏ธ  Time: ${howToSchema.totalTime || 'Not specified'}`);
        console.log(`   ๐Ÿ’ฐ Cost: ${howToSchema.estimatedCost ? `${howToSchema.estimatedCost.value} ${howToSchema.estimatedCost.currency}` : 'Not specified'}`);
      } else {
        console.log(`โŒ FAIL: ${testPage.name} - ${validation.error}`);
        allTestsPassed = false;
      }
      
    } catch (error) {
      console.log(`โŒ ERROR: Failed to test ${testPage.name} - ${error.message}`);
      allTestsPassed = false;
    }
    
    console.log('');
  }
  
  // Test Open Graph meta tags
  console.log('๐Ÿ” Testing Open Graph Meta Tags...');
  
  for (const testPage of testPages) {
    try {
      await page.goto(`${baseUrl}${testPage.url}`, { waitUntil: 'networkidle0' });
      
      const ogTags = await page.evaluate(() => {
        const tags = {};
        const ogSelectors = [
          'meta[property="og:title"]',
          'meta[property="og:description"]',
          'meta[property="og:url"]',
          'meta[property="og:type"]',
          'meta[property="og:image"]'
        ];
        
        ogSelectors.forEach(selector => {
          const element = document.querySelector(selector);
          if (element) {
            const property = element.getAttribute('property');
            const content = element.getAttribute('content');
            tags[property] = content;
          }
        });
        
        return tags;
      });
      
      const requiredTags = ['og:title', 'og:description', 'og:url', 'og:type'];
      const missingTags = requiredTags.filter(tag => !ogTags[tag]);
      
      if (missingTags.length === 0) {
        console.log(`โœ… PASS: ${testPage.name} - All required Open Graph tags present`);
      } else {
        console.log(`โŒ FAIL: ${testPage.name} - Missing Open Graph tags: ${missingTags.join(', ')}`);
        allTestsPassed = false;
      }
      
    } catch (error) {
      console.log(`โŒ ERROR: Failed to test Open Graph on ${testPage.name} - ${error.message}`);
      allTestsPassed = false;
    }
  }
  
  await browser.close();
  
  console.log('\n๐Ÿ“Š Test Summary:');
  console.log(allTestsPassed ? 'โœ… All tests passed!' : 'โŒ Some tests failed');
  
  return allTestsPassed;
}

function validateHowToSchema(schema, testPage) {
  // Check required fields
  if (!schema['@context'] || schema['@context'] !== 'https://schema.org') {
    return { isValid: false, error: 'Invalid @context' };
  }
  
  if (!schema['@type'] || schema['@type'] !== 'HowTo') {
    return { isValid: false, error: 'Invalid @type' };
  }
  
  if (!schema.name) {
    return { isValid: false, error: 'Missing name' };
  }
  
  if (!schema.description) {
    return { isValid: false, error: 'Missing description' };
  }
  
  if (!schema.step || !Array.isArray(schema.step)) {
    return { isValid: false, error: 'Missing or invalid steps array' };
  }
  
  // Check steps structure
  for (let i = 0; i < schema.step.length; i++) {
    const step = schema.step[i];
    if (!step['@type'] || step['@type'] !== 'HowToStep') {
      return { isValid: false, error: `Step ${i + 1} has invalid @type` };
    }
    if (!step.name) {
      return { isValid: false, error: `Step ${i + 1} missing name` };
    }
    if (!step.text) {
      return { isValid: false, error: `Step ${i + 1} missing text` };
    }
  }
  
  // Check if we have the expected number of steps
  if (schema.step.length < testPage.expectedSteps) {
    return { 
      isValid: false, 
      error: `Expected at least ${testPage.expectedSteps} steps, found ${schema.step.length}` 
    };
  }
  
  return { 
    isValid: true, 
    stepCount: schema.step.length 
  };
}

// Run the test if this file is executed directly
if (require.main === module) {
  testHowToSchema()
    .then(success => {
      process.exit(success ? 0 : 1);
    })
    .catch(error => {
      console.error('Test failed with error:', error);
      process.exit(1);
    });
}

module.exports = { testHowToSchema }; 

CasperSecurity Mini