33 lines
1.8 KiB
PHP
33 lines
1.8 KiB
PHP
<?php
|
|
|
|
use App\Services\WindowsTaskXml;
|
|
|
|
function syntheticWindowsTaskXml(): string
|
|
{
|
|
return '<?xml version="1.0" encoding="UTF-8"?><Task xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task" version="1.2">'
|
|
.'<RegistrationInfo><Description>Conferência de prazos — QA</Description></RegistrationInfo>'
|
|
.'<Actions><Exec><Command>C:/synthetic/php.exe</Command><Arguments>"C:/synthetic/deadlines.php" --once</Arguments></Exec></Actions></Task>';
|
|
}
|
|
|
|
test('task file encoding matches its UTF16 declaration without changing any task content', function () {
|
|
$xml = syntheticWindowsTaskXml();
|
|
$bytes = WindowsTaskXml::encode($xml);
|
|
expect(in_array(substr($bytes, 0, 2), ["\xFF\xFE", "\xFE\xFF"], true))->toBeTrue()
|
|
->and(WindowsTaskXml::parse($bytes)->documentElement->C14N())->toBe(WindowsTaskXml::parse($xml)->documentElement->C14N());
|
|
});
|
|
|
|
test('native console task XML with a mismatched declaration preserves accents and action arguments', function () {
|
|
$xml = syntheticWindowsTaskXml();
|
|
$console = str_replace('encoding="UTF-8"', 'encoding="UTF-16"', $xml);
|
|
$document = WindowsTaskXml::parse($console);
|
|
expect($document->documentElement->C14N())->toBe(WindowsTaskXml::parse($xml)->documentElement->C14N())
|
|
->and($document->getElementsByTagName('Description')->item(0)->textContent)->toBe('Conferência de prazos — QA')
|
|
->and($document->getElementsByTagName('Arguments')->item(0)->textContent)->toBe('"C:/synthetic/deadlines.php" --once');
|
|
});
|
|
|
|
test('invalid or unrelated XML is refused before task registration', function () {
|
|
foreach (['<Task', '<Task/>', '<other xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task"/>'] as $xml) {
|
|
expect(fn () => WindowsTaskXml::encode($xml))->toThrow(LogicException::class, 'WINDOWS_TASK_XML_INVALID');
|
|
}
|
|
});
|