public function testTips()
 {
     $client = static::makeClient(true);
     $tip = $this->fixtures->getReference('tipoftheday');
     /**
      * @var IriConverter
      */
     $iriConverter = $this->getContainer()->get('api.iri_converter');
     $iri = $iriConverter->getIriFromItem($tip);
     $iri .= '/markTipRead';
     $client->request('PUT', $iri);
     $response = json_decode($client->getResponse()->getContent());
     $this->assertObjectHasAttribute('name', $response);
     $this->assertObjectHasAttribute('@type', $response);
     $this->assertEquals('TipOfTheDay', $response->{'@type'});
     $this->assertEquals('FOO', $response->name);
     $client->request('GET', '/api/tip_of_the_day_histories');
     $response = json_decode($client->getResponse()->getContent());
     $this->assertObjectHasAttribute('@type', $response);
     $this->assertObjectHasAttribute('hydra:member', $response);
     $this->assertEquals('hydra:Collection', $response->{'@type'});
     $this->assertArrayHasKey(0, $response->{'hydra:member'});
     $this->assertEquals('FOO', $response->{'hydra:member'}[0]->name);
     $client->request('POST', '/api/tip_of_the_days/markAllTipsAsUnread');
     $this->assertEquals('OK', $client->getResponse()->getContent());
     $client->request('GET', '/api/tip_of_the_day_histories');
     $response = json_decode($client->getResponse()->getContent());
     $this->assertObjectHasAttribute('@type', $response);
     $this->assertObjectHasAttribute('hydra:member', $response);
     $this->assertEquals('hydra:Collection', $response->{'@type'});
     $this->assertEquals(0, count($response->{'hydra:member'}));
 }
 public function testStockHistory()
 {
     $client = static::makeClient(true);
     /**
      * @var $part1 Part
      */
     $part1 = $this->fixtures->getReference("part.1");
     $stockLevel = new StockEntry();
     $stockLevel->setPart($part1);
     $stockLevel->setStockLevel(5);
     $fosUser = $this->fixtures->getReference("user.admin");
     $userService = $this->getContainer()->get("partkeepr.userservice");
     $user = $userService->getProxyUser($fosUser->getUsername(), $userService->getBuiltinProvider(), true);
     $stockLevel->setUser($user);
     $part1->addStockLevel($stockLevel);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush();
     $iriCoverter = $this->getContainer()->get("api.iri_converter");
     $iri = $iriCoverter->getIriFromItem($part1);
     $client->request("GET", $iri);
     $response = $client->getResponse()->getContent();
     $responseObj = json_decode($response, true);
     $responseObj["stockLevels"] = array();
     $client->request("PUT", $iri, array(), array(), array(), json_encode($responseObj));
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->refresh($part1);
     $this->assertEquals(1, count($part1->getStockLevels()));
 }
Exemple #3
0
 public function testAssociationRemoval()
 {
     $part = new Part();
     $part->setName("TEST");
     $part->setCategory($this->getContainer()->get("partkeepr.part.category_service")->getRootNode());
     $part->setStorageLocation($this->fixtures->getReference("storagelocation.first"));
     $partManufacturer = new PartManufacturer();
     $partManufacturer->setManufacturer($this->fixtures->getReference("manufacturer.first"));
     $part->addManufacturer($partManufacturer);
     $partDistributor = new PartDistributor();
     $partDistributor->setDistributor($this->fixtures->getReference("distributor.first"));
     $part->addDistributor($partDistributor);
     $partAttachment = new PartAttachment();
     $fileService = $this->getContainer()->get("partkeepr_uploadedfile_service");
     $fileService->replaceFromData($partAttachment, "BLA", "test.txt");
     $part->addAttachment($partAttachment);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->persist($part);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush($part);
     $part->removeDistributor($partDistributor);
     $part->removeManufacturer($partManufacturer);
     $part->removeAttachment($partAttachment);
     $this->getContainer()->get("doctrine.orm.default_entity_manager")->flush($part);
     $storage = $fileService->getStorage($partAttachment);
     $this->assertNull($partDistributor->getId());
     $this->assertNull($partDistributor->getId());
     $this->assertNull($partAttachment->getId());
     $this->assertFalse($storage->has($partAttachment->getFullFilename()));
 }
 public function testTips()
 {
     $client = static::makeClient(true);
     $tip = $this->fixtures->getReference("tipoftheday");
     /**
      * @var $iriConverter IriConverter
      */
     $iriConverter = $this->getContainer()->get("api.iri_converter");
     $iri = $iriConverter->getIriFromItem($tip);
     $iri .= "/markTipRead";
     $client->request('PUT', $iri);
     $response = json_decode($client->getResponse()->getContent());
     $this->assertObjectHasAttribute("name", $response);
     $this->assertObjectHasAttribute("@type", $response);
     $this->assertEquals("TipOfTheDay", $response->{"@type"});
     $this->assertEquals("FOO", $response->name);
     $client->request('GET', '/api/tip_of_the_day_histories');
     $response = json_decode($client->getResponse()->getContent());
     $this->assertObjectHasAttribute("@type", $response);
     $this->assertObjectHasAttribute("hydra:member", $response);
     $this->assertEquals("hydra:Collection", $response->{"@type"});
     $this->assertArrayHasKey(0, $response->{"hydra:member"});
     $this->assertEquals("FOO", $response->{"hydra:member"}[0]->name);
     $client->request('POST', '/api/tip_of_the_days/markAllTipsAsUnread');
     $this->assertEquals("OK", $client->getResponse()->getContent());
     $client->request('GET', '/api/tip_of_the_day_histories');
     $response = json_decode($client->getResponse()->getContent());
     $this->assertObjectHasAttribute("@type", $response);
     $this->assertObjectHasAttribute("hydra:member", $response);
     $this->assertEquals("hydra:Collection", $response->{"@type"});
     $this->assertEquals(0, count($response->{"hydra:member"}));
 }
 public function testGetSalt()
 {
     $client = static::createClient();
     $request = array("username" => "admin");
     $client->request('POST', '/api/users/getSalt', array(), array(), array('CONTENT_TYPE' => 'application/json'), json_encode($request));
     $response = json_decode($client->getResponse()->getContent());
     $admin = $this->fixtures->getReference("user.admin");
     /**
      * @var FOSUser $admin
      */
     $this->assertEquals($admin->getSalt(), $response);
 }
 public function testIDReferenceArray()
 {
     $client = static::makeClient(true);
     /**
      * @var IriConverter
      */
     $iriConverter = $this->getContainer()->get('api.iri_converter');
     $filter = [["property" => "storageLocation", "operator" => "IN", "value" => [$iriConverter->getIriFromItem($this->fixtures->getReference("storagelocation.first")), $iriConverter->getIriFromItem($this->fixtures->getReference("storagelocation.second"))]]];
     $client->request('GET', "/api/parts?filter=" . json_encode($filter), [], [], ['CONTENT_TYPE' => 'application/json']);
     $data = json_decode($client->getResponse()->getContent(), true);
     $this->assertArrayHasKey("hydra:member", $data);
     $this->assertGreaterThan(1, $data["hydra:member"]);
 }
Exemple #7
0
 public function testProjectPartRemoval()
 {
     $client = static::makeClient(true);
     $project = $this->fixtures->getReference("project");
     $projectPart = $this->fixtures->getReference("projectpart.1");
     $project->removePart($projectPart);
     $serializedProject = $this->getContainer()->get("serializer")->normalize($project, 'jsonld');
     $iriConverter = $this->getContainer()->get("api.iri_converter");
     $iri = $iriConverter->getIriFromItem($project);
     $client->request('PUT', $iri, array(), array(), array(), json_encode($serializedProject));
     $response = json_decode($client->getResponse()->getContent());
     $this->markTestIncomplete("This test can't be completed yet. See https://github.com/dunglas/DunglasApiBundle/issues/285");
     $this->assertInternalType("array", $response->parts);
     $this->assertArrayNotHasKey(1, $response->parts, "When removing an entry from the ArrayCollection, the array must be resorted!");
 }
 public function testCreateCategory()
 {
     $client = static::makeClient(true);
     $rootCategory = $this->fixtures->getReference($this->getReferencePrefix() . ".root");
     /**
      * @var $iriConverter IriConverter
      */
     $iriConverter = $this->getContainer()->get("api.iri_converter");
     $request = array("parent" => $iriConverter->getIriFromItem($rootCategory), "name" => "test");
     $resource = $this->getContainer()->get("api.resource_collection")->getResourceForEntity($this->getResourceClass());
     $iri = $iriConverter->getIriFromResource($resource);
     $client->request('POST', $iri, array(), array(), array('CONTENT_TYPE' => 'application/json'), json_encode($request));
     $responseObject = json_decode($client->getResponse()->getContent());
     $this->assertInternalType("object", $responseObject);
     $this->assertObjectHasAttribute("@id", $responseObject);
     $this->assertObjectHasAttribute("name", $responseObject);
     $item = $iriConverter->getItemFromIri($responseObject->{"@id"});
     $this->assertNotNull($item->getParent());
     $this->assertEquals($item->getParent()->getId(), $rootCategory->getId());
 }
 public function testCreateCategory()
 {
     $client = static::makeClient(true);
     $rootCategory = $this->fixtures->getReference($this->getReferencePrefix() . '.root');
     /**
      * @var IriConverter
      */
     $iriConverter = $this->getContainer()->get('api.iri_converter');
     $request = ['parent' => $iriConverter->getIriFromItem($rootCategory), 'name' => 'test'];
     $resource = $this->getContainer()->get('api.resource_collection')->getResourceForEntity($this->getResourceClass());
     $iri = $iriConverter->getIriFromResource($resource);
     $client->request('POST', $iri, [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($request));
     $responseObject = json_decode($client->getResponse()->getContent());
     $this->assertInternalType('object', $responseObject);
     $this->assertObjectHasAttribute('@id', $responseObject);
     $this->assertObjectHasAttribute('name', $responseObject);
     $item = $iriConverter->getItemFromIri($responseObject->{'@id'});
     $this->assertNotNull($item->getParent());
     $this->assertEquals($item->getParent()->getId(), $rootCategory->getId());
 }
Exemple #10
0
 public function testSetStock()
 {
     $client = static::makeClient(true);
     /**
      * @var Part
      */
     $part = $this->fixtures->getReference('part.1');
     /**
      * @var IriConverter
      */
     $iriConverter = $this->getContainer()->get('api.iri_converter');
     $iri = $iriConverter->getIriFromItem($part);
     $iri .= '/setStock';
     $request = ['quantity' => 33];
     $client->request('PUT', $iri, [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($request));
     $result = json_decode($client->getResponse()->getContent());
     $newStockLevel = $this->getStockLevel($part);
     $this->assertEquals(33, $newStockLevel);
     $this->assertObjectHasAttribute('stockLevel', $result);
     $this->assertEquals($newStockLevel, $result->stockLevel);
 }
 public function testMoveCategory()
 {
     $client = static::makeClient(true);
     /**
      * @var AbstractCategory
      * @var $rootCategory    AbstractCategory
      */
     $secondCategory = $this->fixtures->getReference($this->getReferencePrefix() . '.second');
     $rootCategory = $this->fixtures->getReference($this->getReferencePrefix() . '.root');
     /**
      * @var IriConverter
      */
     $iriConverter = $this->getContainer()->get('api.iri_converter');
     $iri = $iriConverter->getIriFromItem($secondCategory);
     $iri .= '/move';
     $targetIri = $iriConverter->getIriFromItem($rootCategory);
     $request = ['parent' => $targetIri];
     $client->request('PUT', $iri, [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($request));
     $this->assertEquals($rootCategory->getId(), $secondCategory->getParent()->getId());
     $this->assertEquals('Root Node ➤ Second Category', $secondCategory->getCategoryPath());
 }
 public function testMoveCategory()
 {
     $client = static::makeClient(true);
     /**
      * @var $secondCategory AbstractCategory
      * @var $rootCategory   AbstractCategory
      */
     $secondCategory = $this->fixtures->getReference($this->getReferencePrefix() . ".second");
     $rootCategory = $this->fixtures->getReference($this->getReferencePrefix() . ".root");
     /**
      * @var $iriConverter IriConverter
      */
     $iriConverter = $this->getContainer()->get("api.iri_converter");
     $iri = $iriConverter->getIriFromItem($secondCategory);
     $iri .= "/move";
     $targetIri = $iriConverter->getIriFromItem($rootCategory);
     $request = array("parent" => $targetIri);
     $client->request('PUT', $iri, array(), array(), array('CONTENT_TYPE' => 'application/json'), json_encode($request));
     $this->assertEquals($rootCategory->getId(), $secondCategory->getParent()->getId());
     $this->assertEquals("Root Node ➤ Second Category", $secondCategory->getCategoryPath());
 }
Exemple #13
0
 public function testSetStock()
 {
     $client = static::makeClient(true);
     /**
      * @var $part Part
      */
     $part = $this->fixtures->getReference("part.1");
     /**
      * @var $iriConverter IriConverter
      */
     $iriConverter = $this->getContainer()->get("api.iri_converter");
     $iri = $iriConverter->getIriFromItem($part);
     $iri .= "/setStock";
     $request = array("quantity" => 33);
     $client->request('PUT', $iri, array(), array(), array('CONTENT_TYPE' => 'application/json'), json_encode($request));
     $result = json_decode($client->getResponse()->getContent());
     $newStockLevel = $this->getStockLevel($part);
     $this->assertEquals(33, $newStockLevel);
     $this->assertObjectHasAttribute("stockLevel", $result);
     $this->assertEquals($newStockLevel, $result->stockLevel);
 }
 public function testInternalPartNumberUniqueness()
 {
     $client = static::makeClient(true);
     /**
      * @var $iriConverter IriConverter
      */
     $iriConverter = $this->getContainer()->get('api.iri_converter');
     $part = ["name" => "foobar", "storageLocation" => $iriConverter->getIriFromItem($this->fixtures->getReference("storagelocation.first")), "category" => $iriConverter->getIriFromItem($this->fixtures->getReference("partcategory.first")), "partUnit" => $iriConverter->getIriFromItem($this->fixtures->getReference("partunit.default")), "internalPartNumber" => "foo123"];
     $client->request('POST', '/api/parts', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($part));
     $client->request('POST', '/api/parts', [], [], ['CONTENT_TYPE' => 'application/json'], json_encode($part));
     $this->assertEquals(500, $client->getResponse()->getStatusCode());
     $response = json_decode($client->getResponse()->getContent());
     $this->assertObjectHasAttribute("@type", $response);
     $this->assertObjectHasAttribute("@context", $response);
     $this->assertObjectHasAttribute('hydra:title', $response);
     $this->assertObjectHasAttribute('hydra:description', $response);
     $this->assertEquals('/api/contexts/Error', $response->{'@context'});
     $this->assertEquals('Error', $response->{'@type'});
     $this->assertEquals('An error occurred', $response->{'hydra:title'});
     $this->assertEquals('The internal part number is already used', $response->{'hydra:description'});
 }
Exemple #15
0
 public function testProjectAttachmentRemoval()
 {
     $client = static::makeClient(true);
     /**
      * @var Project
      */
     $project = $this->fixtures->getReference('project');
     $projectAttachment = new ProjectAttachment();
     $fileService = $this->getContainer()->get('partkeepr_uploadedfile_service');
     $fileService->replaceFromData($projectAttachment, 'BLA', 'test.txt');
     $project->addAttachment($projectAttachment);
     $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush($project);
     $project->removeAttachment($projectAttachment);
     $serializedProject = $this->getContainer()->get('serializer')->normalize($project, 'jsonld');
     $iriConverter = $this->getContainer()->get('api.iri_converter');
     $iri = $iriConverter->getIriFromItem($project);
     $client->request('PUT', $iri, [], [], [], json_encode($serializedProject));
     $response = json_decode($client->getResponse()->getContent());
     $this->assertInternalType('array', $response->attachments);
     $this->assertArrayNotHasKey(1, $response->attachments, 'When removing an entry from the ArrayCollection, the array must be resorted!');
     $this->assertEquals(0, count($response->attachments));
 }
Exemple #16
0
 public function testUserUnprotect()
 {
     /**
      * @var FOSUser
      */
     $fosUser = $this->fixtures->getReference('user.admin');
     $userService = $this->getContainer()->get('partkeepr.userservice');
     $user = $userService->getProxyUser($fosUser->getUsername(), $userService->getBuiltinProvider(), true);
     /*
      * @var User $user
      */
     $userService->unprotect($user);
     $this->assertFalse($user->isProtected());
 }
 public function testDistributorFilter()
 {
     /**
      * @var Part
      */
     $part = $this->fixtures->getReference('part.1');
     /**
      * @var Distributor
      */
     $distributor = $this->fixtures->getReference('distributor.first');
     $partDistributor = new PartDistributor();
     $partDistributor->setDistributor($distributor);
     $part->addDistributor($partDistributor);
     $this->getContainer()->get('doctrine.orm.default_entity_manager')->flush();
     $filter = ['property' => 'distributors.distributor', 'operator' => '=', 'value' => $this->getContainer()->get('api.iri_converter')->getIriFromItem($distributor)];
     $filters = [$filter];
     $client = static::makeClient(true);
     $partResource = $this->getContainer()->get('resource.part');
     $iri = $this->getContainer()->get('api.iri_converter')->getIriFromResource($partResource);
     $client->request('GET', $iri, ['filter' => json_encode($filters)]);
     $this->assertEquals(200, $client->getResponse()->getStatusCode());
     $data = json_decode($client->getResponse()->getContent());
     $this->assertEquals(1, $data->{'hydra:totalItems'});
 }
 public function testReferenceReconstruction()
 {
     $em = $this->getMockSqliteEntityManager();
     $referenceRepository = new ProxyReferenceRepository($em);
     $listener = new ORMReferenceListener($referenceRepository);
     $em->getEventManager()->addEventSubscriber($listener);
     $schemaTool = new SchemaTool($em);
     $schemaTool->dropSchema(array());
     $schemaTool->createSchema(array($em->getClassMetadata(self::TEST_ENTITY_ROLE)));
     $roleFixture = new TestFixtures\RoleFixture();
     $roleFixture->setReferenceRepository($referenceRepository);
     $roleFixture->load($em);
     // first test against managed state
     $ref = $referenceRepository->getReference('admin-role');
     $this->assertNotInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $ref);
     // test reference reconstruction from serialized data (was managed)
     $serializedData = $referenceRepository->serialize();
     $proxyReferenceRepository = new ProxyReferenceRepository($em);
     $proxyReferenceRepository->unserialize($serializedData);
     $ref = $proxyReferenceRepository->getReference('admin-role');
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $ref);
     // now test reference reconstruction from identity
     $em->clear();
     $ref = $referenceRepository->getReference('admin-role');
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $ref);
     // test reference reconstruction from serialized data (was identity)
     $serializedData = $referenceRepository->serialize();
     $proxyReferenceRepository = new ProxyReferenceRepository($em);
     $proxyReferenceRepository->unserialize($serializedData);
     $ref = $proxyReferenceRepository->getReference('admin-role');
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $ref);
 }
 public function testReferenceMultipleEntries()
 {
     $em = $this->getMockSqliteEntityManager();
     $referenceRepository = new ProxyReferenceRepository($em);
     $em->getEventManager()->addEventSubscriber(new ORMReferenceListener($referenceRepository));
     $schemaTool = new SchemaTool($em);
     $schemaTool->createSchema(array($em->getClassMetadata(self::TEST_ENTITY_ROLE)));
     $role = new TestEntity\Role();
     $role->setName('admin');
     $em->persist($role);
     $referenceRepository->addReference('admin', $role);
     $referenceRepository->addReference('duplicate', $role);
     $em->flush();
     $em->clear();
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $referenceRepository->getReference('admin'));
     $this->assertInstanceOf('Doctrine\\ORM\\Proxy\\Proxy', $referenceRepository->getReference('duplicate'));
 }