Tests/Services/DocumentServiceTest.php
changeset 65 ba6b8e38d90e
parent 63 774ba82dca59
child 67 989d9e117586
equal deleted inserted replaced
64:caeb4c8b5487 65:ba6b8e38d90e
    38         if(is_null($this->_doctrine))
    38         if(is_null($this->_doctrine))
    39         {
    39         {
    40             $this->_doctrine = $this->get('doctrine');
    40             $this->_doctrine = $this->get('doctrine');
    41         }
    41         }
    42         return $this->_doctrine;
    42         return $this->_doctrine;
       
    43     }
       
    44         
       
    45     
       
    46     public function testInsert()
       
    47     {
       
    48         $newdoc = new \Company\BaseBundle\Entity\Document();
       
    49         $newdoc->setTitle("Title 5");
       
    50         $newdoc->setDescription("Description 5");
       
    51         
       
    52         $this->getDoctrine()->getEntityManager()->persist($newdoc);
       
    53         
       
    54         $this->getDoctrine()->getEntityManager()->flush();
       
    55         
       
    56         
       
    57         $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($newdoc->getId());
       
    58         
       
    59         $this->assertEquals("Title 5", $doc->getTitle());
       
    60         $this->assertEquals("Description 5", $doc->getDescription());
       
    61         
       
    62         
       
    63     }
       
    64 
       
    65     public function testUpdate()
       
    66     {
       
    67         $hostdoc = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 3");
       
    68         
       
    69         $this->assertEquals("Title 3", $hostdoc->getTitle());
       
    70         $this->assertEquals("Description 3", $hostdoc->getDescription());
       
    71         
       
    72         $hostdoc->setTitle("Title 3 modified");
       
    73         $hostdoc->setDescription("Description 3 modified");
       
    74         
       
    75         $this->getDoctrine()->getEntityManager()->persist($hostdoc);
       
    76         $this->getDoctrine()->getEntityManager()->flush();
       
    77         
       
    78         $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($hostdoc->getId());
       
    79         
       
    80         $this->assertEquals("Title 3 modified", $doc->getTitle());
       
    81         $this->assertEquals("Description 3 modified", $doc->getDescription());
       
    82 
       
    83     }
       
    84     
       
    85     public function testUpdateCategory()
       
    86     {
       
    87         $hostdoc = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 5");
       
    88         $cat = $this->getDoctrine()->getRepository("CompanyBaseBundle:category")->findOneByName("cat3");
       
    89     
       
    90         $this->assertEquals("Title 5", $hostdoc->getTitle());
       
    91         $this->assertEquals("Description 5", $hostdoc->getDescription());
       
    92         $this->assertEquals("cat1,cat2", $hostdoc->getCategoriesStr());
       
    93         
       
    94         
       
    95         $hostdoc->setTitle("Title 5 modified");
       
    96         $hostdoc->setDescription("Description 5 modified");
       
    97         $hostdoc->getCategories()->add($cat);
       
    98     
       
    99         $this->getDoctrine()->getEntityManager()->persist($hostdoc);
       
   100         $this->getDoctrine()->getEntityManager()->flush();
       
   101     
       
   102         $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($hostdoc->getId());
       
   103     
       
   104         $this->assertEquals("Title 5 modified", $doc->getTitle());
       
   105         $this->assertEquals("Description 5 modified", $doc->getDescription());
       
   106         
       
   107         
       
   108         $this->assertEquals("cat1,cat2,cat3", $doc->getCategories());
       
   109         
       
   110     }
       
   111     
       
   112     
       
   113     public function testDelete()
       
   114     {
       
   115         $hostdoc = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 10");
       
   116         $hostdocid = $hostdoc->getId();
       
   117         $this->getDoctrine()->getEntityManager()->remove($hostdoc);
       
   118         $this->getDoctrine()->getEntityManager()->flush();
       
   119         
       
   120         $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($hostdocid);
       
   121         
       
   122         //$this->assertNull($doc);
       
   123         
    43     }
   124     }
    44     
   125     
    45     
   126     
    46     public function testGetTagLabels()
   127     public function testGetTagLabels()
    47     {
   128     {