From ab777bc2641b56267b6ffbe92ecac7439988acce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Sun, 9 Feb 2020 22:10:29 +0100 Subject: [PATCH] Add some fixtures for parts to test part pages. --- src/DataFixtures/PartFixtures.php | 123 ++++++++++++++++++ .../ApplicationAvailabilityFunctionalTest.php | 20 ++- tests/DatatablesAvailabilityTest.php | 69 ++++++++++ 3 files changed, 201 insertions(+), 11 deletions(-) create mode 100644 src/DataFixtures/PartFixtures.php create mode 100644 tests/DatatablesAvailabilityTest.php diff --git a/src/DataFixtures/PartFixtures.php b/src/DataFixtures/PartFixtures.php new file mode 100644 index 00000000..c8a42f3e --- /dev/null +++ b/src/DataFixtures/PartFixtures.php @@ -0,0 +1,123 @@ +em = $entityManager; + } + + /** + * @inheritDoc + */ + public function load(ObjectManager $manager) + { + $table_name = $this->em->getClassMetadata(Part::class)->getTableName(); + $this->em->getConnection()->exec("ALTER TABLE `${table_name}` AUTO_INCREMENT = 1;"); + + /** Simple part */ + $part = new Part(); + $part->setName('Part 1'); + $part->setCategory($manager->find(Category::class, 1)); + $manager->persist($part); + + /** More complex part */ + $part = new Part(); + $part->setName('Part 2'); + $part->setCategory($manager->find(Category::class, 1)); + $part->setFootprint($manager->find(Footprint::class, 1)); + $part->setManufacturer($manager->find(Manufacturer::class, 1)); + $part->setTags('test, Test, Part2'); + $part->setMass(100.2); + $part->setNeedsReview(true); + $part->setManufacturingStatus('active'); + $manager->persist($part); + + /** Part with orderdetails, storelocations and Attachments */ + $part = new Part(); + $part->setFavorite(true); + $part->setName('Part 2'); + $part->setCategory($manager->find(Category::class, 1)); + $partLot1 = new PartLot(); + $partLot1->setAmount(1.0); + $partLot1->setStorageLocation($manager->find(Storelocation::class, 1)); + $part->addPartLot($partLot1); + + $partLot2 = new PartLot(); + $partLot2->setExpirationDate(new \DateTime()); + $partLot2->setComment('Test'); + $partLot2->setNeedsRefill(true); + $partLot2->setStorageLocation($manager->find(Storelocation::class, 3)); + $part->addPartLot($partLot2); + + $orderdetail = new Orderdetail(); + $orderdetail->setSupplier($manager->find(Supplier::class, 1)); + $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(10)); + $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice(15)); + $part->addOrderdetail($orderdetail); + + $orderdetail = new Orderdetail(); + $orderdetail->setSupplierpartnr('BC 547'); + $orderdetail->setObsolete(true); + $orderdetail->setSupplier($manager->find(Supplier::class, 1)); + $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(1.0)->setPrice(10)); + $orderdetail->addPricedetail((new Pricedetail())->setPriceRelatedQuantity(10.0)->setPrice(15)); + $part->addOrderdetail($orderdetail); + + $attachment = new PartAttachment(); + $attachment->setName('TestAttachment'); + $attachment->setURL('www.foo.bar'); + $attachment->setAttachmentType($manager->find(AttachmentType::class, 1)); + $part->addAttachment($attachment); + + $attachment = new PartAttachment(); + $attachment->setName('Test2'); + $attachment->setPath('invalid'); + $attachment->setShowInTable(true); + $attachment->setAttachmentType($manager->find(AttachmentType::class, 1)); + $part->addAttachment($attachment); + + $manager->persist($part); + $manager->flush(); + } +} \ No newline at end of file diff --git a/tests/ApplicationAvailabilityFunctionalTest.php b/tests/ApplicationAvailabilityFunctionalTest.php index adfcec28..53615300 100644 --- a/tests/ApplicationAvailabilityFunctionalTest.php +++ b/tests/ApplicationAvailabilityFunctionalTest.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace App\Tests; +use App\Entity\Parts\Manufacturer; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; /** @@ -61,16 +62,6 @@ class ApplicationAvailabilityFunctionalTest extends WebTestCase yield ['/user/settings']; yield ['/user/info']; - //Part lists - yield ['/category/1/parts']; - yield ['/footprint/1/parts']; - yield ['/manufacturer/1/parts']; - yield ['/store_location/1/parts']; - yield ['/supplier/1/parts']; - yield ['/parts/by_tag/Test']; - yield ['/parts/search?keyword=test']; - yield ['/parts']; - //Login/logout yield ['/login']; @@ -89,7 +80,14 @@ class ApplicationAvailabilityFunctionalTest extends WebTestCase //yield ['/tree/device/1']; yield ['/tree/devices']; - yield ['/log/']; + //Part tests + yield ['/part/1']; + yield ['/part/2']; + yield ['/part/3']; + + yield ['/part/1/edit']; + yield ['/part/2/edit']; + yield ['/part/3/edit']; //Typeahead yield ['/typeahead/builtInResources/search/DIP8']; diff --git a/tests/DatatablesAvailabilityTest.php b/tests/DatatablesAvailabilityTest.php new file mode 100644 index 00000000..c3b2a87c --- /dev/null +++ b/tests/DatatablesAvailabilityTest.php @@ -0,0 +1,69 @@ + 'admin', + 'PHP_AUTH_PW' => 'test', + ]); + + $client->request('GET', $url); + $this->assertTrue($client->getResponse()->isSuccessful(), 'Request not successful. Status code is '.$client->getResponse()->getStatusCode()); + + $client->request('POST', $url, ['_dt' => 'dt']); + $this->assertTrue($client->getResponse()->isSuccessful()); + $this->assertJson($client->getResponse()->getContent()); + } + + public function urlProvider() + { + //Part lists + yield ['/category/1/parts']; + yield ['/footprint/1/parts']; + yield ['/manufacturer/1/parts']; + yield ['/store_location/1/parts']; + yield ['/supplier/1/parts']; + yield ['/parts/by_tag/Test']; + yield ['/parts/search?keyword=test']; + yield ['/parts']; + + yield ['/log/']; + + yield ['/attachment/list']; + + } +} \ No newline at end of file