<commit_before><?php

namespace PHPOrchestra\BackofficeBundle\Test\Manager;

use PHPOrchestra\BackofficeBundle\Manager\FolderManager;
use PHPOrchestra\ModelBundle\Document\Folder;
use PHPOrchestra\ModelBundle\Model\FolderInterface;
use PHPOrchestra\ModelBundle\Repository\FolderRepository;
use PHPOrchestra\ModelBundle\Document\MediaFolder;
use Doctrine\Common\Collections\ArrayCollection;

use Phake;

/**
 * Class FolderManagerTest
 */
class FolderManagerTest extends \PHPUnit_Framework_TestCase
{
    protected $manager;
    protected $folderRepository;
    protected $documentManager;

    /**
     * Set up the test
     */
    public function setUp()
    {
        $this->folderRepository = Phake::mock('PHPOrchestra\ModelBundle\Repository\FolderRepository');
        $this->documentManager = Phake::mock('Doctrine\ODM\MongoDB\DocumentManager');

        $this->manager = new FolderManager($this->folderRepository, $this->documentManager);
    }

    /**
     * @param MediaFolderInterface $folder
     * @param int                  $expectedCall
     * @param boolean              $isDeletable
     *
     * @dataProvider provideFolder
     */
    public function testDeleteTree($folder, $expectedCall, $isDeletable)
    {
        Phake::when($this->folderRepository)->find(Phake::anyParameters())->thenReturn($folder);
        $this->manager->deleteTree('test');
        Phake::verify($this->documentManager, Phake::times($expectedCall))->remove($folder);
    }

    /**
     * @param MediaFolderInterface $folder
     * @param int                  $expectedCall
     * @param boolean              $isDeletable
     *
     * @dataProvider provideFolder
     */
    public function testIsDeletable($folder, $expectedCall, $isDeletable)
    {
        Phake::when($this->folderRepository)->find($folder->getId())->thenReturn($folder);
        $this->assertEquals($this->manager->isDeletable($folder->getId()), $isDeletable);
    }

    /**
     * @return array
     */
    public function provideFolder()
    {
        $subfolder0 = Phake::mock('PHPOrchestra\ModelBundle\Document\MediaFolder');
        Phake::when($subfolder0)->getMedias()->thenReturn(new ArrayCollection());
        Phake::when($subfolder0)->getSubFolders()->thenReturn(new ArrayCollection());

        $subfolder1 = Phake::mock('PHPOrchestra\ModelBundle\Document\MediaFolder');
        Phake::when($subfolder1)->getMedias()->thenReturn(new ArrayCollection());
        Phake::when($subfolder1)->getSubFolders()->thenReturn(new ArrayCollection());

        $medias = new ArrayCollection();
        $medias->add(Phake::mock('PHPOrchestra\ModelBundle\Model\MediaInterface'));
        $medias->add(Phake::mock('PHPOrchestra\ModelBundle\Model\MediaInterface'));<commit_msg>add delete folder functionnality<commit_after><?php

namespace PHPOrchestra\BackofficeBundle\Test\Manager;

use PHPOrchestra\BackofficeBundle\Manager\FolderManager;
use PHPOrchestra\ModelBundle\Document\Folder;
use PHPOrchestra\ModelBundle\Model\FolderInterface;
use PHPOrchestra\ModelBundle\Repository\FolderRepository;
use PHPOrchestra\ModelBundle\Document\MediaFolder;
use Doctrine\Common\Collections\ArrayCollection;

use Phake;

/**
 * Class FolderManagerTest
 */
class FolderManagerTest extends \PHPUnit_Framework_TestCase
{
    protected $manager;
    protected $folderRepository;
    protected $documentManager;

    /**
     * Set up the test
     */
    public function setUp()
    {
        $this->folderRepository = Phake::mock('PHPOrchestra\ModelBundle\Repository\FolderRepository');
        $this->documentManager = Phake::mock('Doctrine\ODM\MongoDB\DocumentManager');

        $this->manager = new FolderManager($this->folderRepository, $this->documentManager);
    }

    /**
     * @param MediaFolderInterface $folder
     * @param int                  $expectedCall
     * @param boolean              $isDeletable
     *
     * @dataProvider provideFolder
     */
    public function testDeleteTree($folder, $expectedCall, $isDeletable)
    {
        Phake::when($this->folderRepository)->find(Phake::anyParameters())->thenReturn($folder);
        $this->manager->deleteTree('test');
        Phake::verify($this->documentManager, Phake::times($expectedCall))->remove($folder);
    }

    /**
     * @param MediaFolderInterface $folder
     * @param int                  $expectedCall
     * @param boolean              $isDeletable
     *
     * @dataProvider provideFolder
     */
    public function testIsDeletable($folder, $expectedCall, $isDeletable)
    {
        Phake::when($this->folderRepository)->find(Phake::anyParameters())->thenReturn($folder);
        $this->assertEquals($this->manager->isDeletable('test'), $isDeletable);
    }

    /**
     * @return array
     */
    public function provideFolder()
    {
        $subfolder0 = Phake::mock('PHPOrchestra\ModelBundle\Document\MediaFolder');
        Phake::when($subfolder0)->getMedias()->thenReturn(new ArrayCollection());
        Phake::when($subfolder0)->getSubFolders()->thenReturn(new ArrayCollection());

        $subfolder1 = Phake::mock('PHPOrchestra\ModelBundle\Document\MediaFolder');
        Phake::when($subfolder1)->getMedias()->thenReturn(new ArrayCollection());
        Phake::when($subfolder1)->getSubFolders()->thenReturn(new ArrayCollection());

        $medias = new ArrayCollection();
        $medias->add(Phake::mock('PHPOrchestra\ModelBundle\Model\MediaInterface'));
        $medias->add(Phake::mock('PHPOrchestra\ModelBundle\Model\MediaInterface'));
{'fraction_non_alphanumeric': 0.13638843426077468, 'fraction_numerical': 0.002182214948172395, 'mean_word_length': 3.7169811320754715, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 61, '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': '6535065', 'n_tokens_mistral': 1524, 'n_tokens_neox': 1527, 'n_words': 212}