/** * @dataProvider provideRemoveSnippetWithReferencesDereference */ public function testRemoveSnippetWithReferencesDereference($multiple = false) { $document = $this->documentManager->create('page'); $document->setTitle('test'); $document->setResourceSegment('/url/foo'); if ($multiple) { $document->getStructure()->bind(['animals' => [$this->snippet1->getUuid(), $this->snippet2->getUuid()]], false); } else { $document->getStructure()->bind(['animals' => $this->snippet1->getUuid()], false); } $document->setParent($this->parent); $document->setStructureType('test_page'); $this->documentManager->persist($document, 'de'); $this->documentManager->flush(); $this->contentMapper->delete($this->snippet1->getUuid(), 'sulu_io', true); try { $this->session->getNode($this->snippet1OriginalPath); $this->assertTrue(false, 'Snippet was found FAIL'); } catch (\PHPCR\PathNotFoundException $e) { $this->assertTrue(true, 'Snippet was removed'); } $referrer = $this->documentManager->find('/cmf/sulu_io/contents/test', 'de'); if ($multiple) { $contents = $referrer->getStructure()->getProperty('animals')->getValue(); $this->assertCount(1, $contents); $content = reset($contents); $this->assertEquals($this->snippet2->getUuid(), $content); } else { $contents = $referrer->getStructure()->getProperty('animals')->getValue(); $this->assertCount(0, $contents); } }
/** * Deletes an existing Snippet. * * @param Request $request * @param string $uuid * * @return JsonResponse */ public function deleteSnippetAction(Request $request, $uuid) { $webspaceKey = $request->query->get('webspace', null); $references = $this->snippetRepository->getReferences($uuid); if (count($references) > 0) { $force = $request->headers->get('SuluForceRemove', false); if ($force) { $this->contentMapper->delete($uuid, $webspaceKey, true); } else { return $this->getReferentialIntegrityResponse($webspaceKey, $references); } } else { $this->contentMapper->delete($uuid, $webspaceKey); } return new JsonResponse(); }
/** * It should delete a node which has children with history. * It should not throw an exception. */ public function testDeleteWithChildrenHistory() { $data = [['title' => 'A', 'url' => '/a'], ['title' => 'B', 'url' => '/a/b'], ['title' => 'C', 'url' => '/a/b/c'], ['title' => 'D', 'url' => '/a/d']]; // save content $data[0] = $this->mapper->save($data[0], 'overview', 'sulu_io', 'de', 1); $data[1] = $this->mapper->save($data[1], 'overview', 'sulu_io', 'de', 1, true, null, $data[0]->getUuid()); $data[2] = $this->mapper->save($data[2], 'overview', 'sulu_io', 'de', 1, true, null, $data[1]->getUuid()); $data[3] = $this->mapper->save($data[3], 'overview', 'sulu_io', 'de', 1, true, null, $data[0]->getUuid()); // move /a/b to /a/d/b $this->mapper->move($data[1]->getUuid(), $data[3]->getUuid(), 1, 'sulu_io', 'de'); // delete /a/d $this->mapper->delete($data[3]->getUuid(), 'sulu_io'); // check try { $this->mapper->load($data[3]->getUuid(), 'sulu_io', 'de'); $this->fail('Node should not exist'); } catch (DocumentNotFoundException $ex) { } $result = $this->mapper->loadByParent($data[0]->getUuid(), 'sulu_io', 'de'); $this->assertEquals(0, count($result)); }