<commit_before><?php

/**
 * (c) FSi sp. z o.o. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace spec\FSi\Bundle\DoctrineExtensionsBundle\Resolver;

use FSi\DoctrineExtensions\Uploadable\File;
use Gaufrette\Adapter\Local;
use Gaufrette\Adapter\Cache;
use Gaufrette\Filesystem;
use PhpSpec\ObjectBehavior;
use Twig_Environment;

class FSiFilePathResolverSpec extends ObjectBehavior
{
    function let()
    {
        $this->beConstructedWith(__DIR__ . '/tmp', 'uploaded');
    }

    function it_generate_url_for_fsi_file_with_local_adapter(File $file, Filesystem $filesystem, Local $adapter)
    {
        $file->getKey()->willReturn('TestFolder/File/file name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $this->filePath($file)->shouldReturn('/uploaded/TestFolder/File/file%20name.jpg');
    }

    function it_generate_url_for_fsi_file_with_cache_adapter(File $file, Filesystem $filesystem, Local $adapter)
    {
        $file->getKey()->willReturn('/TestFolder/File/file&name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $this->filePath($file)->shouldReturn('/uploaded/TestFolder/File/file%26name.jpg');
    }

    function it_generate_url_with_file_path_prefix(File $file, Filesystem $filesystem, Cache $adapter)
    {
        $file->getKey()->willReturn('/TestFolder/File/file:name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $this->filePath($file, 'uploaded')->shouldReturn('/uploaded/TestFolder/File/file%3Aname.jpg');
    }

    function it_generate_url_with_file_path_prefix_that_should_be_trimed(
        File $file, Filesystem $filesystem, Local $adapter
    ) {
        $file->getKey()->willReturn('TestFolder/File/file<>name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $this->filePath($file, '/uploaded/')->shouldReturn('/uploaded/TestFolder/File/file%3C%3Ename.jpg');
    }

    function it_generate_url_for_fsi_file_with_external_adapter(
        File $file, Filesystem $filesystem, Local $adapter
    ) {
        $file->getKey()->willReturn('Test Folder/File/nazwy plików.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $file->getContent()->willReturn('file content');

        $this->filePath($file)->shouldReturn('/uploaded/Test%20Folder/File/nazwy%20plik%C3%B3w.jpg');
    }

    function it_generate_url_with_prefix_from_globals(
        Twig_Environment $environment, File $file, Filesystem $filesystem, Local $adapter
    ) {
        $environment->getGlobals()->willReturn(array('fsi_file_prefix' => 'uploaded'));
        $environment->initRuntime();

        $file->getKey()->willReturn('TestFolder/File/file%name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $this->filePath($file)->shouldReturn('/uploaded/TestFolder/File/file%25name.jpg');
    }

    function it_generate_url_with_passed_prefix_even_if_there_is_a_prefix_in_globals(
        Twig_Environment $environment, File $file, Filesystem $filesystem, Local $adapter
    ) {
        $environment->getGlobals()->willReturn(array(
                'fsi_file_prefix' => 'uploaded'
            ));
        $environment->initRuntime();

        $file->getKey()->willReturn('TestFolder/File/file1@2.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);


        $this->filePath($file, 'my_prefix')->shouldReturn('/my_prefix/TestFolder/File/file1%402.jpg');
    }

    /**
     * @param \FSi\DoctrineExtensions\Uploadable\File $file
     */
    function it_generate_fsi_file_basename($file)
    {
        $file->getName()->willReturn('TestFolder/File/file.jpg');

        $this->fileBasename($file)->shouldReturn('file.jpg');
    }<commit_msg>Updated FSiFilePathResolver Spec<commit_after><?php

/**
 * (c) FSi sp. z o.o. <<EMAIL>>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace spec\FSi\Bundle\DoctrineExtensionsBundle\Resolver;

use FSi\DoctrineExtensions\Uploadable\File;
use Gaufrette\Adapter\Local;
use Gaufrette\Adapter\Cache;
use Gaufrette\Filesystem;
use PhpSpec\ObjectBehavior;
use FSi\Bundle\DoctrineExtensionsBundle\Listener\Uploadable\Filesystem as UploadableFilesystem;
use Twig_Environment;

class FSiFilePathResolverSpec extends ObjectBehavior
{
    function let()
    {
        $this->beConstructedWith(__DIR__ . '/tmp', 'uploaded');
    }

    function it_generate_path_for_fsi_file_with_local_adapter(File $file, Filesystem $filesystem, Local $adapter)
    {
        $file->getKey()->willReturn('TestFolder/File/file name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $this->filePath($file)->shouldReturn('/uploaded/TestFolder/File/file%20name.jpg');
    }

    function it_generate_path_for_fsi_file_with_cache_adapter(File $file, Filesystem $filesystem, Local $adapter)
    {
        $file->getKey()->willReturn('/TestFolder/File/file&name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $this->filePath($file)->shouldReturn('/uploaded/TestFolder/File/file%26name.jpg');
    }

    function it_generate_path_with_file_path_prefix(File $file, Filesystem $filesystem, Cache $adapter)
    {
        $file->getKey()->willReturn('/TestFolder/File/file:name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $this->filePath($file, 'uploaded')->shouldReturn('/uploaded/TestFolder/File/file%3Aname.jpg');
    }

    function it_generate_path_with_file_path_prefix_that_should_be_trimed(
        File $file, Filesystem $filesystem, Local $adapter
    ) {
        $file->getKey()->willReturn('TestFolder/File/file<>name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $this->filePath($file, '/uploaded/')->shouldReturn('/uploaded/TestFolder/File/file%3C%3Ename.jpg');
    }

    function it_generate_path_for_fsi_file_with_external_adapter(
        File $file, Filesystem $filesystem, Local $adapter
    ) {
        $file->getKey()->willReturn('Test Folder/File/nazwy plików.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $file->getContent()->willReturn('file content');

        $this->filePath($file)->shouldReturn('/uploaded/Test%20Folder/File/nazwy%20plik%C3%B3w.jpg');
    }

    function it_generate_path_with_prefix_from_globals(
        Twig_Environment $environment, File $file, Filesystem $filesystem, Local $adapter
    ) {
        $environment->getGlobals()->willReturn(array('fsi_file_prefix' => 'uploaded'));
        $environment->initRuntime();

        $file->getKey()->willReturn('TestFolder/File/file%name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);

        $this->filePath($file)->shouldReturn('/uploaded/TestFolder/File/file%25name.jpg');
    }

    function it_generate_path_with_passed_prefix_even_if_there_is_a_prefix_in_globals(
        Twig_Environment $environment, File $file, Filesystem $filesystem, Local $adapter
    ) {
        $environment->getGlobals()->willReturn(array(
                'fsi_file_prefix' => 'uploaded'
            ));
        $environment->initRuntime();

        $file->getKey()->willReturn('TestFolder/File/file1@2.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getAdapter()->willReturn($adapter);


        $this->filePath($file, 'my_prefix')->shouldReturn('/my_prefix/TestFolder/File/file1%402.jpg');
    }

    function it_generate_url_for_fsi_file_with_base_url_set(
        File $file, UploadableFilesystem $filesystem, Local $adapter
    ) {
        $file->getKey()->willReturn('TestFolder/File/file name.jpg');
        $file->getFilesystem()->willReturn($filesystem);
        $filesystem->getBaseUrl()->willReturn("http://domain.com/basepath/");

        $this->fileUrl($file)->shouldReturn('http://domain.com/basepath/TestFolder/File/file%20name.jpg');
    }

    /**
     * @param \FSi\DoctrineExtensions\Uploadable\File $file
     */
    function it_generate_fsi_file_basename($file)
    {
        $file->getName()->willReturn('TestFolder/File/file.jpg');

        $this->fileBasename($file)->shouldReturn('file.jpg');
    }
{'fraction_non_alphanumeric': 0.15415460013366006, 'fraction_numerical': 0.004900868790376476, 'mean_word_length': 3.971760797342193, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 159, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '2279650', 'n_tokens_mistral': 2756, 'n_tokens_neox': 2704, 'n_words': 331}