diff --git a/tests/Unit/Models/ModelTest.php b/tests/Unit/Models/ModelTest.php index 28a2e084..5d0f82ff 100644 --- a/tests/Unit/Models/ModelTest.php +++ b/tests/Unit/Models/ModelTest.php @@ -11,6 +11,8 @@ use LdapRecord\Models\BatchModification; use LdapRecord\Models\Entry; use LdapRecord\Models\Model; +use LdapRecord\Testing\DirectoryFake; +use LdapRecord\Testing\LdapFake; use LdapRecord\Tests\TestCase; class ModelTest extends TestCase @@ -729,19 +731,32 @@ public function test_generated_dns_are_properly_escaped() $this->assertEquals('cn=John\5c\2c\3d\2b\3c\3e\3b\5c\23Doe,dc=local,dc=com', $model->getCreatableDn()); } - public function test_generated_dns_properly_substitute_base() + public function test_generated_dns_properly_substitute_base_on_creation() { Container::addConnection(new Connection([ 'base_dn' => 'dc=local,dc=com', ])); + DirectoryFake::setup()->getLdapConnection()->expect( + LdapFake::operation('add') + ->once() + ->with( + 'cn=foo,dc=local,dc=com', + ['cn' => ['foo'], 'objectclass' => ['bar']] + ) + ->andReturnTrue() + ); + $model = new Entry(); $model->inside('{base}'); $model->cn = 'foo'; + $model->objectclass = ['bar']; + + $model->save(); - $this->assertEquals('cn=foo,dc=local,dc=com', $model->getCreatableDn()); + $this->assertEquals('cn=foo,dc=local,dc=com', $model->getDn()); } public function test_setting_dn_attributes_set_distinguished_name_on_model()