mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-24 18:58:46 +02:00
Use new cached treeview nodes for twig inline generator (admin pages)
This commit is contained in:
parent
ad69c32832
commit
d9b15ddbb9
20 changed files with 277 additions and 214 deletions
|
@ -21,7 +21,7 @@
|
|||
|
||||
namespace App\Tests\Helpers;
|
||||
|
||||
use App\Helpers\TreeViewNode;
|
||||
use App\Helpers\Trees\TreeViewNode;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TreeViewNodeTest extends TestCase
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace App\Tests\Repository;
|
|||
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Entity\UserSystem\User;
|
||||
use App\Helpers\TreeViewNode;
|
||||
use App\Helpers\Trees\TreeViewNode;
|
||||
use App\Repository\NamedDBElementRepository;
|
||||
use App\Repository\StructuralDBElementRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
namespace App\Tests\Repository;
|
||||
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Helpers\TreeViewNode;
|
||||
use App\Helpers\Trees\TreeViewNode;
|
||||
use App\Repository\StructuralDBElementRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
|
80
tests/Services/Trees/NodesListBuilderTest.php
Normal file
80
tests/Services/Trees/NodesListBuilderTest.php
Normal file
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
/**
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
namespace App\Tests\Services\Trees;
|
||||
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Services\Trees\NodesListBuilder;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @Group DB
|
||||
* @package App\Tests\Services\Trees
|
||||
*/
|
||||
class NodesListBuilderTest extends WebTestCase
|
||||
{
|
||||
|
||||
/**
|
||||
* @var NodesListBuilder $service
|
||||
*/
|
||||
protected $service;
|
||||
protected $em;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
$this->service = self::$container->get(NodesListBuilder::class);
|
||||
$this->em = self::$container->get(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test $repo->toNodesList() for null as parameter
|
||||
*/
|
||||
public function testTypeToNodesListtRoot() : void
|
||||
{
|
||||
//List all root nodes and their children
|
||||
$nodes = $this->service->typeToNodesList(AttachmentType::class);
|
||||
|
||||
$this->assertCount(7, $nodes);
|
||||
$this->assertContainsOnlyInstancesOf(AttachmentType::class, $nodes);
|
||||
$this->assertEquals('Node 1', $nodes[0]->getName());
|
||||
$this->assertEquals('Node 1.1', $nodes[1]->getName());
|
||||
$this->assertEquals('Node 1.1.1', $nodes[2]->getName());
|
||||
$this->assertEquals('Node 1.2', $nodes[3]->getName());
|
||||
$this->assertEquals('Node 2', $nodes[4]->getName());
|
||||
$this->assertEquals('Node 2.1', $nodes[5]->getName());
|
||||
$this->assertEquals('Node 3', $nodes[6]->getName());
|
||||
}
|
||||
|
||||
public function testTypeToNodesListElement() : void
|
||||
{
|
||||
//List all nodes that are children to Node 1
|
||||
$node1 = $this->em->find(AttachmentType::class, 1);
|
||||
$nodes = $this->service->typeToNodesList(AttachmentType::class, $node1);
|
||||
|
||||
$this->assertCount(3, $nodes);
|
||||
$this->assertContainsOnlyInstancesOf(AttachmentType::class, $nodes);
|
||||
$this->assertEquals('Node 1.1', $nodes[0]->getName());
|
||||
$this->assertEquals('Node 1.1.1', $nodes[1]->getName());
|
||||
$this->assertEquals('Node 1.2', $nodes[2]->getName());
|
||||
}
|
||||
}
|
|
@ -22,21 +22,24 @@
|
|||
namespace App\Tests\Services\Trees;
|
||||
|
||||
use App\Entity\Attachments\AttachmentType;
|
||||
use App\Helpers\TreeViewNode;
|
||||
use App\Entity\Parts\Category;
|
||||
use App\Helpers\Trees\TreeViewNode;
|
||||
use App\Services\AmountFormatter;
|
||||
use App\Services\Trees\TreeViewGenerator;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
/**
|
||||
* @group DB
|
||||
*/
|
||||
class TreeGeneratorTest extends WebTestCase
|
||||
class TreeViewGeneratorTest extends WebTestCase
|
||||
{
|
||||
/**
|
||||
* @var TreeViewGenerator
|
||||
*/
|
||||
protected $service;
|
||||
protected $em;
|
||||
|
||||
public function setUp() : void
|
||||
{
|
||||
|
@ -45,6 +48,7 @@ class TreeGeneratorTest extends WebTestCase
|
|||
//Get an service instance.
|
||||
self::bootKernel();
|
||||
$this->service = self::$container->get(TreeViewGenerator::class);
|
||||
$this->em = self::$container->get(EntityManagerInterface::class);
|
||||
}
|
||||
|
||||
public function testGetGenericTree()
|
||||
|
@ -71,6 +75,49 @@ class TreeGeneratorTest extends WebTestCase
|
|||
$this->assertEquals(1, $tree[0]->getId());
|
||||
$this->assertEquals(2, $tree[1]->getId());
|
||||
$this->assertEquals(7, $tree[0]->getNodes()[0]->getNodes()[0]->getId());
|
||||
}
|
||||
|
||||
public function testGetTreeViewBasic()
|
||||
{
|
||||
$tree = $this->service->getTreeView(Category::class);
|
||||
$this->assertIsArray($tree);
|
||||
$this->assertContainsOnlyInstancesOf(TreeViewNode::class, $tree);
|
||||
|
||||
$this->assertCount(3, $tree);
|
||||
$this->assertCount(2, $tree[0]->getNodes());
|
||||
$this->assertCount(1, $tree[0]->getNodes()[0]->getNodes());
|
||||
|
||||
//Assert that the nodes contain the correct links
|
||||
$this->assertEquals('/en/category/1/parts', $tree[0]->getHref());
|
||||
$this->assertEquals('/en/category/2/parts', $tree[1]->getHref());
|
||||
$this->assertEquals('/en/category/7/parts', $tree[0]->getNodes()[0]->getNodes()[0]->getHref());
|
||||
}
|
||||
|
||||
public function testGetTreeViewNewEdit()
|
||||
{
|
||||
$tree = $this->service->getTreeView(Category::class, null, 'newEdit');
|
||||
|
||||
//First element should link to new category
|
||||
$this->assertStringContainsStringIgnoringCase('New', $tree[0]->getText());
|
||||
$this->assertEquals('/en/category/new', $tree[0]->getHref());
|
||||
//By default the new element node is selected
|
||||
$this->assertTrue($tree[0]->getState()->getSelected());
|
||||
|
||||
//Next element is spacing
|
||||
$this->assertEquals('', $tree[1]->getText());
|
||||
$this->assertTrue($tree[1]->getState()->getDisabled());
|
||||
|
||||
//All other elements should be normal
|
||||
$this->assertCount(5, $tree);
|
||||
}
|
||||
|
||||
public function testGetTreeViewSelectedNode()
|
||||
{
|
||||
$selected = $this->em->find(Category::class, 2);
|
||||
$tree = $this->service->getTreeView(Category::class, null, 'edit', $selected);
|
||||
|
||||
$this->assertNull($tree[0]->getState());
|
||||
//Only second element must be selected
|
||||
$this->assertTrue($tree[1]->getState()->getSelected());
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue