public function test_model_hidden_fields() { $model = new RealModelStub(['myField' => 'value', 'anotherField' => 'yeah', 'someField' => 'whatever', 'hiddenField' => 'secrets!', 'passwordHash' => '1234']); $modelArray = $model->toArray(); $this->assertFalse(isset($modelArray['hiddenField'])); $this->assertFalse(isset($modelArray['passwordHash'])); $this->assertEquals('secrets!', $model->getAttribute('hiddenField')); $this->assertEquals('1234', $model->getAttribute('passwordHash')); }
public function testModelExposesHiddenFields() { $model = new RealModelStub(['myField' => 'value', 'anotherField' => 'yeah', 'someField' => 'whatever', 'hiddenField' => 'secrets!', 'passwordHash' => '1234']); $hidden = $model->withHidden(['hiddenField', 'passwordHash'])->toArray(); $this->assertTrue(isset($hidden['hiddenField'])); $this->assertTrue(isset($hidden['passwordHash'])); $this->assertEquals('secrets!', $hidden['hiddenField']); $this->assertEquals('1234', $hidden['passwordHash']); }