Tests/Services/DocumentServiceTest.php
author ymh <ymh.work@gmail.com>
Mon, 19 Dec 2011 17:50:04 +0100
changeset 65 ba6b8e38d90e
parent 63 774ba82dca59
child 67 989d9e117586
permissions -rw-r--r--
Correct event mamangement in hdabo_sf
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
<?php
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
/*
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
 * This file is part of the WikiTagBundle package.
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
 *
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
 * (c) IRI <http://www.iri.centrepompidou.fr/>
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
 *
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
 * For the full copyright and license information, please view the LICENSE
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
 * file that was distributed with this source code.
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
 */
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
namespace IRI\Bundle\WikiTagBundle\Tests\Services;
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
require_once(__DIR__ . "/../../../../../../../app/AppKernel.php");
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
class DocumentServiceTest extends \PHPUnit_Framework_TestCase
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
{
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
    protected $_container;
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    19
    protected $_doctrine;
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    20
    protected $_application;
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    21
    protected $_kernel;
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
    
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
    public function __construct()
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
    {
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    25
        $this->_kernel = new \AppKernel("test", true);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    26
        $this->_kernel->boot();
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    27
        $this->_container = $this->_kernel->getContainer();
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
        parent::__construct();
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
    }
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    protected function get($service)
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    {
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
        return $this->_container->get($service);
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    }
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
    
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    36
    protected function getDoctrine()
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    37
    {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    38
        if(is_null($this->_doctrine))
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    39
        {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    40
            $this->_doctrine = $this->get('doctrine');
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    41
        }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    42
        return $this->_doctrine;
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
    43
    }
65
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    44
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    45
    
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    46
    public function testInsert()
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    47
    {
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    48
        $newdoc = new \Company\BaseBundle\Entity\Document();
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    49
        $newdoc->setTitle("Title 5");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    50
        $newdoc->setDescription("Description 5");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    51
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    52
        $this->getDoctrine()->getEntityManager()->persist($newdoc);
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    53
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    54
        $this->getDoctrine()->getEntityManager()->flush();
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    55
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    56
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    57
        $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($newdoc->getId());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    58
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    59
        $this->assertEquals("Title 5", $doc->getTitle());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    60
        $this->assertEquals("Description 5", $doc->getDescription());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    61
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    62
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    63
    }
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    64
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    65
    public function testUpdate()
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    66
    {
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    67
        $hostdoc = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 3");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    68
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    69
        $this->assertEquals("Title 3", $hostdoc->getTitle());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    70
        $this->assertEquals("Description 3", $hostdoc->getDescription());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    71
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    72
        $hostdoc->setTitle("Title 3 modified");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    73
        $hostdoc->setDescription("Description 3 modified");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    74
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    75
        $this->getDoctrine()->getEntityManager()->persist($hostdoc);
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    76
        $this->getDoctrine()->getEntityManager()->flush();
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    77
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    78
        $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($hostdoc->getId());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    79
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    80
        $this->assertEquals("Title 3 modified", $doc->getTitle());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    81
        $this->assertEquals("Description 3 modified", $doc->getDescription());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    82
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    83
    }
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    84
    
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    85
    public function testUpdateCategory()
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    86
    {
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    87
        $hostdoc = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 5");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    88
        $cat = $this->getDoctrine()->getRepository("CompanyBaseBundle:category")->findOneByName("cat3");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    89
    
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    90
        $this->assertEquals("Title 5", $hostdoc->getTitle());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    91
        $this->assertEquals("Description 5", $hostdoc->getDescription());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    92
        $this->assertEquals("cat1,cat2", $hostdoc->getCategoriesStr());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    93
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    94
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    95
        $hostdoc->setTitle("Title 5 modified");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    96
        $hostdoc->setDescription("Description 5 modified");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    97
        $hostdoc->getCategories()->add($cat);
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    98
    
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
    99
        $this->getDoctrine()->getEntityManager()->persist($hostdoc);
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   100
        $this->getDoctrine()->getEntityManager()->flush();
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   101
    
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   102
        $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($hostdoc->getId());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   103
    
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   104
        $this->assertEquals("Title 5 modified", $doc->getTitle());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   105
        $this->assertEquals("Description 5 modified", $doc->getDescription());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   106
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   107
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   108
        $this->assertEquals("cat1,cat2,cat3", $doc->getCategories());
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   109
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   110
    }
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   111
    
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   112
    
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   113
    public function testDelete()
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   114
    {
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   115
        $hostdoc = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 10");
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   116
        $hostdocid = $hostdoc->getId();
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   117
        $this->getDoctrine()->getEntityManager()->remove($hostdoc);
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   118
        $this->getDoctrine()->getEntityManager()->flush();
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   119
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   120
        $doc = $this->getDoctrine()->getRepository("WikiTagBundle:Document")->findOneByExternalId($hostdocid);
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   121
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   122
        //$this->assertNull($doc);
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   123
        
ba6b8e38d90e Correct event mamangement in hdabo_sf
ymh <ymh.work@gmail.com>
parents: 63
diff changeset
   124
    }
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   125
    
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   126
    
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   127
    public function testGetTagLabels()
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   128
    {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   129
        $doc_service = $this->get("wiki_tag.document");
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   130
        $doc1 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 1");
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   131
        
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   132
        $tags = $doc_service->getTagLabels($doc1->getId());
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   133
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   134
        $this->assertEquals(4,count($tags));
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   135
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   136
        $this->assertEquals(array("Tag1","Tag2","Tag3","Tag4"),$tags);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   137
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   138
    }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   139
    
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   140
    public function testCopyTags()
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   141
    {
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   142
    
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   143
        $doc_service = $this->get("wiki_tag.document");
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   144
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   145
        $doc1 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 1");
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   146
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   147
        $this->assertEquals(4,count($doc_service->getTagLabels($doc1->getId())));
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   148
                
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   149
        $doc2 = $this->getDoctrine()->getRepository("CompanyBaseBundle:Document")->findOneByTitle("Title 4");
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   150
        
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   151
        $this->assertEquals(0,count($doc_service->getTagLabels($doc2->getId())));
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   152
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   153
        $doc_service->copyTags($doc1->getId(), $doc2->getId());
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   154
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   155
        $this->assertEquals(4,count($doc_service->getTagLabels($doc2->getId())));
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   156
        $this->assertEquals(array("Tag1","Tag2","Tag3","Tag4"),$doc_service->getTagLabels($doc2->getId()));
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   157
        
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   158
    }
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   159
    
63
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   160
    public function setUp()
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   161
    {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   162
        $this->_application = new \Symfony\Bundle\FrameworkBundle\Console\Application($this->_kernel);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   163
        $this->_application->setAutoExit(false);
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   164
        $this->runConsole("doctrine:schema:drop", array("--force" => true));
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   165
        $this->runConsole("wikitag:schema:create");
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   166
        $this->runConsole("cache:warmup");
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   167
        $this->runConsole("doctrine:fixtures:load", array("--fixtures" => __DIR__ . "/../../../../../../../src/Company/BaseBundle/DataFixtures"));
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   168
    }
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   169
    
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   170
    protected function runConsole($command, Array $options = array())
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   171
    {
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   172
        
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   173
        $options["-e"] = "test";
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   174
        $options["-q"] = null;
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   175
        $options = array_merge($options, array('command' => $command));
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   176
        return $this->_application->run(new \Symfony\Component\Console\Input\ArrayInput($options));
774ba82dca59 add tests and fixtures
ymh <ymh.work@gmail.com>
parents: 57
diff changeset
   177
    }
57
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   178
    
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   179
}
186c4121c7b3 add service tp copy tag from one document to another
ymh <ymh.work@gmail.com>
parents:
diff changeset
   180