Exemplo n.º 1
0
 /**
  * The Default user model does not have a listener bind to the updating and deleting model events.
  * However, when loading the blameable trait, the Observer should auto register itself for the model.
  */
 public function testObserverBind()
 {
     $model = new User();
     // Booting a normal model that does not include the Blameable trait
     $this->assertFalse($model->getEventDispatcher()->hasListeners('eloquent.creating: Culpa\\Tests\\Models\\User'));
     $this->assertFalse($model->getEventDispatcher()->hasListeners('eloquent.updating: Culpa\\Tests\\Models\\User'));
     $this->assertFalse($model->getEventDispatcher()->hasListeners('eloquent.deleting: Culpa\\Tests\\Models\\User'));
     $model = new FullyBlameableModel();
     // We will boot the model, Laravel invokes the bootBlameable() method which hooks our observer to the events
     $this->assertTrue($model->getEventDispatcher()->hasListeners('eloquent.creating: Culpa\\Tests\\Models\\FullyBlameableModel'));
     $this->assertTrue($model->getEventDispatcher()->hasListeners('eloquent.updating: Culpa\\Tests\\Models\\FullyBlameableModel'));
     $this->assertTrue($model->getEventDispatcher()->hasListeners('eloquent.deleting: Culpa\\Tests\\Models\\FullyBlameableModel'));
 }
Exemplo n.º 2
0
 public function testDelete()
 {
     $this->model->title = 'Hello, world!';
     $this->assertTrue($this->model->save());
     $this->model = FullyBlameableModel::find(1);
     $this->assertTrue($this->model->delete());
     // Reload the model
     $this->model = FullyBlameableModel::withTrashed()->find(1);
     // Check datetimes are being set properly for sanity's sake
     $this->assertNotNull($this->model->created_at);
     $this->assertGreaterThan($this->model->created_at, $this->model->updated_at);
     $this->assertNotNull($this->model->deleted_at);
     $this->assertEquals(1, $this->model->created_by);
     $this->assertEquals(1, $this->model->updated_by);
     $this->assertEquals(1, $this->model->deleted_by);
     $this->assertEquals(Auth::user()->name, $this->model->creator->name);
     $this->assertEquals(Auth::user()->name, $this->model->updater->name);
     $this->assertEquals(Auth::user()->name, $this->model->eraser->name);
 }