<?php
// Exercise the shared extraction path independently of language labels and database.
require_once __DIR__.'/../shared/lib/student_projects.php';
if(extension_loaded('zip')){echo "SKIP: fixture uses a stub; run without extensions.\n";exit;}
class ZipArchive {
 public $numFiles=3;public $items=['site/index.html'=>'<!doctype html><h1>Hello</h1>','site/css/style.css'=>'body { color: red; }','site/js/app.js'=>'console.log("hello");'];
 function open($p){return true;}function statIndex($i){$name=array_keys($this->items)[$i];return ['name'=>$name,'size'=>strlen($this->items[$name]),'crc'=>hexdec(hash('crc32b',$this->items[$name]))];}
 function getExternalAttributesIndex($i,&$os,&$attr){$os=0;$attr=0;return true;}function getStream($name){$h=fopen('php://temp','r+');fwrite($h,$this->items[$name]);rewind($h);return $h;}function close(){}
}
$key=bin2hex(random_bytes(24));$p=['storage_key'=>$key,'archive_type'=>'zip','technologies'=>'["Other"]'];$root=project_root($p);mkdir($root,0700,true);mkdir($root.'/blobs');file_put_contents($root.'/original','fixture');
try{$m=project_extract($p,['id'=>1]);foreach((new ZipArchive)->items as $name=>$text){if(!isset($m['files'][$name]))throw new RuntimeException('Missing '.$name);if(file_get_contents($root.'/blobs/'.$m['files'][$name]['blob'])!==$text)throw new RuntimeException('Changed source');}echo "PASS: Other technology preserves HTML/CSS/JS paths, parent folders and exact source bytes.\n";}finally{foreach(glob($root.'/blobs/*') as $f)unlink($f);rmdir($root.'/blobs');foreach(glob($root.'/*') as $f)unlink($f);rmdir($root);}
