<commit_before><?php

namespace Oro\Bundle\InstallerBundle\Tests\Unit\Composer;

use Symfony\Component\Filesystem\Filesystem;

use Oro\Bundle\InstallerBundle\Composer\PermissionsHandler;

class PermissionsHandlerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var PermissionsHandler
     */
    protected $handler;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject
     */
    protected $process;

    /**
     * @var string
     */
    protected $directory;

    protected function setUp()
    {
        $this->process = $this
            ->getMockBuilder('Symfony\Component\Process\Process')
            ->disableOriginalConstructor()
            ->getMock();

        $this->directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . time();

        $fs = new Filesystem();
        $fs->mkdir($this->directory);

        $this->handler = new PermissionsHandler();
        $this->handler->setProcess($this->process);
    }

    protected function tearDown()
    {
        $fs = new Filesystem();
        $fs->remove($this->directory);
    }

    public function testSetPermissionsSetfacl()
    {
        $this->process
            ->expects($this->atLeastOnce())
            ->method('isSuccessful')
            ->will($this->returnValue(true));

        $this->process
            ->expects($this->any())
            ->method('setCommandLine')
            ->with(
                $this->callback(
                    function ($argument) {
                        return in_array(
                            $argument,
                            [
                                PermissionsHandler::PS_AUX,
                                sprintf(
                                    PermissionsHandler::SETFACL,
                                    PermissionsHandler::SETFACL_MODE_NONE,
                                    PermissionsHandler::USER,
                                    PermissionsHandler::USER,
                                    $this->directory
                                ),
                                sprintf(
                                    PermissionsHandler::SETFACL,
                                    PermissionsHandler::SETFACL_MODE_NONE,
                                    PermissionsHandler::USER,
                                    PermissionsHandler::USER,
                                    $this->directory
                                ),
                            ]
                        );
                    }
                )
            );

        $this->process
            ->expects($this->exactly(3))
            ->method('setCommandLine');

        $this->process
            ->expects($this->atLeastOnce())
            ->method('getOutput')
            ->will($this->returnValue(PermissionsHandler::USER));

        $this->handler->setPermissionsSetfacl($this->directory);
    }

    public function testSetPermissionsChmod()
    {
        $this->process
            ->expects($this->atLeastOnce())
            ->method('isSuccessful')
            ->will($this->returnValue(true));

        $this->process
            ->expects($this->any())
            ->method('setCommandLine')
            ->with(
                $this->callback(
                    function ($argument) {
                        return in_array(
                            $argument,
                            [
                                PermissionsHandler::PS_AUX,
                                sprintf(
                                    PermissionsHandler::CHMOD,
                                    PermissionsHandler::USER,
                                    $this->directory
                                ),
                            ]
                        );
                    }
                )
            );

        $this->process
            ->expects($this->exactly(2))
            ->method('setCommandLine');

        $this->process
            ->expects($this->atLeastOnce())
            ->method('getOutput')
            ->will($this->returnValue(PermissionsHandler::USER));

        $this->handler->setPermissionsChmod($this->directory);
    }

    public function testSetPermissions()
    {
        $this->process
            ->expects($this->atLeastOnce())
            ->method('isSuccessful')
            ->will($this->returnValue(false));

        $this->process
            ->expects($this->atLeastOnce())
            ->method('getOutput')
            ->will($this->returnValue(PermissionsHandler::USER));

        $result = $this->handler->setPermissions($this->directory);

        $this->assertFalse($result);
    }
}<commit_msg>OC-318: OroCRM: First Run of Web Based Installer Fails with Permissions Errors - fix tests<commit_after><?php

namespace Oro\Bundle\InstallerBundle\Tests\Unit\Composer;

use Symfony\Component\Filesystem\Filesystem;

use Oro\Bundle\InstallerBundle\Composer\PermissionsHandler;

class PermissionsHandlerTest extends \PHPUnit_Framework_TestCase
{
    /**
     * @var PermissionsHandler
     */
    protected $handler;

    /**
     * @var \PHPUnit_Framework_MockObject_MockObject
     */
    protected $process;

    /**
     * @var string
     */
    protected $directory;

    protected function setUp()
    {
        $this->process = $this
            ->getMockBuilder('Symfony\Component\Process\Process')
            ->disableOriginalConstructor()
            ->getMock();

        $this->directory = sys_get_temp_dir() . DIRECTORY_SEPARATOR . time();

        $fs = new Filesystem();
        $fs->mkdir($this->directory);

        $this->handler = new PermissionsHandler();
        $this->handler->setProcess($this->process);
    }

    protected function tearDown()
    {
        $fs = new Filesystem();
        $fs->remove($this->directory);
    }

    public function testSetPermissionsSetfacl()
    {
        $this->process
            ->expects($this->atLeastOnce())
            ->method('isSuccessful')
            ->will($this->returnValue(true));

        $this->process
            ->expects($this->any())
            ->method('setCommandLine')
            ->with(
                $this->callback(
                    function ($argument) {
                        return in_array(
                            $argument,
                            [
                                PermissionsHandler::PS_AUX,
                                str_replace(
                                    [
                                        PermissionsHandler::VAR_USER,
                                        PermissionsHandler::VAR_GROUP,
                                        PermissionsHandler::VAR_PATH
                                    ],
                                    [
                                        PermissionsHandler::USER,
                                        PermissionsHandler::USER,
                                        $this->directory
                                    ],
                                    PermissionsHandler::SETFACL
                                )
                            ]
                        );
                    }
                )
            );

        $this->process
            ->expects($this->exactly(3))
            ->method('setCommandLine');

        $this->process
            ->expects($this->atLeastOnce())
            ->method('getOutput')
            ->will($this->returnValue(PermissionsHandler::USER));

        $this->handler->setPermissionsSetfacl($this->directory);
    }

    public function testSetPermissionsChmod()
    {
        $this->process
            ->expects($this->atLeastOnce())
            ->method('isSuccessful')
            ->will($this->returnValue(true));

        $this->process
            ->expects($this->any())
            ->method('setCommandLine')
            ->with(
                $this->callback(
                    function ($argument) {
                        return in_array(
                            $argument,
                            [
                                PermissionsHandler::PS_AUX,
                                str_replace(
                                    [PermissionsHandler::VAR_USER, PermissionsHandler::VAR_PATH],
                                    [PermissionsHandler::USER, $this->directory],
                                    PermissionsHandler::CHMOD
                                )
                            ]
                        );
                    }
                )
            );

        $this->process
            ->expects($this->exactly(3))
            ->method('setCommandLine');

        $this->process
            ->expects($this->atLeastOnce())
            ->method('getOutput')
            ->will($this->returnValue(PermissionsHandler::USER));

        $this->handler->setPermissionsChmod($this->directory);
    }

    public function testSetPermissions()
    {
        $this->process
            ->expects($this->atLeastOnce())
            ->method('isSuccessful')
            ->will($this->returnValue(false));

        $this->process
            ->expects($this->atLeastOnce())
            ->method('getOutput')
            ->will($this->returnValue(PermissionsHandler::USER));

        $result = $this->handler->setPermissions($this->directory);

        $this->assertFalse($result);
    }
}
{'fraction_non_alphanumeric': 0.11577145302803338, 'fraction_numerical': 0.000748983522362508, 'mean_word_length': 1.1905319896883055, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 166, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 27, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6348873', 'n_tokens_mistral': 2202, 'n_tokens_neox': 2116, 'n_words': 275}