<commit_before><?php

/*
 * Copyright (c) 2016 Refinery29, Inc.
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Refinery29\Sitemap\Test\Unit\Component\Video;

use InvalidArgumentException;
use Refinery29\Sitemap\Component\Video\Restriction;
use Refinery29\Sitemap\Component\Video\RestrictionInterface;
use Refinery29\Test\Util\Faker\GeneratorTrait;
use ReflectionClass;

class RestrictionTest extends \PHPUnit_Framework_TestCase
{
    use GeneratorTrait;

    public function testIsFinal()
    {
        $reflectionClass = new ReflectionClass(Restriction::class);

        $this->assertTrue($reflectionClass->isFinal());
    }

    public function testImplementsRestrictionInterface()
    {
        $reflectionClass = new ReflectionClass(Restriction::class);

        $this->assertTrue($reflectionClass->implementsInterface(RestrictionInterface::class));
    }

    public function testDefaults()
    {
        $relationship = $this->getFaker()->randomElement([
            RestrictionInterface::RELATIONSHIP_ALLOW,
            RestrictionInterface::RELATIONSHIP_DENY,
        ]);

        $restriction = new Restriction($relationship);

        $this->assertInternalType('array', $restriction->countryCodes());
        $this->assertCount(0, $restriction->countryCodes());
    }

    /**
     * @dataProvider providerInvalidRestriction
     *
     * @param mixed $restriction
     */
    public function testConstructorRejectsInvalidRestriction($restriction)
    {
        $this->setExpectedException(InvalidArgumentException::class);

        new Restriction($restriction);
    }

    /**
     * @return \Generator
     */
    public function providerInvalidRestriction()
    {
        $values = [
            null,
            $this->getFaker()->sentence(),
        ];

        foreach ($values as $value) {
            yield [
                $value,
            ];
        }
    }

    public function testConstructorSetsValue()
    {
        $relationship = $this->getFaker()->randomElement([
            RestrictionInterface::RELATIONSHIP_ALLOW,
            RestrictionInterface::RELATIONSHIP_DENY,
        ]);

        $restriction = new Restriction($relationship);

        $this->assertSame($relationship, $restriction->relationship());
    }

    public function testWithCountryCodesClonesObjectAndSetsValue()
    {
        $faker = $this->getFaker();

        $countryCodes = [
            $faker->countryCode,
            $faker->countryCode,
            $faker->countryCode,
        ];

        $restriction = new Restriction($faker->randomElement([
            RestrictionInterface::RELATIONSHIP_ALLOW,
            RestrictionInterface::RELATIONSHIP_DENY,
        ]));

        $instance = $restriction->withCountryCodes($countryCodes);

        $this->assertInstanceOf(Restriction::class, $instance);<commit_msg>Enhancement: Assert that non-string country codes are rejected<commit_after><?php

/*
 * Copyright (c) 2016 Refinery29, Inc.
 *
 * For the full copyright and license information, please view
 * the LICENSE file that was distributed with this source code.
 */

namespace Refinery29\Sitemap\Test\Unit\Component\Video;

use InvalidArgumentException;
use Refinery29\Sitemap\Component\Video\Restriction;
use Refinery29\Sitemap\Component\Video\RestrictionInterface;
use Refinery29\Test\Util\Faker\GeneratorTrait;
use ReflectionClass;

class RestrictionTest extends \PHPUnit_Framework_TestCase
{
    use GeneratorTrait;

    public function testIsFinal()
    {
        $reflectionClass = new ReflectionClass(Restriction::class);

        $this->assertTrue($reflectionClass->isFinal());
    }

    public function testImplementsRestrictionInterface()
    {
        $reflectionClass = new ReflectionClass(Restriction::class);

        $this->assertTrue($reflectionClass->implementsInterface(RestrictionInterface::class));
    }

    public function testDefaults()
    {
        $relationship = $this->getFaker()->randomElement([
            RestrictionInterface::RELATIONSHIP_ALLOW,
            RestrictionInterface::RELATIONSHIP_DENY,
        ]);

        $restriction = new Restriction($relationship);

        $this->assertInternalType('array', $restriction->countryCodes());
        $this->assertCount(0, $restriction->countryCodes());
    }

    /**
     * @dataProvider providerInvalidRestriction
     *
     * @param mixed $restriction
     */
    public function testConstructorRejectsInvalidRestriction($restriction)
    {
        $this->setExpectedException(InvalidArgumentException::class);

        new Restriction($restriction);
    }

    /**
     * @return \Generator
     */
    public function providerInvalidRestriction()
    {
        $values = [
            null,
            $this->getFaker()->sentence(),
        ];

        foreach ($values as $value) {
            yield [
                $value,
            ];
        }
    }

    public function testConstructorSetsValue()
    {
        $relationship = $this->getFaker()->randomElement([
            RestrictionInterface::RELATIONSHIP_ALLOW,
            RestrictionInterface::RELATIONSHIP_DENY,
        ]);

        $restriction = new Restriction($relationship);

        $this->assertSame($relationship, $restriction->relationship());
    }

    /**
     * @dataProvider Refinery29\Test\Util\DataProvider\InvalidString::data
     *
     * @param mixed $countryCode
     */
    public function testWithCountryCodeRejectsInvalidCountryCodes($countryCode)
    {
        $this->setExpectedException(InvalidArgumentException::class);

        $faker = $this->getFaker();

        $countryCodes = [
            $faker->countryCode,
            $countryCode,
        ];

        $restriction = new Restriction(
            $faker->randomElement([
            RestrictionInterface::RELATIONSHIP_ALLOW,
            RestrictionInterface::RELATIONSHIP_DENY,
        ]));

        $restriction->withCountryCodes($countryCodes);
    }

    public function testWithCountryCodesClonesObjectAndSetsValue()
    {
        $faker = $this->getFaker();

        $countryCodes = [
            $faker->countryCode,
            $faker->countryCode,
            $faker->countryCode,
        ];

        $restriction = new Restriction($faker->randomElement([
            RestrictionInterface::RELATIONSHIP_ALLOW,
            RestrictionInterface::RELATIONSHIP_DENY,
        ]));

        $instance = $restriction->withCountryCodes($countryCodes);

        $this->assertInstanceOf(Restriction::class, $instance);
{'fraction_non_alphanumeric': 0.10945576162967467, 'fraction_numerical': 0.00486470051687443, 'mean_word_length': 2.8183401044689496, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 56, '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': '6711030', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1720, 'n_words': 279}