Exemplo n.º 1
0
 public function testFreez()
 {
     $em = $this->getMockBuilder('\\Doctrine\\ORM\\EntityManager')->disableOriginalConstructor()->getMock();
     $em->expects($this->atLeastOnce())->method('getReference')->will($this->returnCallback(function ($class_name, $id) {
         $ref = new \stdClass();
         $ref->class = $class_name;
         $ref->id = $id;
         return $ref;
     }));
     /* @var $doctrine \PHPUnit_Framework_MockObject_MockObject|Registry */
     $doctrine = $this->getMockBuilder('\\Doctrine\\Bundle\\DoctrineBundle\\Registry')->disableOriginalConstructor()->getMock();
     $doctrine->expects($this->once())->method('getManager')->will($this->returnValue($em));
     // set related entities
     $country = $this->getRef('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Country', 'setCountry');
     $storage = $this->getRef('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Storage', 'setStorage');
     $type = $this->getRef('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Type', 'setType');
     $genre1 = $this->getRef('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Genre', 'addGenre');
     $genre2 = $this->getRef('\\AnimeDb\\Bundle\\CatalogBundle\\Entity\\Genre', 'addGenre');
     $this->item->freez($doctrine);
     // test freez result
     $this->assertEquals($country, $this->item->getCountry());
     $this->assertEquals($storage, $this->item->getStorage());
     $this->assertEquals($type, $this->item->getType());
     $this->assertEquals($genre1, $this->item->getGenres()[0]);
     $this->assertEquals($genre2, $this->item->getGenres()[1]);
 }
Exemplo n.º 2
0
 /**
  * Fill item
  *
  * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $item
  * @param \AnimeDb\Bundle\CatalogBundle\Entity\Item $new_item
  * @param string $field
  *
  * @return \AnimeDb\Bundle\CatalogBundle\Entity\Item
  */
 protected function fillItem(Item $item, Item $new_item, $field)
 {
     switch ($field) {
         case self::FIELD_COUNTRY:
             $item->setCountry($new_item->getCountry());
             break;
         case self::FIELD_DATE_END:
             $item->setDateEnd($new_item->getDateEnd());
             break;
         case self::FIELD_DATE_PREMIERE:
             $item->setDatePremiere($new_item->getDatePremiere());
             break;
         case self::FIELD_DURATION:
             $item->setDuration($new_item->getDuration());
             break;
         case self::FIELD_EPISODES:
             $item->setEpisodes($new_item->getEpisodes());
             break;
         case self::FIELD_EPISODES_NUMBER:
             $item->setEpisodesNumber($new_item->getEpisodesNumber());
             break;
         case self::FIELD_FILE_INFO:
             $item->setFileInfo($new_item->getFileInfo());
             break;
         case self::FIELD_GENRES:
             /* @var $new_genre \AnimeDb\Bundle\CatalogBundle\Entity\Genre */
             foreach ($new_item->getGenres() as $new_genre) {
                 $item->addGenre($new_genre);
             }
             break;
         case self::FIELD_NAMES:
             // set main name in top of names list
             $new_names = $new_item->getNames()->toArray();
             array_unshift($new_names, (new Name())->setName($new_item->getName()));
             foreach ($new_names as $new_name) {
                 $item->addName($new_name);
             }
             break;
         case self::FIELD_SOURCES:
             foreach ($new_item->getSources() as $new_source) {
                 $item->addSource($new_source);
             }
             break;
         case self::FIELD_STUDIO:
             $item->setStudio($new_item->getStudio());
             break;
         case self::FIELD_SUMMARY:
             $item->setSummary($new_item->getSummary());
             break;
     }
     return $item;
 }
Exemplo n.º 3
0
 /**
  * Get form for field.
  *
  * @param string $field
  * @param Item $item_origin
  * @param Item $item_fill
  *
  * @return Form
  */
 protected function getForm($field, Item $item_origin, Item $item_fill)
 {
     switch ($field) {
         case RefillerInterface::FIELD_DATE_END:
             $form = new DateEndForm();
             $data = ['date_end' => $item_fill->getDateEnd()];
             break;
         case RefillerInterface::FIELD_DATE_PREMIERE:
             $form = new DatePremiereForm();
             $data = ['date_premiere' => $item_fill->getDatePremiere()];
             break;
         case RefillerInterface::FIELD_DURATION:
             $form = new DurationForm();
             $data = ['duration' => $item_fill->getDuration()];
             break;
         case RefillerInterface::FIELD_EPISODES:
             $form = new EpisodesForm();
             $data = ['episodes' => $item_fill->getEpisodes()];
             break;
         case RefillerInterface::FIELD_EPISODES_NUMBER:
             $form = new EpisodesNumberForm();
             $data = ['episodes_number' => $item_fill->getEpisodesNumber()];
             break;
         case RefillerInterface::FIELD_FILE_INFO:
             $form = new FileInfoForm();
             $data = ['file_info' => $item_fill->getFileInfo()];
             break;
         case RefillerInterface::FIELD_GENRES:
             $form = $this->get('anime_db.form.type.refill.gengres');
             $data = ['genres' => $item_fill->getGenres()];
             break;
         case RefillerInterface::FIELD_IMAGES:
             $form = new ImagesForm();
             $data = ['images' => $item_fill->getImages()];
             break;
         case RefillerInterface::FIELD_COUNTRY:
             $form = $this->get('anime_db.form.type.refill.country');
             $data = ['country' => $item_fill->getCountry()];
             break;
         case RefillerInterface::FIELD_NAMES:
             $form = new NamesForm();
             $data = ['names' => $item_fill->getNames()];
             break;
         case RefillerInterface::FIELD_SOURCES:
             $form = new SourcesForm();
             $data = ['sources' => $item_fill->getSources()];
             break;
         case RefillerInterface::FIELD_SUMMARY:
             $form = new SummaryForm();
             $data = ['summary' => $item_fill->getSummary()];
             break;
         case RefillerInterface::FIELD_TRANSLATE:
             $form = new TranslateForm();
             $data = ['translate' => $item_fill->getTranslate()];
             break;
         case RefillerInterface::FIELD_STUDIO:
             $form = $this->get('anime_db.form.type.refill.studio');
             $data = ['studio' => $item_fill->getStudio()];
             break;
         default:
             throw $this->createNotFoundException('Field \'' . $field . '\' is not supported');
     }
     // search new source link
     /* @var $sources_origin Source[] */
     $sources_origin = array_reverse($item_origin->getSources()->toArray());
     /* @var $sources_fill Source[] */
     $sources_fill = array_reverse($item_fill->getSources()->toArray());
     foreach ($sources_fill as $source_fill) {
         // sources is already added
         foreach ($sources_origin as $source_origin) {
             if ($source_fill->getUrl() == $source_origin->getUrl()) {
                 continue 2;
             }
         }
         $data['source'] = $source_fill->getUrl();
         break;
     }
     return $this->createForm($form, $data);
 }