Skip to content

Commit 70e84a6

Browse files
committed
Remove getter/setter for element
1 parent 06d7285 commit 70e84a6

3 files changed

Lines changed: 94 additions & 33 deletions

File tree

src/XML/AbstractSignedXMLElement.php

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ abstract class AbstractSignedXMLElement implements SignedElementInterface
4040
*/
4141
protected function __construct(DOMElement $xml, SignableElementInterface $elt, Signature $signature)
4242
{
43+
$this->element = $elt;
4344
$this->setStructure($xml);
44-
$this->setElement($elt);
4545
$this->setSignature($signature);
4646
}
4747

@@ -57,28 +57,6 @@ public function __toString(): string
5757
}
5858

5959

60-
/**
61-
* Collect the value of the unsigned element
62-
*
63-
* @return \SimpleSAML\XMLSecurity\XML\SignableElementInterface
64-
*/
65-
public function getElement(): SignableElementInterface
66-
{
67-
return $this->element;
68-
}
69-
70-
71-
/**
72-
* Set the value of the elment-property
73-
*
74-
* @param \SimpleSAML\XMLSecurity\XML\SignableElementInterface $elt
75-
*/
76-
private function setElement(SignableElementInterface $elt): void
77-
{
78-
$this->element = $elt;
79-
}
80-
81-
8260
/**
8361
* Collect the value of the structure-property
8462
*

tests/XML/CustomSigned.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,21 @@ public static function fromXML(DOMElement $xml): object
3434
Assert::same($xml->localName, 'CustomSignable', InvalidDOMElementException::class);
3535
Assert::same($xml->namespaceURI, CustomSignable::NS, InvalidDOMElementException::class);
3636

37-
var_dump($xml->ownerDocument->saveXML());
38-
// $signatureElement = XMLUtils::xpQuery($xml, './ds:Signature');
39-
// Assert::minCount($signatureElement, 1, MissingElementException::class);
40-
// Assert::minCount($signatureElement, 1, TooManyElementsException::class);
41-
$signature = Signature::getChildrenOfClass($xml);
42-
Assert::minCount($signature, 1, MissingElementException::class);
43-
Assert::minCount($signature, 1, TooManyElementsException::class);
37+
//var_dump($xml->ownerDocument->saveXML());
38+
$signatureElement = XMLUtils::xpQuery($xml, './ds:Signature');
39+
Assert::minCount($signatureElement, 1, MissingElementException::class);
40+
Assert::minCount($signatureElement, 1, TooManyElementsException::class);
41+
// $signature = Signature::getChildrenOfClass($xml);
42+
// Assert::minCount($signature, 1, MissingElementException::class);
43+
// Assert::minCount($signature, 1, TooManyElementsException::class);
4444

45-
// $clone = clone $signatureElement[0];
46-
// $signature = Signature::fromXML($clone);
45+
$clone = clone $signatureElement[0];
46+
$signature = Signature::fromXML($clone);
4747

4848
return new self(
4949
$xml,
5050
CustomSignable::fromXML($xml),
51-
array_pop($signature)
51+
$signature
5252
);
5353
}
5454
}

tests/XML/CustomSignedTest.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace SimpleSAML\XMLSecurity\Test\XML;
6+
7+
use DOMDocument;
8+
use PHPUnit\Framework\TestCase;
9+
use SimpleSAML\XML\DOMDocumentFactory;
10+
use SimpleSAML\XML\Chunk;
11+
use SimpleSAML\XMLSecurity\Test\XML\CustomSigned;
12+
13+
/**
14+
* Class \SimpleSAML\XMLSecurity\XML\CustomSignedTest
15+
*
16+
* @covers \SimpleSAML\XMLSecurity\XML\AbstractSignedXMLElement
17+
* @covers \SimpleSAML\XMLSecurity\XML\SignedElementTrait
18+
* @covers \SimpleSAML\XMLSecurity\Test\XML\CustomSigned
19+
*
20+
* @package simplesamlphp/xml-security
21+
*/
22+
final class SignedElementTest extends TestCase
23+
{
24+
/** @var \DOMDocument */
25+
private DOMDocument $document;
26+
27+
28+
/**
29+
*/
30+
public function setUp(): void
31+
{
32+
$this->document = DOMDocumentFactory::fromFile(
33+
dirname(dirname(__FILE__)) . '/resources/xml/custom_CustomSigned.xml'
34+
);
35+
}
36+
37+
38+
/**
39+
public function testMarshalling(): void
40+
{
41+
$document = DOMDocumentFactory::fromString(
42+
'<some>Chunk</some>'
43+
);
44+
45+
$customSignable = new CustomSignable(new Chunk($document->documentElement));
46+
$this->assertFalse($customSignable->isEmptyElement());
47+
$this->assertEquals(
48+
$this->document->saveXML($this->document->documentElement),
49+
strval($customSignable)
50+
);
51+
}
52+
*/
53+
54+
55+
/**
56+
public function testUnmarshalling(): void
57+
{
58+
$customSignable = CustomSignable::fromXML($this->document->documentElement);
59+
60+
$customSignableElement = $customSignable->getElement();
61+
$customSignableElement = $customSignableElement->getXML();
62+
63+
$this->assertEquals('some', $customSignableElement->tagName);
64+
$this->assertEquals(
65+
'Chunk',
66+
$customSignableElement->textContent
67+
);
68+
}
69+
*/
70+
71+
72+
/**
73+
* Test serialization / unserialization
74+
*/
75+
public function testSerialization(): void
76+
{
77+
$this->assertEquals(
78+
$this->document->saveXML($this->document->documentElement),
79+
strval(unserialize(serialize(CustomSigned::fromXML($this->document->documentElement))))
80+
);
81+
}
82+
}
83+

0 commit comments

Comments
 (0)