Tests/Services/DocumentServiceTest.php
changeset 65 ba6b8e38d90e
parent 63 774ba82dca59
child 67 989d9e117586
--- a/Tests/Services/DocumentServiceTest.php	Wed Dec 14 23:53:37 2011 +0100
+++ b/Tests/Services/DocumentServiceTest.php	Mon Dec 19 17:50:04 2011 +0100
@@ -41,6 +41,87 @@
         }
         return $this->_doctrine;
     }
+        
+    
+    public function testInsert()
+    {
+        $newdoc = new \Company\BaseBundle\Entity\Document();
+        $newdoc->setTitle("Title 5");
+        $newdoc->setDescription("Description 5");
+        
+        $this->getDoctrine()->getEntityManager()->persist($newdoc);
+        
+        $this->getDoctrine()->getEntityManager()->flush();
+        
+        
+        $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($newdoc->getId());
+        
+        $this->assertEquals("Title 5", $doc->getTitle());
+        $this->assertEquals("Description 5", $doc->getDescription());
+        
+        
+    }
+
+    public function testUpdate()
+    {
+        $hostdoc = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 3");
+        
+        $this->assertEquals("Title 3", $hostdoc->getTitle());
+        $this->assertEquals("Description 3", $hostdoc->getDescription());
+        
+        $hostdoc->setTitle("Title 3 modified");
+        $hostdoc->setDescription("Description 3 modified");
+        
+        $this->getDoctrine()->getEntityManager()->persist($hostdoc);
+        $this->getDoctrine()->getEntityManager()->flush();
+        
+        $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($hostdoc->getId());
+        
+        $this->assertEquals("Title 3 modified", $doc->getTitle());
+        $this->assertEquals("Description 3 modified", $doc->getDescription());
+
+    }
+    
+    public function testUpdateCategory()
+    {
+        $hostdoc = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 5");
+        $cat = $this->getDoctrine()->getRepository("CompanyBaseBundle:category")->findOneByName("cat3");
+    
+        $this->assertEquals("Title 5", $hostdoc->getTitle());
+        $this->assertEquals("Description 5", $hostdoc->getDescription());
+        $this->assertEquals("cat1,cat2", $hostdoc->getCategoriesStr());
+        
+        
+        $hostdoc->setTitle("Title 5 modified");
+        $hostdoc->setDescription("Description 5 modified");
+        $hostdoc->getCategories()->add($cat);
+    
+        $this->getDoctrine()->getEntityManager()->persist($hostdoc);
+        $this->getDoctrine()->getEntityManager()->flush();
+    
+        $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($hostdoc->getId());
+    
+        $this->assertEquals("Title 5 modified", $doc->getTitle());
+        $this->assertEquals("Description 5 modified", $doc->getDescription());
+        
+        
+        $this->assertEquals("cat1,cat2,cat3", $doc->getCategories());
+        
+    }
+    
+    
+    public function testDelete()
+    {
+        $hostdoc = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 10");
+        $hostdocid = $hostdoc->getId();
+        $this->getDoctrine()->getEntityManager()->remove($hostdoc);
+        $this->getDoctrine()->getEntityManager()->flush();
+        
+        $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($hostdocid);
+        
+        //$this->assertNull($doc);
+        
+    }
     
     
     public function testGetTagLabels()