Test the admin pages, if read/list/delete is working.

This commit is contained in:
Jan Böhmer 2019-10-26 22:27:04 +02:00
parent 7e8752d1a2
commit dd1dc54d97
27 changed files with 858 additions and 109 deletions

View file

@ -0,0 +1,128 @@
<?php
/**
*
* part-db version 0.1
* Copyright (C) 2005 Christoph Lechner
* http://www.cl-projects.de/
*
* part-db version 0.2+
* Copyright (C) 2009 K. Jacobs and others (see authors.php)
* http://code.google.com/p/part-db/
*
* Part-DB Version 0.4+
* Copyright (C) 2016 - 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\DataFixtures;
use App\Entity\Attachments\AttachmentType;
use App\Entity\Base\StructuralDBElement;
use App\Entity\Devices\Device;
use App\Entity\Parts\Category;
use App\Entity\Parts\Footprint;
use App\Entity\Parts\Manufacturer;
use App\Entity\Parts\MeasurementUnit;
use App\Entity\Parts\Storelocation;
use App\Entity\Parts\Supplier;
use App\Entity\PriceInformations\Currency;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
class DataStructureFixtures extends Fixture
{
protected $em;
public function __construct(EntityManagerInterface $entityManager)
{
$this->em = $entityManager;
}
/**
* Load data fixtures with the passed EntityManager
*
* @param ObjectManager $manager
*/
public function load(ObjectManager $manager)
{
//Reset autoincrement
$types = [AttachmentType::class, Device::class, Category::class, Footprint::class, Manufacturer::class,
MeasurementUnit::class, Storelocation::class, Supplier::class];
foreach ($types as $type) {
$this->createNodesForClass($type, $manager);
}
$manager->flush();
}
/**
* Creates a datafixture with serveral nodes for the given class.
* @param string $class The class for which the nodes should be generated (must be a StructuralDBElement child)
* @param ObjectManager $manager The ObjectManager that should be used to persist the nodes
*/
public function createNodesForClass(string $class, ObjectManager $manager)
{
if (!new $class() instanceof StructuralDBElement) {
throw new \InvalidArgumentException('$class must be a StructuralDBElement!');
}
$table_name = $this->em->getClassMetadata($class)->getTableName();
$this->em->getConnection()->exec("ALTER TABLE `$table_name` AUTO_INCREMENT = 1;");
/** @var StructuralDBElement $node1 */
$node1 = new $class();
$node1->setName('Node 1');
/** @var StructuralDBElement $node2 */
$node2 = new $class();
$node2->setName('Node 2');
/** @var StructuralDBElement $node3 */
$node3 = new $class();
$node3->setName('Node 3');
$node1_1 = new $class();
$node1_1->setName('Node 1.1');
$node1_1->setParent($node1);
$node1_2 = new $class();
$node1_2->setName('Node 1.2');
$node1_2->setParent($node1);
$node2_1 = new $class();
$node2_1->setName('Node 2.1');
$node2_1->setParent($node2);
$node1_1_1 = new $class();
$node1_1_1->setName('Node 1.1.1');
$node1_1_1->setParent($node1_1);
$manager->persist($node1);
$manager->persist($node2);
$manager->persist($node3);
$manager->persist($node1_1);
$manager->persist($node1_2);
$manager->persist($node2_1);
$manager->persist($node1_1_1);
}
}

View file

@ -16,19 +16,50 @@ class GroupFixtures extends Fixture
{
$admins = new Group();
$admins->setName('admins');
//Perm values taken from Version 1
$admins->getPermissions()->setRawPermissionValues([
'system' => '21','groups' => '1365','users' => '87381','self' => '85','config' => '85',
'database' => '21','parts' => '1431655765','parts_name' => '5','parts_description' => '5',
'parts_footprint' => '5','parts_manufacturer' => '5','parts_comment' => '5','parts_order' => '5',
'parts_orderdetails' => '341','parts_prices' => '341','parts_attachments' => '341','devices' => '5461',
'devices_parts' => '325','storelocations' => '5461','footprints' => '5461','categories' => '5461',
'suppliers' => '5461','manufacturers' => '5461','attachment_types' => '1365','tools' => '1365',
'labels' => '21','parts_category' => '5','parts_minamount' => '5','parts_lots' => '85','parts_tags' => '5',
'parts_unit' => '5','parts_mass' => '5','parts_status' => '5','parts_mpn' => '5','currencies' => '5461',
'measurement_units' => '5461'
]);
$this->setReference(self::ADMINS, $admins);
$manager->persist($admins);
$readonly = new Group();
$readonly->setName('readonly');
$readonly->getPermissions()->setRawPermissionValues([
'system' => '2','groups' => '2730','users' => '43690','self' => '25','config' => '170',
'database' => '42','parts' => '2778027689','parts_name' => '9','parts_description' => '9',
'parts_footprint' => '9','parts_manufacturer' => '9','parts_comment' => '9','parts_order' => '9',
'parts_orderdetails' => '681','parts_prices' => '681','parts_attachments' => '681','devices' => '1705',
'devices_parts' => '649','storelocations' => '1705','footprints' => '1705','categories' => '1705',
'suppliers' => '1705','manufacturers' => '1705','attachment_types' => '681','tools' => '1366',
'labels' => '165','parts_category' => '9','parts_minamount' => '9','parts_lots' => '169','parts_tags' => '9',
'parts_unit' => '9','parts_mass' => '9','parts_status' => '9','parts_mpn' => '9','currencies' => '9897',
'measurement_units' => '9897'
]);
$this->setReference(self::READONLY, $readonly);
$manager->persist($readonly);
$users = new Group();
$users->setName('users');
$users->getPermissions()->setRawPermissionValues([
'system' => '42','groups' => '2730','users' => '43690','self' => '89','config' => '105',
'database' => '41','parts' => '1431655765','parts_name' => '5','parts_description' => '5',
'parts_footprint' => '5','parts_manufacturer' => '5','parts_comment' => '5','parts_order' => '5',
'parts_orderdetails' => '341','parts_prices' => '341','parts_attachments' => '341','devices' => '5461',
'devices_parts' => '325','storelocations' => '5461','footprints' => '5461','categories' => '5461',
'suppliers' => '5461','manufacturers' => '5461','attachment_types' => '1365','tools' => '1365',
'labels' => '85','parts_category' => '5','parts_minamount' => '5','parts_lots' => '85','parts_tags' => '5',
'parts_unit' => '5','parts_mass' => '5','parts_status' => '5','parts_mpn' => '5','currencies' => '5461',
'measurement_units' => '5461'
]);
$this->setReference(self::USERS, $users);
$manager->persist($users);

View file

@ -28,12 +28,14 @@ class UserFixtures extends Fixture
$anonymous = new User();
$anonymous->setName('anonymous');
$anonymous->setGroup($this->getReference(GroupFixtures::READONLY));
$anonymous->setNeedPwChange(false);
$anonymous->setPassword($this->encoder->encodePassword($anonymous, 'test'));
$manager->persist($anonymous);
$admin = new User();
$admin->setName('admin');
$admin->setPassword($this->encoder->encodePassword($admin, 'test'));
$admin->setNeedPwChange(false);
$admin->setGroup($this->getReference(GroupFixtures::ADMINS));
$manager->persist($admin);
@ -45,6 +47,12 @@ class UserFixtures extends Fixture
$user->setGroup($this->getReference(GroupFixtures::USERS));
$manager->persist($user);
$noread = new User();
$noread->setName('noread');
$noread->setNeedPwChange(false);
$noread->setPassword($this->encoder->encodePassword($noread, 'test'));
$manager->persist($noread);
$manager->flush();
}
}