/**
  * @test
  */
 public function addTag()
 {
     $asset = $this->buildAssetObject();
     $tag = new Tag('test');
     $this->tagRepository->add($tag);
     $asset->addTag($tag);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $asset = $this->assetRepository->findAll()->getFirst();
     $this->assertAssetHasTags($asset, ['test']);
 }
 /**
  * @test
  */
 public function findBySearchTermReturnsFilteredResult()
 {
     $tag1 = new Tag('foobar');
     $tag2 = new Tag('foo bar');
     $tag3 = new Tag('bar foo bar');
     $this->tagRepository->add($tag1);
     $this->tagRepository->add($tag2);
     $this->tagRepository->add($tag3);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $this->assertCount(3, $this->tagRepository->findBySearchTerm('foo'));
     $this->assertCount(2, $this->tagRepository->findBySearchTerm('foo bar'));
     $this->assertCount(1, $this->tagRepository->findBySearchTerm(' foo '));
 }
 /**
  * @param string $label
  * @return void
  * @Flow\Validate(argumentName="label", type="NotEmpty")
  * @Flow\Validate(argumentName="label", type="Label")
  */
 public function createTagAction($label)
 {
     $existingTag = $this->tagRepository->findOneByLabel($label);
     if ($existingTag !== null) {
         if (($assetCollection = $this->browserState->get('activeAssetCollection')) !== null && $assetCollection->addTag($existingTag)) {
             $this->assetCollectionRepository->update($assetCollection);
             $this->addFlashMessage('tagAlreadyExistsAndAddedToCollection', '', Message::SEVERITY_OK, [htmlspecialchars($label)]);
         }
     } else {
         $tag = new Tag($label);
         $this->tagRepository->add($tag);
         if (($assetCollection = $this->browserState->get('activeAssetCollection')) !== null && $assetCollection->addTag($tag)) {
             $this->assetCollectionRepository->update($assetCollection);
         }
         $this->addFlashMessage('tagHasBeenCreated', '', Message::SEVERITY_OK, [htmlspecialchars($label)]);
     }
     $this->redirect('index');
 }
 /**
  * @test
  */
 public function findBySearchTermAndTagsReturnsFilteredResult()
 {
     $tag = new Tag('home');
     $this->tagRepository->add($tag);
     $resource1 = $this->resourceManager->importResource(__DIR__ . '/../../Fixtures/Resources/license.txt');
     $resource2 = $this->resourceManager->importResource(__DIR__ . '/../../Fixtures/Resources/417px-Mihaly_Csikszentmihalyi.jpg');
     $asset1 = new Asset($resource1);
     $asset1->setTitle('asset for homepage');
     $asset2 = new Asset($resource2);
     $asset2->setTitle('just another asset');
     $asset2->addTag($tag);
     $this->assetRepository->add($asset1);
     $this->assetRepository->add($asset2);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $this->assertCount(2, $this->assetRepository->findBySearchTermOrTags('home', array($tag)));
     $this->assertCount(2, $this->assetRepository->findBySearchTermOrTags('homepage', array($tag)));
     $this->assertCount(1, $this->assetRepository->findBySearchTermOrTags('baz', array($tag)));
     // This is necessary to initialize all resource instances before the tables are deleted
     foreach ($this->assetRepository->findAll() as $asset) {
         $asset->getResource()->getSha1();
     }
 }