<commit_before><?php

declare(strict_types=1);

namespace SAML2\XML\saml;

use PHPUnit\Framework\TestCase;
use SAML2\Constants;
use SAML2\DOMDocumentFactory;

/**
 * Tests for AttributeValue elements.
 *
 * @package simplesamlphp/saml2
 */
final class AttributeValueTest extends TestCase
{
    protected $document;


    protected function setUp(): void
    {
        $nssaml = Constants::NS_SAML;
        $nsxs = Constants::NS_XS;
        $nsxsi = Constants::NS_XSI;

        $this->document = DOMDocumentFactory::fromString(<<<XML
<saml:AttributeValue xmlns:saml="{$nssaml}" xmlns:xsi="{$nsxsi}" xmlns:xs="{$nsxs}" xsi:type="xs:string">value</saml:AttributeValue>
XML
        );
    }


    /**
     * Test creating an AttributeValue from scratch.
     */
    public function testMarshalling(): void
    {
        $av = new AttributeValue('value');
        $this->assertEquals('value', $av->getString());
    }


    /**
     * Verifies that supplying an empty string as attribute value will
     * generate a tag with no content (instead of e.g. an empty tag).
     * @return void
     */
    public function testEmptyStringAttribute(): void
    {
        $av = new AttributeValue('');
        $this->document->documentElement->textContent = '';
        $this->assertEqualXMLStructure(
            $this->document->documentElement,
            $av->toXML()
        );
        $this->assertEquals('', $av->getString());
    }


    /**4
     * Verifies that we can create an AttributeValue from a DOMElement.
     * @return void
     */
    public function testUnmarshalling(): void
    {
        $av = AttributeValue::fromXML($this->document->documentElement);
        $this->assertEquals('value', $av->getString());
        $this->assertEquals(
            $this->document->saveXML($this->document->documentElement),
            strval($av)
        );
    }


    /**
     * Serialize an AttributeValue and Unserialize that again.
     * @return void
     */
    public function testSerialize(): void
    {
        $this->assertEquals(<commit_msg>Raise coverage on AttributeValue<commit_after><?php

declare(strict_types=1);

namespace SAML2\XML\saml;

use PHPUnit\Framework\TestCase;
use SAML2\Constants;
use SAML2\DOMDocumentFactory;

/**
 * Tests for AttributeValue elements.
 *
 * @package simplesamlphp/saml2
 */
final class AttributeValueTest extends TestCase
{
    /** @var \DOMDocument */
    protected $document;


    /**
     * @return void
     */
    protected function setUp(): void
    {
        $nssaml = Constants::NS_SAML;
        $nsxs = Constants::NS_XS;
        $nsxsi = Constants::NS_XSI;

        $this->document = DOMDocumentFactory::fromString(<<<XML
<saml:AttributeValue xmlns:saml="{$nssaml}" xmlns:xsi="{$nsxsi}" xmlns:xs="{$nsxs}" xsi:type="xs:string">value</saml:AttributeValue>
XML
        );
    }


    /**
     * Test creating an AttributeValue from scratch using a string.
     *
     * @return void
     */
    public function testMarshallingString(): void
    {
        $av = new AttributeValue('value');
        $this->assertEquals('value', $av->getString());
    }


    /**
     * Test creating an AttributeValue from scratch using a DOMElement.
     *
     * @return void
     */
    public function testMarshallingDOMElement(): void
    {
        $av = new AttributeValue($this->document->documentElement);
        $this->assertEquals($this->document->documentElement, $av->getElement());
    }


    /**
     * Verifies that supplying an empty string as attribute value will
     * generate a tag with no content (instead of e.g. an empty tag).
     *
     * @return void
     */
    public function testEmptyStringAttribute(): void
    {
        $av = new AttributeValue('');
        $this->document->documentElement->textContent = '';
        $this->assertEqualXMLStructure(
            $this->document->documentElement,
            $av->toXML()
        );
        $this->assertEquals('', $av->getString());
    }


    /**
     * Verifies that we can create an AttributeValue from a DOMElement.
     *
     * @return void
     */
    public function testUnmarshalling(): void
    {
        $av = AttributeValue::fromXML($this->document->documentElement);
        $this->assertEquals('value', $av->getString());
        $this->assertEquals(
            $this->document->saveXML($this->document->documentElement),
            strval($av)
        );
    }


    /**
     * Serialize an AttributeValue and Unserialize that again.
     *
     * @return void
     */
    public function testSerialize(): void
    {
        $this->assertEquals(
{'fraction_non_alphanumeric': 0.13472858077174624, 'fraction_numerical': 0.002398081534772182, 'mean_word_length': 2.5899843505477307, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '967165', 'n_tokens_mistral': 1335, 'n_tokens_neox': 1287, 'n_words': 292}