Skip to content

Commit 5a57409

Browse files
committed
fix tests
1 parent ad38d4c commit 5a57409

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/PhpWord/Metadata/Protection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function getAlgorithm()
162162
* @param $algorithm
163163
* @return self
164164
*/
165-
public function setMswordAlgorithmSid($algorithm)
165+
public function setAlgorithm($algorithm)
166166
{
167167
$this->algorithm = $algorithm;
168168

src/PhpWord/Shared/Microsoft/PasswordEncoder.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,17 @@ private static function getAlgorithm($algorithmName)
162162
return $algorithm;
163163
}
164164

165+
/**
166+
* Returns the algorithm ID
167+
*
168+
* @param sting $algorithmName
169+
* @return int
170+
*/
171+
public static function getAlgorithmId($algorithmName)
172+
{
173+
return self::$algorithmMapping[$algorithmName][0];
174+
}
175+
165176
/**
166177
* Build combined key from low-order word and high-order word
167178
*

src/PhpWord/Writer/Word2007/Part/Settings.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ private function setOnOffValue($settingName, $booleanValue)
183183
private function setDocumentProtection($documentProtection)
184184
{
185185
if ($documentProtection->getEditing() !== null) {
186-
if (empty($documentProtection->getPassword())) {
186+
if ($documentProtection->getPassword() == null) {
187187
$this->settings['w:documentProtection'] = array(
188188
'@attributes' => array(
189189
'w:enforcement' => 1,
@@ -202,7 +202,7 @@ private function setDocumentProtection($documentProtection)
202202
'w:cryptProviderType' => 'rsaFull',
203203
'w:cryptAlgorithmClass' => 'hash',
204204
'w:cryptAlgorithmType' => 'typeAny',
205-
'w:cryptAlgorithmSid' => $documentProtection->getMswordAlgorithmSid(),
205+
'w:cryptAlgorithmSid' => PasswordEncoder::getAlgorithmId($documentProtection->getAlgorithm()),
206206
'w:cryptSpinCount' => $documentProtection->getSpinCount(),
207207
'w:hash' => $passwordHash,
208208
'w:salt' => base64_encode($documentProtection->getSalt()),

tests/PhpWord/Writer/Word2007/Part/SettingsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use PhpOffice\PhpWord\SimpleType\Zoom;
2525
use PhpOffice\PhpWord\Style\Language;
2626
use PhpOffice\PhpWord\TestHelperDOCX;
27+
use PhpOffice\PhpWord\Shared\Microsoft\PasswordEncoder;
2728

2829
/**
2930
* Test class for PhpOffice\PhpWord\Writer\Word2007\Part\Settings
@@ -65,7 +66,7 @@ public function testDocumentProtectionWithPassword()
6566
$phpWord->getSettings()->getDocumentProtection()->setEditing('readOnly');
6667
$phpWord->getSettings()->getDocumentProtection()->setPassword('testÄö@€!$&');
6768
$phpWord->getSettings()->getDocumentProtection()->setSalt(base64_decode('uq81pJRRGFIY5U+E9gt8tA=='));
68-
$phpWord->getSettings()->getDocumentProtection()->setMswordAlgorithmSid(1);
69+
$phpWord->getSettings()->getDocumentProtection()->setAlgorithm(PasswordEncoder::ALGORITHM_MD2);
6970
$phpWord->getSettings()->getDocumentProtection()->setSpinCount(10);
7071

7172
$doc = TestHelperDOCX::getDocument($phpWord);

0 commit comments

Comments
 (0)