<commit_before><?php

namespace CultuurNet\UDB3\Media;

use CultuurNet\UDB3\Offer\Commands\AuthorizableCommandInterface;
use CultuurNet\UDB3\Role\ValueObjects\Permission;
use CultuurNet\UDB3\Security\SecurityInterface;

class MediaSecurityTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var SecurityInterface|\PHPUnit_Framework_MockObject_MockObject
     */
    private $baseSecurity;

    /**
     * @var MediaSecurity|\PHPUnit_Framework_MockObject_MockObject
     */
    private $mediaSecurity;

    public function setUp()
    {
        $this->baseSecurity = $this->createMock(SecurityInterface::class);
        $this->mediaSecurity = new MediaSecurity($this->baseSecurity);
    }

    /**
     * @test
     */
    public function it_should_always_authorize_command_with_media_upload_permission()
    {
        /** @var AuthorizableCommandInterface|\PHPUnit_Framework_MockObject_MockObject $command */
        $command = $this->createMock(AuthorizableCommandInterface::class);
        $command
            ->expects($this->once())
            ->method('getPermission')
            ->willReturn(Permission::MEDIA_UPLOADEN());

        $authorized = $this->mediaSecurity->isAuthorized($command);

        $this->assertEquals(true, $authorized);
    }

    /**
     * @test
     */
    public function it_should_delegate_authorization_of_non_media_commands_to_the_decorated_security()
    {
        /** @var AuthorizableCommandInterface|\PHPUnit_Framework_MockObject_MockObject $command */
        $command = $this->createMock(AuthorizableCommandInterface::class);
        $command
            ->expects($this->once())
            ->method('getPermission')
            ->willReturn(Permission::GEBRUIKERS_BEHEREN());

        $this->baseSecurity
            ->expects($this->once())
            ->method('isAuthorized')
            ->with($command);

        $this->mediaSecurity->isAuthorized($command);
    }
}
<commit_msg>III-2308 Change unit test to cover UploadImage calls.<commit_after><?php

namespace CultuurNet\UDB3\Media;

use CultuurNet\UDB3\Language;
use CultuurNet\UDB3\Media\Commands\UploadImage;
use CultuurNet\UDB3\Media\Properties\MIMEType;
use CultuurNet\UDB3\Offer\Commands\AuthorizableCommandInterface;
use CultuurNet\UDB3\Role\ValueObjects\Permission;
use CultuurNet\UDB3\Security\SecurityInterface;
use ValueObjects\Identity\UUID;
use ValueObjects\StringLiteral\StringLiteral;

class MediaSecurityTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var SecurityInterface|\PHPUnit_Framework_MockObject_MockObject
     */
    private $baseSecurity;

    /**
     * @var MediaSecurity|\PHPUnit_Framework_MockObject_MockObject
     */
    private $mediaSecurity;

    public function setUp()
    {
        $this->baseSecurity = $this->createMock(SecurityInterface::class);
        $this->mediaSecurity = new MediaSecurity($this->baseSecurity);
    }

    /**
     * @test
     */
    public function it_should_always_authorize_command_with_media_upload_permission()
    {
        $command = new UploadImage(
            UUID::fromNative('de305d54-75b4-431b-adb2-eb6b9e546014'),
            new MIMEType('image/png'),
            StringLiteral::fromNative('description'),
            StringLiteral::fromNative('copyright'),
            StringLiteral::fromNative('/uploads/de305d54-75b4-431b-adb2-eb6b9e546014.png'),
            new Language('en')
        );

        $authorized = $this->mediaSecurity->isAuthorized($command);

        $this->assertEquals(true, $authorized);
    }

    /**
     * @test
     */
    public function it_should_delegate_authorization_of_non_media_commands_to_the_decorated_security()
    {
        /** @var AuthorizableCommandInterface|\PHPUnit_Framework_MockObject_MockObject $command */
        $command = $this->createMock(AuthorizableCommandInterface::class);
        $command
            ->expects($this->once())
            ->method('getPermission')
            ->willReturn(Permission::GEBRUIKERS_BEHEREN());

        $this->baseSecurity
            ->expects($this->once())
            ->method('isAuthorized')
            ->with($command);

        $this->mediaSecurity->isAuthorized($command);
    }
}

{'fraction_non_alphanumeric': 0.1199138343705122, 'fraction_numerical': 0.013164193393968406, 'mean_word_length': 3.2169525731584256, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, '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': '3607261', 'n_tokens_mistral': 1225, 'n_tokens_neox': 1195, 'n_words': 147}