Ejemplo n.º 1
0
 /**
  * Test related methods
  */
 public function testGetterSetter()
 {
     $this->assertEquals($this->version->getAuthor(), 'admin');
     $this->assertEquals($this->version->getResourceId(), 1);
     $this->assertEquals($this->version->getVersion(), 2);
     $this->assertEquals($this->version->getSnapshot(), ['field' => 'value']);
     $this->assertEquals($this->version->getChangeset(), ['field' => 'value']);
     $this->assertEquals($this->version->getContext(), 'foo');
 }
 function it_applies_on_timestampable_versioned_object_with_a_document_manager($registry, LifecycleEventArgs $args, DocumentManager $om, ODMUnitOfWork $uow, Version $version, TimestampableInterface $object, ODMClassMetadata $metadata)
 {
     $registry->getManagerForClass('bar')->willReturn($om);
     $om->getClassMetadata('bar')->willReturn($metadata);
     $metadata->getReflectionClass()->willReturn(new \ReflectionClass('Pim\\Component\\Catalog\\Model\\TimestampableInterface'));
     $version->getResourceId()->willReturn('foo');
     $version->getResourceName()->willReturn('bar');
     $version->getLoggedAt()->willReturn('foobar');
     $args->getObject()->willReturn($version);
     $om->getUnitOfWork()->willReturn($uow);
     $om->find('bar', 'foo')->willReturn($object);
     $uow->computeChangeSet($metadata, $object)->shouldBeCalled();
     $object->setUpdated('foobar')->shouldBeCalled();
     $this->prePersist($args);
 }
 function it_normalize_versions_with_deleted_user($userManager, $translator, Version $version, \DateTime $versionTime)
 {
     $version->getId()->willReturn(12);
     $version->getResourceId()->willReturn(112);
     $version->getSnapshot()->willReturn('a nice snapshot');
     $version->getChangeset()->willReturn('the changeset');
     $version->getContext()->willReturn(['locale' => 'en_US', 'channel' => 'mobile']);
     $version->getVersion()->willReturn(12);
     $version->getLoggedAt()->willReturn($versionTime);
     $versionTime->format('Y-m-d H:i:s')->willReturn('1985-10-1 09:41:00');
     $version->isPending()->willReturn(false);
     $version->getAuthor()->willReturn('steve');
     $userManager->findUserByUsername('steve')->willReturn(null);
     $translator->trans('Removed user')->willReturn('Utilisateur supprimé');
     $this->normalize($version, 'internal_api')->shouldReturn(['id' => 12, 'author' => 'steve - Utilisateur supprimé', 'resource_id' => '112', 'snapshot' => 'a nice snapshot', 'changeset' => 'the changeset', 'context' => ['locale' => 'en_US', 'channel' => 'mobile'], 'version' => 12, 'logged_at' => '1985-10-1 09:41:00', 'pending' => false]);
 }
 /**
  * {@inheritDoc}
  */
 public function getResourceId()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getResourceId', array());
     return parent::getResourceId();
 }
 /**
  * Build a pending version
  *
  * @param Version      $pending
  * @param Version|null $previousVersion
  *
  * @return Version
  */
 public function buildPendingVersion(Version $pending, Version $previousVersion = null)
 {
     if (null === $previousVersion) {
         $previousVersion = $this->getVersionRepository()->getNewestLogEntry($pending->getResourceName(), $pending->getResourceId());
     }
     return $this->versionBuilder->buildPendingVersion($pending, $previousVersion);
 }