Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
troosan committed Dec 13, 2017
1 parent ad38d4c commit 5a57409
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/PhpWord/Metadata/Protection.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function getAlgorithm()
* @param $algorithm
* @return self
*/
public function setMswordAlgorithmSid($algorithm)
public function setAlgorithm($algorithm)
{
$this->algorithm = $algorithm;

Expand Down
11 changes: 11 additions & 0 deletions src/PhpWord/Shared/Microsoft/PasswordEncoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,17 @@ private static function getAlgorithm($algorithmName)
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
*
Expand Down
4 changes: 2 additions & 2 deletions src/PhpWord/Writer/Word2007/Part/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ private function setOnOffValue($settingName, $booleanValue)
private function setDocumentProtection($documentProtection)
{
if ($documentProtection->getEditing() !== null) {
if (empty($documentProtection->getPassword())) {
if ($documentProtection->getPassword() == null) {
$this->settings['w:documentProtection'] = array(
'@attributes' => array(
'w:enforcement' => 1,
Expand All @@ -202,7 +202,7 @@ private function setDocumentProtection($documentProtection)
'w:cryptProviderType' => 'rsaFull',
'w:cryptAlgorithmClass' => 'hash',
'w:cryptAlgorithmType' => 'typeAny',
'w:cryptAlgorithmSid' => $documentProtection->getMswordAlgorithmSid(),
'w:cryptAlgorithmSid' => PasswordEncoder::getAlgorithmId($documentProtection->getAlgorithm()),
'w:cryptSpinCount' => $documentProtection->getSpinCount(),
'w:hash' => $passwordHash,
'w:salt' => base64_encode($documentProtection->getSalt()),
Expand Down
3 changes: 2 additions & 1 deletion tests/PhpWord/Writer/Word2007/Part/SettingsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use PhpOffice\PhpWord\SimpleType\Zoom;
use PhpOffice\PhpWord\Style\Language;
use PhpOffice\PhpWord\TestHelperDOCX;
use PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder;

/**
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
Expand Down Expand Up @@ -65,7 +66,7 @@ public function testDocumentProtectionWithPassword()
$phpWord->getSettings()->getDocumentProtection()->setEditing('readOnly');
$phpWord->getSettings()->getDocumentProtection()->setPassword('testÄö@€!$&');
$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);

$doc = TestHelperDOCX::getDocument($phpWord);
Expand Down

0 comments on commit 5a57409

Please sign in to comment.