Ejemplo n.º 1
0
 public function testCopyWithoutSave()
 {
     $writer_copy = $this->writer->copy();
     $this->assertInstanceOf(Writer::class, $writer_copy);
     $this->assertFalse($writer_copy->isLoaded());
     $this->assertEmpty($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.º 2
0
 /**
  * Add object to the pool.
  *
  * @param EntityInterface $object
  */
 public function remember(EntityInterface &$object)
 {
     if ($object->isLoaded()) {
         $this->addToObjectPool($this->requireRegisteredType(get_class($object)), $object->getId(), $object);
     } else {
         throw new InvalidArgumentException('Object needs to be saved in the database to be remembered');
     }
 }
 public function testRevetField()
 {
     $started_with = $this->writer->getName();
     $this->assertFalse($this->writer->isModified());
     $this->assertFalse($this->writer->isModifiedField('name'));
     $this->writer->setName('Lew Nikolajewitsch Tolstoi');
     $this->assertTrue($this->writer->isModified());
     $this->assertTrue($this->writer->isModifiedField('name'));
     $this->writer->revertField('name');
     $this->assertTrue($this->writer->isModified());
     $this->assertTrue($this->writer->isModifiedField('name'));
     $this->assertSame($started_with, $this->writer->getName());
 }
Ejemplo n.º 4
0
 /**
  * @param  EntityInterface $object
  * @param  UserInterface   $user
  * @return bool
  */
 protected function canDelete(EntityInterface $object, UserInterface $user = null)
 {
     if ($user && $user->getId()) {
         if ($object instanceof PermissionsInterface) {
             return $object->canDelete($user);
         }
         return true;
     }
     return true;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function &scrap(EntityInterface &$instance, $force_delete = false)
 {
     if (!$force_delete && $instance instanceof ScrapInterface) {
         return $instance->scrap();
     } else {
         return $instance->delete();
     }
 }
Ejemplo n.º 6
0
 public function testExtendedSerializationIsEmptyByDefault()
 {
     $this->assertInternalType('array', $this->writer->jsonSerializeDetails());
     $this->assertEmpty($this->writer->jsonSerializeDetails());
 }
Ejemplo n.º 7
0
 public function testPassWhenLoadedObjectsMatch()
 {
     $this->assertTrue($this->writer->is($this->pool->reload(Writer::class, $this->writer->getId())));
 }