fix tests
This commit is contained in:
parent
ad38d4c20f
commit
5a57409df0
|
|
@ -162,7 +162,7 @@ class Protection
|
||||||
* @param $algorithm
|
* @param $algorithm
|
||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function setMswordAlgorithmSid($algorithm)
|
public function setAlgorithm($algorithm)
|
||||||
{
|
{
|
||||||
$this->algorithm = $algorithm;
|
$this->algorithm = $algorithm;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -162,6 +162,17 @@ class PasswordEncoder
|
||||||
return $algorithm;
|
return $algorithm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the algorithm ID
|
||||||
|
*
|
||||||
|
* @param sting $algorithmName
|
||||||
|
* @return int
|
||||||
|
*/
|
||||||
|
public static function getAlgorithmId($algorithmName)
|
||||||
|
{
|
||||||
|
return self::$algorithmMapping[$algorithmName][0];
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build combined key from low-order word and high-order word
|
* Build combined key from low-order word and high-order word
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -183,7 +183,7 @@ class Settings extends AbstractPart
|
||||||
private function setDocumentProtection($documentProtection)
|
private function setDocumentProtection($documentProtection)
|
||||||
{
|
{
|
||||||
if ($documentProtection->getEditing() !== null) {
|
if ($documentProtection->getEditing() !== null) {
|
||||||
if (empty($documentProtection->getPassword())) {
|
if ($documentProtection->getPassword() == null) {
|
||||||
$this->settings['w:documentProtection'] = array(
|
$this->settings['w:documentProtection'] = array(
|
||||||
'@attributes' => array(
|
'@attributes' => array(
|
||||||
'w:enforcement' => 1,
|
'w:enforcement' => 1,
|
||||||
|
|
@ -202,7 +202,7 @@ class Settings extends AbstractPart
|
||||||
'w:cryptProviderType' => 'rsaFull',
|
'w:cryptProviderType' => 'rsaFull',
|
||||||
'w:cryptAlgorithmClass' => 'hash',
|
'w:cryptAlgorithmClass' => 'hash',
|
||||||
'w:cryptAlgorithmType' => 'typeAny',
|
'w:cryptAlgorithmType' => 'typeAny',
|
||||||
'w:cryptAlgorithmSid' => $documentProtection->getMswordAlgorithmSid(),
|
'w:cryptAlgorithmSid' => PasswordEncoder::getAlgorithmId($documentProtection->getAlgorithm()),
|
||||||
'w:cryptSpinCount' => $documentProtection->getSpinCount(),
|
'w:cryptSpinCount' => $documentProtection->getSpinCount(),
|
||||||
'w:hash' => $passwordHash,
|
'w:hash' => $passwordHash,
|
||||||
'w:salt' => base64_encode($documentProtection->getSalt()),
|
'w:salt' => base64_encode($documentProtection->getSalt()),
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ use PhpOffice\PhpWord\Settings;
|
||||||
use PhpOffice\PhpWord\SimpleType\Zoom;
|
use PhpOffice\PhpWord\SimpleType\Zoom;
|
||||||
use PhpOffice\PhpWord\Style\Language;
|
use PhpOffice\PhpWord\Style\Language;
|
||||||
use PhpOffice\PhpWord\TestHelperDOCX;
|
use PhpOffice\PhpWord\TestHelperDOCX;
|
||||||
|
use PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
|
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
|
||||||
|
|
@ -65,7 +66,7 @@ class SettingsTest extends \PHPUnit\Framework\TestCase
|
||||||
$phpWord->getSettings()->getDocumentProtection()->setEditing('readOnly');
|
$phpWord->getSettings()->getDocumentProtection()->setEditing('readOnly');
|
||||||
$phpWord->getSettings()->getDocumentProtection()->setPassword('testÄö@€!$&');
|
$phpWord->getSettings()->getDocumentProtection()->setPassword('testÄö@€!$&');
|
||||||
$phpWord->getSettings()->getDocumentProtection()->setSalt(base64_decode('uq81pJRRGFIY5U+E9gt8tA=='));
|
$phpWord->getSettings()->getDocumentProtection()->setSalt(base64_decode('uq81pJRRGFIY5U+E9gt8tA=='));
|
||||||
$phpWord->getSettings()->getDocumentProtection()->setMswordAlgorithmSid(1);
|
$phpWord->getSettings()->getDocumentProtection()->setAlgorithm(PasswordEncoder::ALGORITHM_MD2);
|
||||||
$phpWord->getSettings()->getDocumentProtection()->setSpinCount(10);
|
$phpWord->getSettings()->getDocumentProtection()->setSpinCount(10);
|
||||||
|
|
||||||
$doc = TestHelperDOCX::getDocument($phpWord);
|
$doc = TestHelperDOCX::getDocument($phpWord);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue