<commit_before><?php

declare(strict_types=1);

namespace SimpleSAML\Test\Utils\Config;

use DOMDocument;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use SAML2\Constants;
use SimpleSAML\Utils\Config\Metadata;
use TypeError;

/**
 * Tests related to SAML metadata.
 *
 * @covers \SimpleSAML\Utils\Config
 */
class MetadataTest extends TestCase
{
    /**
     * Test contact configuration parsing and sanitizing.
     */
    public function testGetContact(): void
    {
        // test missing type
        $contact = [
            'name' => '<NAME>'
        ];
        try {
            Metadata::getContact($contact);
        } catch (InvalidArgumentException $e) {
            $this->assertStringStartsWith('"contactType" is mandatory and must be one of ', $e->getMessage());
        }

        // test invalid type
        $contact = [
            'contactType' => 'invalid'
        ];
        try {
            Metadata::getContact($contact);
        } catch (InvalidArgumentException $e) {
            $this->assertStringStartsWith('"contactType" is mandatory and must be one of ', $e->getMessage());
        }

        // test all valid contact types
        foreach (Metadata::$VALID_CONTACT_TYPES as $type) {
            $contact = [
                'contactType' => $type
            ];
            $parsed = Metadata::getContact($contact);
            $this->assertArrayHasKey('contactType', $parsed);
            $this->assertArrayNotHasKey('givenName', $parsed);
            $this->assertArrayNotHasKey('surName', $parsed);
        }

        // test basic name parsing
        $contact = [
            'contactType' => 'technical',
            'name'        => '<NAME>'
        ];
        $parsed = Metadata::getContact($contact);
        $this->assertArrayNotHasKey('name', $parsed);
        $this->assertArrayHasKey('givenName', $parsed);
        $this->assertArrayHasKey('surName', $parsed);
        $this->assertEquals('John', $parsed['givenName']);
        $this->assertEquals('Doe', $parsed['surName']);

        // test comma-separated names
        $contact = [
            'contactType' => 'technical',
            'name'        => '<NAME>'
        ];
        $parsed = Metadata::getContact($contact);
        $this->assertArrayHasKey('givenName', $parsed);
        $this->assertArrayHasKey('surName', $parsed);
        $this->assertEquals('John', $parsed['givenName']);
        $this->assertEquals('Doe', $parsed['surName']);

        // test long names
        $contact = [
            'contactType' => 'technical',
            'name'        => '<NAME>'
        ];
        $parsed = Metadata::getContact($contact);
        $this->assertArrayNotHasKey('name', $parsed);
        $this->assertArrayHasKey('givenName', $parsed);
        $this->assertArrayNotHasKey('surName', $parsed);
        $this->assertEquals('<NAME>', $parsed['givenName']);

        // test comma-separated long names
        $contact = [
            'contactType' => 'technical',
            'name'        => '<NAME>, <NAME>'
        ];
        $parsed = Metadata::getContact($contact);
        $this->assertArrayNotHasKey('name', $parsed);
        $this->assertArrayHasKey('givenName', $parsed);
        $this->assertArrayHasKey('surName', $parsed);
        $this->assertEquals('<NAME>', $parsed['givenName']);
        $this->assertEquals('<NAME>', $parsed['surName']);

        // test givenName
        $contact = [
            'contactType' => 'technical',
        ];
        $invalid_types = [0, [0], 0.1, true, false];
        foreach ($invalid_types as $type) {
            $contact['givenName'] = $type;
            try {
                Metadata::getContact($contact);
            } catch (InvalidArgumentException $e) {
                $this->assertEquals('"givenName" must be a string and cannot be empty.', $e->getMessage());
            }
        }

        // test surName
        $contact = [
            'contactType' => 'technical',
        ];
        $invalid_types = [0, [0], 0.1, true, false];
        foreach ($invalid_types as $type) {
            $contact['surName'] = $type;
            try {
                Metadata::getContact($contact);
            } catch (InvalidArgumentException $e) {
                $this->assertEquals('"surName" must be a string and cannot be empty.', $e->getMessage());<commit_msg>Remove tests for removed functionality<commit_after><?php

declare(strict_types=1);

namespace SimpleSAML\Test\Utils\Config;

use DOMDocument;
use InvalidArgumentException;
use PHPUnit\Framework\TestCase;
use SAML2\Constants;
use SimpleSAML\Utils\Config\Metadata;
use TypeError;

/**
 * Tests related to SAML metadata.
 *
 * @covers \SimpleSAML\Utils\Config
 */
class MetadataTest extends TestCase
{
    /**
     * Test contact configuration parsing and sanitizing.
     */
    public function testGetContact(): void
    {
        // test missing type
        $contact = [
            'name' => '<NAME>'
        ];
        try {
            Metadata::getContact($contact);
        } catch (InvalidArgumentException $e) {
            $this->assertStringStartsWith('"contactType" is mandatory and must be one of ', $e->getMessage());
        }

        // test invalid type
        $contact = [
            'contactType' => 'invalid'
        ];
        try {
            Metadata::getContact($contact);
        } catch (InvalidArgumentException $e) {
            $this->assertStringStartsWith('"contactType" is mandatory and must be one of ', $e->getMessage());
        }

        // test all valid contact types
        foreach (Metadata::$VALID_CONTACT_TYPES as $type) {
            $contact = [
                'contactType' => $type
            ];
            $parsed = Metadata::getContact($contact);
            $this->assertArrayHasKey('contactType', $parsed);
            $this->assertArrayNotHasKey('givenName', $parsed);
            $this->assertArrayNotHasKey('surName', $parsed);
        }

        // test givenName
        $contact = [
            'contactType' => 'technical',
        ];
        $invalid_types = [0, [0], 0.1, true, false];
        foreach ($invalid_types as $type) {
            $contact['givenName'] = $type;
            try {
                Metadata::getContact($contact);
            } catch (InvalidArgumentException $e) {
                $this->assertEquals('"givenName" must be a string and cannot be empty.', $e->getMessage());
            }
        }

        // test surName
        $contact = [
            'contactType' => 'technical',
        ];
        $invalid_types = [0, [0], 0.1, true, false];
        foreach ($invalid_types as $type) {
            $contact['surName'] = $type;
            try {
                Metadata::getContact($contact);
            } catch (InvalidArgumentException $e) {
                $this->assertEquals('"surName" must be a string and cannot be empty.', $e->getMessage());
{'fraction_non_alphanumeric': 0.14544663573085848, 'fraction_numerical': 0.002900232018561485, 'mean_word_length': 2.1095581605049594, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '5557592', 'n_tokens_mistral': 1891, 'n_tokens_neox': 1854, 'n_words': 408}