|
| 1 | +<?php |
| 2 | + |
| 3 | +require __DIR__ . '/../../vendor/autoload.php'; |
| 4 | +use PHPUnit\Framework\TestCase; |
| 5 | + |
| 6 | +class MandatoryAttributesTest extends \Mockery\Adapter\Phpunit\MockeryTestCase |
| 7 | +{ |
| 8 | + private function getAttributesMap() |
| 9 | + { |
| 10 | + return array( |
| 11 | + 'firstname' => array('attribute' => 'givenname', 'mandatory' => array('all')), |
| 12 | + 'lastname' => array('attribute' => 'sn', 'mandatory' => array('create')), |
| 13 | + 'fullname' => array('attribute' => 'cn', 'mandatory' => array('update')), |
| 14 | + 'title' => array('attribute' => 'title'), |
| 15 | + ); |
| 16 | + } |
| 17 | + |
| 18 | + public function testCreateRequiresMandatoryValues() |
| 19 | + { |
| 20 | + $missing = (new \Ltb\Attributes)->findMissingMandatoryAttributes( |
| 21 | + 'create', |
| 22 | + $this->getAttributesMap(), |
| 23 | + array( |
| 24 | + 'givenname' => array('Alice'), |
| 25 | + 'cn' => 'Alice Doe', |
| 26 | + ) |
| 27 | + ); |
| 28 | + |
| 29 | + $this->assertSame(array('lastname'), $missing); |
| 30 | + } |
| 31 | + |
| 32 | + public function testCreateAcceptsMandatoryMacroValue() |
| 33 | + { |
| 34 | + $missing = (new \Ltb\Attributes)->findMissingMandatoryAttributes( |
| 35 | + 'create', |
| 36 | + $this->getAttributesMap(), |
| 37 | + array( |
| 38 | + 'givenname' => array('Alice'), |
| 39 | + 'sn' => 'Doe', |
| 40 | + ) |
| 41 | + ); |
| 42 | + |
| 43 | + $this->assertSame(array(), $missing); |
| 44 | + } |
| 45 | + |
| 46 | + public function testUpdateChecksOnlyProposedMandatoryAttributes() |
| 47 | + { |
| 48 | + $missing = (new \Ltb\Attributes)->findMissingMandatoryAttributes( |
| 49 | + 'update', |
| 50 | + $this->getAttributesMap(), |
| 51 | + array( |
| 52 | + 'givenname' => array(), |
| 53 | + 'cn' => array(), |
| 54 | + ), |
| 55 | + array('fullname') |
| 56 | + ); |
| 57 | + |
| 58 | + $this->assertSame(array('fullname'), $missing); |
| 59 | + } |
| 60 | + |
| 61 | + public function testUpdateIgnoresMandatoryAttributesNotProposedForChange() |
| 62 | + { |
| 63 | + $missing = (new \Ltb\Attributes)->findMissingMandatoryAttributes( |
| 64 | + 'update', |
| 65 | + $this->getAttributesMap(), |
| 66 | + array( |
| 67 | + 'givenname' => array(), |
| 68 | + 'cn' => array(), |
| 69 | + ), |
| 70 | + array('title') |
| 71 | + ); |
| 72 | + |
| 73 | + $this->assertSame(array(), $missing); |
| 74 | + } |
| 75 | +} |
0 commit comments