open($path, ZipArchive::OVERWRITE);
$zip->addFromString('[Content_Types].xml', '');
$zip->addFromString('word/document.xml', ''.($unsafe ? ']>' : '').''.str_repeat('Ficticio ', 300).'');
$zip->setCompressionName('word/document.xml', ZipArchive::CM_STORE);
$zip->close();
try {
return UploadedFile::fake()->createWithContent('curriculo.docx', file_get_contents($path));
} finally {
unlink($path);
}
}
test('word documents must contain valid bounded document XML without external entity declarations', function () {
$definition = ['documents' => [['key' => 'cv', 'required' => true, 'formats' => ['docx'], 'max_kb' => 1024]]];
app(CandidateDocuments::class)->validate($definition, ['cv' => candidateWordFixture()]);
expect(fn () => app(CandidateDocuments::class)->validate($definition, ['cv' => candidateWordFixture(true)]))->toThrow(ValidationException::class);
});
test('an image must match its allowed format and content while an optional absent file remains optional', function () {
$definition = ['documents' => [['key' => 'photo', 'required' => false, 'formats' => ['png'], 'max_kb' => 1024]]];
app(CandidateDocuments::class)->validate($definition, []);
$png = base64_decode('iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+jRZkAAAAASUVORK5CYII=');
app(CandidateDocuments::class)->validate($definition, ['photo' => UploadedFile::fake()->createWithContent('photo.png', $png)]);
expect(fn () => app(CandidateDocuments::class)->validate($definition, ['photo' => UploadedFile::fake()->createWithContent('photo.png', str_repeat('invalid', 200))]))->toThrow(ValidationException::class);
});