예제 #1
0
 public function testGetRelationValue()
 {
     Model::unguard();
     $author = Author::create(['name' => 'Stevie']);
     $event = EventLog::make(['action' => "user-created", 'related_id' => $author->id, 'related_type' => get_class($author)]);
     Model::reguard();
     $this->assertEquals([$author->id, get_class($author)], $event->getRelationValue('related'));
 }
예제 #2
0
 public function testSetRelationValue()
 {
     Model::unguard();
     $author = Author::create(['name' => 'Stevie', 'email' => '*****@*****.**']);
     $event1 = EventLog::create(['action' => "user-created"]);
     $event2 = EventLog::create(['action' => "user-updated"]);
     $event3 = EventLog::create(['action' => "user-deleted"]);
     $event4 = EventLog::make(['action' => "user-restored"]);
     Model::reguard();
     // Set by Model object
     $author->event_log = new Collection([$event1, $event2]);
     $author->save();
     $this->assertEquals($author->id, $event1->related_id);
     $this->assertEquals($author->id, $event2->related_id);
     $this->assertEquals('Database\\Tester\\Models\\Author', $event1->related_type);
     $this->assertEquals('Database\\Tester\\Models\\Author', $event2->related_type);
     $this->assertEquals(['user-created', 'user-updated'], $author->event_log->lists('action'));
     // Set by primary key
     $eventId = $event3->id;
     $author->event_log = $eventId;
     $author->save();
     $event3 = EventLog::find($eventId);
     $this->assertEquals($author->id, $event3->related_id);
     $this->assertEquals('Database\\Tester\\Models\\Author', $event3->related_type);
     $this->assertEquals(['user-deleted'], $author->event_log->lists('action'));
     // Nullify
     $author->event_log = null;
     $author->save();
     $event3 = EventLog::find($eventId);
     $this->assertNull($event3->related_type);
     $this->assertNull($event3->related_id);
     $this->assertNull($event3->related);
     // Deferred in memory
     $author->event_log = $event4;
     $this->assertEquals($author->id, $event4->related_id);
     $this->assertEquals('Database\\Tester\\Models\\Author', $event4->related_type);
     $this->assertEquals(['user-restored'], $author->event_log->lists('action'));
 }