Ejemplo n.º 1
0
 public function testSerialization()
 {
     $data = json_decode(json_encode($this->writer), true);
     $this->assertInternalType('array', $data);
     $this->assertArrayHasKey('id', $data);
     $this->assertSame($this->writer->getId(), $data['id']);
     $this->assertArrayHasKey('type', $data);
     $this->assertSame(Writer::class, $data['type']);
     $this->assertArrayHasKey('name', $data);
     $this->assertSame($this->writer->getName(), $data['name']);
     $this->assertArrayHasKey('birthday', $data);
     $this->assertSame($this->writer->getBirthday()->getTimestamp(), $data['birthday']);
 }
Ejemplo n.º 2
0
 public function testCopyWithSave()
 {
     $writer_copy = $this->writer->copy(true);
     $this->assertInstanceOf(Writer::class, $writer_copy);
     $this->assertTrue($writer_copy->isLoaded());
     $this->assertNotEquals($this->writer->getId(), $writer_copy->getId());
     foreach ($writer_copy->getFields() as $field) {
         if ($writer_copy->isPrimaryKey($field)) {
             continue;
         }
         $old_writer_value = $this->writer->getFieldValue($field);
         $writer_copy_value = $writer_copy->getFieldValue($field);
         if ($old_writer_value instanceof DateValueInterface && $writer_copy_value instanceof DateValueInterface || $old_writer_value instanceof DateTimeValueInterface && $writer_copy_value instanceof DateTimeValueInterface) {
             $this->assertSame($old_writer_value->getTimestamp(), $writer_copy_value->getTimestamp());
         } else {
             $this->assertSame($old_writer_value, $writer_copy_value);
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Drop an existing type instance.
  *
  * @param  ServerRequestInterface         $request
  * @return EntityInterface|StatusResponse
  */
 public function delete(ServerRequestInterface $request)
 {
     if ($this->isReadOnly()) {
         return new NotFoundStatusResponse();
     }
     if ($this->active_object && $this->active_object->isLoaded()) {
         $authenticated_user = $this->getAuthenticatedUser($request);
         if ($this->shouldCheckPermissions() && !$this->canDelete($this->active_object, $authenticated_user)) {
             return new ForbiddenStatusResponse();
         }
         $this->active_object = $this->pool->scrap($this->active_object);
         if ($this->active_object->isNew()) {
             return ['single' => ['id' => $this->active_object->getId()]];
         } else {
             return $this->active_object;
         }
     } else {
         return new NotFoundStatusResponse();
     }
 }
Ejemplo n.º 4
0
 public function testPassWhenLoadedObjectsMatch()
 {
     $this->assertTrue($this->writer->is($this->pool->reload(Writer::class, $this->writer->getId())));
 }