|
@@ -12,16 +12,33 @@ class SubjectTest extends TestCase
|
|
{
|
|
{
|
|
$app = $this->mockApplication();
|
|
$app = $this->mockApplication();
|
|
(new migrations\CreateSubjectTable)->up();
|
|
(new migrations\CreateSubjectTable)->up();
|
|
- (new Subject())->save();
|
|
|
|
- (new Subject())->save();
|
|
|
|
- (new Subject())->save();
|
|
|
|
|
|
+ (new Subject('CN=Alice,C=AT'))->save();
|
|
|
|
+ (new Subject('CN=Alice,O=Office,C=AT'))->save();
|
|
|
|
+ (new Subject('CN=Bob,C=AT'))->save();
|
|
$subjects = ArrayHelper::map(
|
|
$subjects = ArrayHelper::map(
|
|
Subject::find()->all(),
|
|
Subject::find()->all(),
|
|
function($s) { return $s->getAttributes(); }
|
|
function($s) { return $s->getAttributes(); }
|
|
);
|
|
);
|
|
$this->assertEquals(3, sizeof($subjects));
|
|
$this->assertEquals(3, sizeof($subjects));
|
|
- $this->assertContains(['id' => 1], $subjects);
|
|
|
|
- $this->assertContains(['id' => 2], $subjects);
|
|
|
|
- $this->assertContains(['id' => 3], $subjects);
|
|
|
|
|
|
+ ArrayHelper::map(
|
|
|
|
+ [['id' => 1, 'distinguished_name' => 'CN=Alice,C=AT'],
|
|
|
|
+ ['id' => 2, 'distinguished_name' => 'CN=Alice,O=Office,C=AT'],
|
|
|
|
+ ['id' => 3, 'distinguished_name' => 'CN=Bob,C=AT']],
|
|
|
|
+ function($a) use ($subjects) {
|
|
|
|
+ $this->assertContains($a, $subjects);
|
|
|
|
+ }
|
|
|
|
+ );
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public function testDNUnique()
|
|
|
|
+ {
|
|
|
|
+ $app = $this->mockApplication();
|
|
|
|
+ (new migrations\CreateSubjectTable)->up();
|
|
|
|
+ $this->assertTrue((new Subject('CN=Alice,C=AT'))->save());
|
|
|
|
+ $this->assertTrue((new Subject('CN=Bob,C=AT'))->save());
|
|
|
|
+ $dup = new Subject('CN=Alice,C=AT');
|
|
|
|
+ $this->assertFalse($dup->save());
|
|
|
|
+ $this->assertEquals(1, sizeof($dup->getErrors()));
|
|
|
|
+ $this->assertEquals(1, sizeof($dup->getErrors('distinguished_name')));
|
|
}
|
|
}
|
|
}
|
|
}
|