1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony). |
4
|
|
|
* |
5
|
|
|
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics) |
6
|
|
|
* |
7
|
|
|
* This program is free software; you can redistribute it and/or |
8
|
|
|
* modify it under the terms of the GNU General Public License |
9
|
|
|
* as published by the Free Software Foundation; either version 2 |
10
|
|
|
* of the License, or (at your option) any later version. |
11
|
|
|
* |
12
|
|
|
* This program is distributed in the hope that it will be useful, |
13
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
14
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15
|
|
|
* GNU General Public License for more details. |
16
|
|
|
* |
17
|
|
|
* You should have received a copy of the GNU General Public License |
18
|
|
|
* along with this program; if not, write to the Free Software |
19
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
20
|
|
|
*/ |
21
|
|
|
|
22
|
|
|
namespace App\Tests\Services\Trees; |
23
|
|
|
|
24
|
|
|
use App\Entity\Attachments\AttachmentType; |
25
|
|
|
use App\Entity\Parts\Category; |
26
|
|
|
use App\Helpers\Trees\TreeViewNode; |
27
|
|
|
use App\Services\AmountFormatter; |
28
|
|
|
use App\Services\Trees\TreeViewGenerator; |
29
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
30
|
|
|
use PHPUnit\Framework\TestCase; |
|
|
|
|
31
|
|
|
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @group DB |
35
|
|
|
*/ |
36
|
|
|
class TreeViewGeneratorTest extends WebTestCase |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @var TreeViewGenerator |
40
|
|
|
*/ |
41
|
|
|
protected $service; |
42
|
|
|
protected $em; |
43
|
|
|
|
44
|
|
|
public function setUp() : void |
45
|
|
|
{ |
46
|
|
|
parent::setUp(); // TODO: Change the autogenerated stub |
47
|
|
|
|
48
|
|
|
//Get an service instance. |
49
|
|
|
self::bootKernel(); |
50
|
|
|
$this->service = self::$container->get(TreeViewGenerator::class); |
51
|
|
|
$this->em = self::$container->get(EntityManagerInterface::class); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function testGetGenericTree() |
55
|
|
|
{ |
56
|
|
|
$tree = $this->service->getGenericTree(AttachmentType::class, null); |
57
|
|
|
|
58
|
|
|
$this->assertIsArray($tree); |
59
|
|
|
$this->assertContainsOnlyInstancesOf(TreeViewNode::class, $tree); |
60
|
|
|
|
61
|
|
|
$this->assertCount(3, $tree); |
62
|
|
|
$this->assertCount(2, $tree[0]->getNodes()); |
63
|
|
|
$this->assertCount(1, $tree[0]->getNodes()[0]->getNodes()); |
64
|
|
|
$this->assertEmpty($tree[2]->getNodes()); |
65
|
|
|
$this->assertEmpty($tree[1]->getNodes()[0]->getNodes()); |
66
|
|
|
|
67
|
|
|
//Check text |
68
|
|
|
$this->assertEquals('Node 1', $tree[0]->getText()); |
69
|
|
|
$this->assertEquals('Node 2', $tree[1]->getText()); |
70
|
|
|
$this->assertEquals('Node 3', $tree[2]->getText()); |
71
|
|
|
$this->assertEquals('Node 1.1', $tree[0]->getNodes()[0]->getText()); |
72
|
|
|
$this->assertEquals('Node 1.1.1', $tree[0]->getNodes()[0]->getNodes()[0]->getText()); |
73
|
|
|
|
74
|
|
|
//Check that IDs were set correctly |
75
|
|
|
$this->assertEquals(1, $tree[0]->getId()); |
76
|
|
|
$this->assertEquals(2, $tree[1]->getId()); |
77
|
|
|
$this->assertEquals(7, $tree[0]->getNodes()[0]->getNodes()[0]->getId()); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function testGetTreeViewBasic() |
81
|
|
|
{ |
82
|
|
|
$tree = $this->service->getTreeView(Category::class); |
83
|
|
|
$this->assertIsArray($tree); |
84
|
|
|
$this->assertContainsOnlyInstancesOf(TreeViewNode::class, $tree); |
85
|
|
|
|
86
|
|
|
$this->assertCount(3, $tree); |
87
|
|
|
$this->assertCount(2, $tree[0]->getNodes()); |
88
|
|
|
$this->assertCount(1, $tree[0]->getNodes()[0]->getNodes()); |
89
|
|
|
|
90
|
|
|
//Assert that the nodes contain the correct links |
91
|
|
|
$this->assertEquals('/en/category/1/parts', $tree[0]->getHref()); |
92
|
|
|
$this->assertEquals('/en/category/2/parts', $tree[1]->getHref()); |
93
|
|
|
$this->assertEquals('/en/category/7/parts', $tree[0]->getNodes()[0]->getNodes()[0]->getHref()); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function testGetTreeViewNewEdit() |
97
|
|
|
{ |
98
|
|
|
$tree = $this->service->getTreeView(Category::class, null, 'newEdit'); |
99
|
|
|
|
100
|
|
|
//First element should link to new category |
101
|
|
|
$this->assertStringContainsStringIgnoringCase('New', $tree[0]->getText()); |
102
|
|
|
$this->assertEquals('/en/category/new', $tree[0]->getHref()); |
103
|
|
|
//By default the new element node is selected |
104
|
|
|
$this->assertTrue($tree[0]->getState()->getSelected()); |
105
|
|
|
|
106
|
|
|
//Next element is spacing |
107
|
|
|
$this->assertEquals('', $tree[1]->getText()); |
108
|
|
|
$this->assertTrue($tree[1]->getState()->getDisabled()); |
109
|
|
|
|
110
|
|
|
//All other elements should be normal |
111
|
|
|
$this->assertCount(5, $tree); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testGetTreeViewSelectedNode() |
115
|
|
|
{ |
116
|
|
|
$selected = $this->em->find(Category::class, 2); |
117
|
|
|
$tree = $this->service->getTreeView(Category::class, null, 'edit', $selected); |
118
|
|
|
|
119
|
|
|
$this->assertNull($tree[0]->getState()); |
120
|
|
|
//Only second element must be selected |
121
|
|
|
$this->assertTrue($tree[1]->getState()->getSelected()); |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths