Exemple #1
0
 public function testTagCollection()
 {
     $pic = new Pic();
     $this->assertFalse($pic->containsTag('t'));
     $pic->addTag('t');
     $this->assertTrue($pic->containsTag('t'));
     $pic->removeTag('t');
     $this->assertFalse($pic->containsTag('t'));
     //Repeat Tag
     $this->assertFalse($pic->containsTag('t'));
     $pic->addTag('t');
     $pic->addTag('t');
     $this->assertTrue($pic->containsTag('t'));
     $pic->removeTag('t');
     $this->assertFalse($pic->containsTag('t'));
     $this->assertFalse($pic->removeTag('t'));
     //containsAllTag and containsAnyTag
     $pic->addTag('t1');
     $pic->addTag('t2');
     $pic->addTag('t3');
     $this->assertTrue($pic->containsAnyTag(array('t0', 't2')));
     $this->assertTrue($pic->containsAnyTag(array('t2', 't3')));
     $this->assertFalse($pic->containsAnyTag(array('t0', 't4')));
     $this->assertTrue($pic->containsAllTags(array('t1', 't2')));
     $this->assertTrue($pic->containsAllTags(array('t1')));
     $this->assertFalse($pic->containsAllTags(array('t0', 't2')));
     $this->assertFalse($pic->containsAllTags(array('t0', 't1', 't2', 't3')));
 }
 /**
  * Set a pic from an url into the series
  */
 public function addPicFile(Series $series, UploadedFile $picFile, $isBanner = false, $bannerTargetUrl = "")
 {
     if (UPLOAD_ERR_OK != $picFile->getError()) {
         throw new \Exception($picFile->getErrorMessage());
     }
     if (!is_file($picFile->getPathname())) {
         throw new FileNotFoundException($picFile->getPathname());
     }
     $path = $picFile->move($this->targetPath . "/" . $series->getId(), $picFile->getClientOriginalName());
     $pic = new Pic();
     $pic->setUrl(str_replace($this->targetPath, $this->targetUrl, $path));
     $pic->setPath($path);
     if ($isBanner) {
         $pic->setHide(true);
         $pic->addTag('banner');
         $series = $this->addBanner($series, $pic->getUrl(), $bannerTargetUrl);
     }
     // TODO: add pic the latest if it is banner
     $series->addPic($pic);
     $this->dm->persist($series);
     $this->dm->flush();
     return $series;
 }
 public function testRemovePicFromSeries()
 {
     $broadcast = $this->createBroadcast(Broadcast::BROADCAST_TYPE_PUB);
     $series = $this->factoryService->createSeries();
     $this->assertEquals(0, count($series->getPics()));
     $pic = new Pic();
     $url = 'http://domain.com/pic.png';
     $pic->setUrl($url);
     $pic->addTag('tag1');
     $pic->addTag('tag2');
     $pic->addTag('tag3');
     $pic->addTag('banner');
     $this->dm->persist($pic);
     $this->dm->flush();
     $series->addPic($pic);
     $this->assertEquals(1, count($series->getPics()));
     $series = $this->seriesPicService->removePicFromSeries($series, $pic->getId());
     $this->assertEquals(0, count($series->getPics()));
     $picPath = realpath(__DIR__ . '/../Resources') . DIRECTORY_SEPARATOR . 'picCopy2.png';
     if (copy($this->originalPicPath, $picPath)) {
         $picFile = new UploadedFile($picPath, 'pic2.png', null, null, null, true);
         $bannerTargetUrl = 'http://domain.com/banner';
         $series = $this->seriesPicService->addPicFile($series, $picFile, true, $bannerTargetUrl);
         $series = $this->repo->find($series->getId());
         $this->assertEquals(1, count($series->getPics()));
         $pic = $series->getPics()[0];
         $this->assertTrue($series->containsPic($pic));
         $series = $this->seriesPicService->removePicFromSeries($series, $pic->getId());
         $this->assertEquals(0, count($series->getPics()));
     }
 }