/** * test set user * * @return void */ public function testSetUser() { $entity = new DocumentEntity(); $user = m::mock('Xpressengine\\Member\\Entities\\Database\\MemberEntity', 'Xpressengine\\Member\\Entities\\MemberEntityInterface'); $user->shouldReceive('getId')->andReturn('id'); $user->shouldReceive('getDisplayName')->andReturn('name'); /** @var \Xpressengine\Member\Entities\Database\MemberEntity $user */ $entity->setAuthor($user); $this->assertEquals('id', $entity->getAuthor()->getId()); $this->assertEquals('name', $entity->getAuthor()->getDisplayName()); $this->assertInstanceOf('\\Xpressengine\\Member\\Entities\\MemberEntityInterface', $entity->getAuthor()); }
/** * update document * * @param DocumentEntity $doc document entity * @return DocumentEntity */ public function put(DocumentEntity $doc) { $doc->setPureContent(); if ($doc->getAuthor() != null && $doc->getAuthor() instanceof Guest === false) { $doc->userId = $doc->getAuthor()->getId(); $doc->writer = $doc->getAuthor()->getDisplayName(); } $doc->updatedAt = date('Y-m-d H:i:s'); if ($doc->userId === null) { throw new Exceptions\RequiredValueException(); } if ($doc->instanceId === null) { throw new Exceptions\RequiredValueException(); } $doc = $this->rawPut($doc); $this->removeCache($doc); return $doc; }
/** * Returns author * * @return MemberEntityInterface */ public function getAuthor() { return $this->doc ? $this->doc->getAuthor() : new Guest(); }