/**
  * Test submit form with transformation on one field
  */
 public function testFormFieldTransformationException()
 {
     $content = new Content();
     $content->setContentType('news');
     $content->setSiteId('2');
     $content->setLanguage('fr');
     $form = $this->formFactory->create('oo_content', $content, array('csrf_protection' => false));
     $form->submit(array('name' => 'foo', 'keywords' => null, 'title' => 'foo', 'publish_start' => 'foo', 'publish_end' => '2015-12-17', 'image' => null, 'intro' => 'foo', 'text' => null));
     $this->assertSame('foo', $form->get('name')->getData());
     $this->assertCount(1, $form->get('publish_start')->getErrors());
     $this->assertNull($form->get('publish_start')->getData());
     $this->assertCount(1, $form->getErrors(true));
 }
 /**
  * test updateStatusByContentType
  */
 public function testUpdateStatusByContentType()
 {
     $contentTypeId = 'test';
     $outOfWorkflow = $this->statusRepository->findOneByOutOfWorkflow();
     $dm = $this->contentTypeRepository->getDocumentManager();
     $contentType = new ContentType();
     $contentType->setContentTypeId($contentTypeId);
     $dm->persist($contentType);
     $dm->flush();
     $content = new Content();
     $content->setContentType($contentTypeId);
     $dm->persist($content);
     $dm->flush();
     $this->assertEquals('draft', $content->getStatus()->getName());
     $this->repository->updateStatusByContentType($outOfWorkflow, $contentTypeId);
     $dm->clear();
     $updatedContent = $this->repository->findOneBy(array('_id' => $content->getId()));
     $this->assertEquals('outOfWorkflow', $updatedContent->getStatus()->getName());
     $contentType = $this->contentTypeRepository->findOneBy(array('contentTypeId' => $contentTypeId));
     $dm->remove($updatedContent);
     $dm->remove($contentType);
     $dm->flush();
 }
 /**
  * @param string $id
  * @param string $type
  * @param int    $typeVersion
  *
  * @return Content
  */
 protected function addBaseContent($id, $type, $typeVersion)
 {
     $content = new Content();
     $content->setContentId($id);
     $content->setContentType($type);
     $content->setContentTypeVersion($typeVersion);
     $content->setDeleted(false);
     $content->setCreatedBy('admin');
     $content->setStatus($this->getReference('status-published'));
     $content->setCurrentlyPublished(true);
     return $content;
 }
 /**
  * @param boolean $isLinkedToSite
  * @param string  $value
  *
  * @dataProvider provideLinkedToSiteAndValue
  */
 public function testPreUpdateWithNoExistingAttributes($isLinkedToSite, $value)
 {
     $attribute = Phake::mock('OpenOrchestra\\ModelInterface\\Model\\ContentAttributeInterface');
     Phake::when($attribute)->getValue()->thenReturn($value);
     $content = Phake::mock('OpenOrchestra\\ModelInterface\\Model\\ContentInterface');
     Phake::when($content)->isLinkedToSite()->thenReturn($isLinkedToSite);
     Phake::when($content)->getAttributeByName($this->fieldId)->thenReturn($attribute);
     Phake::when($this->event)->getDocument()->thenReturn($content);
     $contentDocument = new Content();
     Phake::when($this->contentRepository)->findByContentId(Phake::anyParameters())->thenReturn(array($contentDocument));
     $this->listener->preUpdate($this->event);
     $this->assertSame($isLinkedToSite, $contentDocument->isLinkedToSite());
     $field = $contentDocument->getAttributeByName($this->fieldId);
     $this->assertInstanceOf('OpenOrchestra\\ModelInterface\\Model\\ContentAttributeInterface', $field);
     $this->assertSame($value, $field->getValue());
     $this->assertSame($this->fieldId, $field->getName());
     Phake::verify($this->documentManager)->flush($contentDocument);
 }
 /**
  * @return Content
  */
 protected function generateCustomerContentFr()
 {
     $content = new Content();
     $content->setContentId("jsmith");
     $content->setContentType("customer");
     $content->setContentTypeVersion(1);
     $content->setDeleted(false);
     $content->setCreatedBy('admin');
     $content->setStatus($this->getReference('status-published'));
     $content->setName("John Smith");
     $content->setLanguage("fr");
     $content->setVersion(1);
     $content->setLinkedToSite(true);
     $content->setSiteId('3');
     $attribute1 = $this->generateContentAttribute('firstname', 'John');
     $attribute2 = $this->generateContentAttribute('lastname', 'Smith');
     $attribute3 = $this->generateContentAttribute('identifier', 4987, 'integer');
     $content->addAttribute($attribute1);
     $content->addAttribute($attribute2);
     $content->addAttribute($attribute3);
     return $content;
 }
 /**
  * Fill news attributes
  *
  * @param Content          $news
  * @param ContentAttribute $title
  * @param ContentAttribute $intro
  * @param ContentAttribute $text
  *
  * @return Content
  */
 protected function addNewsAttributes($news, $title, $intro, $text)
 {
     $news->addAttribute($title);
     $news->addAttribute($this->generateContentAttribute('publish_start', '2014-08-26', 'date'));
     $news->addAttribute($this->generateContentAttribute('publish_end', '2014-12-19', 'date'));
     $news->addAttribute($intro);
     $news->addAttribute($text);
     return $news;
 }
 /**
  * Fill news attributes
  *
  * @param Content          $news
  * @param ContentAttribute $title
  * @param ContentAttribute $start
  * @param ContentAttribute $end
  * @param ContentAttribute $intro
  * @param ContentAttribute $text
  *
  * @return Content
  */
 protected function addNewsAttributes($news, $title, $start, $end, $intro, $text)
 {
     $news->addAttribute($title);
     $news->addAttribute($start);
     $news->addAttribute($end);
     $news->addAttribute($intro);
     $news->addAttribute($text);
     return $news;
 }