Completed
Push — master ( e43892...0ee3d6 )
by
unknown
02:55
created

FolderRepositoryTest::testFindFolderTree()   A

↳ Parent: FolderRepositoryTest

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 12
Code Lines 9

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 0
1
<?php
2
3
namespace OpenOrchestra\FunctionalTests\MediaBundle\Repository;
4
5
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase;
6
use OpenOrchestra\Media\Repository\FolderRepositoryInterface;
7
8
/**
9
 * Class FolderRepositoryTest
10
 *
11
 * @group integrationTest
12
 */
13
class FolderRepositoryTest extends AbstractKernelTestCase
14
{
15
    /**
16
     * @var FolderRepositoryInterface
17
     */
18
    protected $repository;
19
20
    /**
21
     * Set up test
22
     */
23
    protected function setUp()
24
    {
25
        parent::setUp();
26
27
        static::bootKernel();
28
        $this->repository = static::$kernel->getContainer()->get('open_orchestra_media.repository.media_folder');
29
    }
30
31
    /**
32
     * @param string $siteId
33
     * @param int    $count
34
     *
35
     * @dataProvider provideSiteIdAndFolderCount
36
     */
37
    public function testFindAllRootFolderBySiteId($siteId, $count)
38
    {
39
        $result = $this->repository->findAllRootFolderBySiteId($siteId);
40
41
        $this->assertLessThanOrEqual($count, count($result));
42
    }
43
44
    /**
45
     * @return array
46
     */
47
    public function provideSiteIdAndFolderCount()
48
    {
49
        return array(
50
            array('1', 2),
51
            array('2', 2),
52
            array('3', 2),
53
        );
54
    }
55
56
    /**
57
     * test findFolderTree
58
     */
59
    public function testFindFolderTree()
60
    {
61
        $tree = $this->repository->findFolderTree('2');
62
63
        $this->assertTrue(is_array($tree));
64
        $this->assertSame(2, count($tree));
65
        $this->assertTree($tree[0], 2);
66
        $this->assertTree($tree[1], 1);
67
        $this->assertTree($tree[0]['children'][0], 1);
68
        $this->assertTree($tree[0]['children'][1], 0);
69
        $this->assertTree($tree[1]['children'][0], 0);
70
    }
71
72
    /**
73
     * @param mixed $tree
74
     * @param int   $childrenCount
75
     */
76
    protected function assertTree($tree, $childrenCount)
77
    {
78
        $this->assertTrue(is_array($tree));
79
        $this->assertArrayHasKey('folder', $tree);
80
        $this->assertArrayHasKey('children', $tree);
81
        $this->assertSame($childrenCount, count($tree['children']));
82
    }
83
}
84