add test
This commit is contained in:
parent
0221414ee0
commit
76246630ce
@ -282,7 +282,7 @@ class Settings extends AbstractPart
|
|||||||
// build low-order word and hig-order word and combine them
|
// build low-order word and hig-order word and combine them
|
||||||
$combinedKey = $this->buildCombinedKey($byteChars);
|
$combinedKey = $this->buildCombinedKey($byteChars);
|
||||||
// build reversed hexadecimal string
|
// build reversed hexadecimal string
|
||||||
$hex = strtoupper(dechex($combinedKey & 0xFFFFFFFF));
|
$hex = str_pad(strtoupper(dechex($combinedKey & 0xFFFFFFFF)), 8, '0', \STR_PAD_LEFT);
|
||||||
$reversedHex = $hex[6] . $hex[7] . $hex[4] . $hex[5] . $hex[2] . $hex[3] . $hex[0] . $hex[1];
|
$reversedHex = $hex[6] . $hex[7] . $hex[4] . $hex[5] . $hex[2] . $hex[3] . $hex[0] . $hex[1];
|
||||||
|
|
||||||
$generatedKey = mb_convert_encoding($reversedHex, 'UCS-2LE', 'UTF-8');
|
$generatedKey = mb_convert_encoding($reversedHex, 'UCS-2LE', 'UTF-8');
|
||||||
|
|||||||
@ -50,6 +50,27 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertTrue($doc->elementExists($path, $file));
|
$this->assertTrue($doc->elementExists($path, $file));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test document protection with password
|
||||||
|
*
|
||||||
|
* Note: to get comparison values, a docx was generated in Word2010 and the values taken from the settings.xml
|
||||||
|
*/
|
||||||
|
public function testDocumentProtectionWithPassword()
|
||||||
|
{
|
||||||
|
$phpWord = new PhpWord();
|
||||||
|
$phpWord->getProtection()->setEditing('readOnly');
|
||||||
|
$phpWord->getProtection()->setPassword('testÄö@€!$&');
|
||||||
|
$phpWord->getProtection()->setSalt(base64_decode("uq81pJRRGFIY5U+E9gt8tA=="));
|
||||||
|
|
||||||
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
||||||
|
$file = 'word/settings.xml';
|
||||||
|
|
||||||
|
$path = '/w:settings/w:documentProtection';
|
||||||
|
$this->assertTrue($doc->elementExists($path, $file));
|
||||||
|
$this->assertEquals($doc->getElement($path, $file)->getAttribute('w:hash'), "RA9jfY/u3DX114PMcl+uSekxsYk=");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test compatibility
|
* Test compatibility
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user