Changeset View
Changeset View
Standalone View
Standalone View
src/tests/Unit/Rules/SharedFolderNameTest.php
Show All 17 Lines | public function testValidation(): void | ||||
// Empty/invalid input | // Empty/invalid input | ||||
$v = Validator::make(['name' => null], $rules); | $v = Validator::make(['name' => null], $rules); | ||||
$this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | $this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | ||||
$v = Validator::make(['name' => []], $rules); | $v = Validator::make(['name' => []], $rules); | ||||
$this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | $this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | ||||
$v = Validator::make(['name' => ['Resources']], $rules); | |||||
$this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | |||||
$v = Validator::make(['name' => ['Resources/Test']], $rules); | |||||
$this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | |||||
// Forbidden chars | // Forbidden chars | ||||
$v = Validator::make(['name' => 'Test@'], $rules); | $v = Validator::make(['name' => 'Test@'], $rules); | ||||
$this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | $this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | ||||
// Length limit | // Length limit | ||||
$v = Validator::make(['name' => str_repeat('a', 192)], $rules); | $v = Validator::make(['name' => str_repeat('a', 192)], $rules); | ||||
$this->assertSame(['name' => ["The name may not be greater than 191 characters."]], $v->errors()->toArray()); | $this->assertSame(['name' => ["The name may not be greater than 191 characters."]], $v->errors()->toArray()); | ||||
// Existing resource | // Existing resource | ||||
$v = Validator::make(['name' => 'Calendar'], $rules); | $v = Validator::make(['name' => 'Calendar'], $rules); | ||||
$this->assertSame(['name' => ["The specified name is not available."]], $v->errors()->toArray()); | $this->assertSame(['name' => ["The specified name is not available."]], $v->errors()->toArray()); | ||||
// Valid name | // Valid name | ||||
$v = Validator::make(['name' => 'TestRule'], $rules); | $v = Validator::make(['name' => 'TestRule'], $rules); | ||||
$this->assertSame([], $v->errors()->toArray()); | $this->assertSame([], $v->errors()->toArray()); | ||||
// Invalid domain | // Invalid domain | ||||
$rules = ['name' => ['present', new SharedFolderName($user, 'kolabnow.com')]]; | $rules = ['name' => ['present', new SharedFolderName($user, 'kolabnow.com')]]; | ||||
$v = Validator::make(['name' => 'TestRule'], $rules); | $v = Validator::make(['name' => 'TestRule'], $rules); | ||||
$this->assertSame(['name' => ["The specified domain is invalid."]], $v->errors()->toArray()); | $this->assertSame(['name' => ["The specified domain is invalid."]], $v->errors()->toArray()); | ||||
// Invalid subfolders | |||||
$rules = ['name' => ['present', new SharedFolderName($user, 'kolab.org')]]; | |||||
$v = Validator::make(['name' => 'Test//Rule'], $rules); | |||||
$this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | |||||
$v = Validator::make(['name' => '/TestRule'], $rules); | |||||
$this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | |||||
$v = Validator::make(['name' => 'TestRule/'], $rules); | |||||
$this->assertSame(['name' => ["The specified name is invalid."]], $v->errors()->toArray()); | |||||
// Valid subfolder | |||||
$v = Validator::make(['name' => 'Test/Rule/Folder'], $rules); | |||||
$this->assertSame([], $v->errors()->toArray()); | |||||
} | } | ||||
} | } |