From de51649d63efc3a8092a909a79e9316054fd81a9 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Sun, 28 Oct 2018 20:28:29 +0100 Subject: [PATCH] In between commit refactoring and implementing tests --- .../src/Entity/Attribut/BlacklistAttribut.php | 24 ---------- .../Attribut/BlacklistAttributInterface.php | 13 ------ .../src/Entity/Attribut/ChildsAttribut.php | 3 +- .../src/Entity/Attribut/ParentsAttribut.php | 3 +- .../Attribut/PlainPasswordAttribute.php | 29 ------------ .../src/Entity/Attribut/WhitelistAttribut.php | 24 ---------- .../Attribut/WhitelistAttributInterface.php | 13 ------ application/src/Entity/Meta/Law.php | 11 +---- application/src/Entity/Meta/LawInterface.php | 2 +- application/src/Entity/Meta/RecieverGroup.php | 2 +- application/src/Entity/Meta/Relation.php | 4 +- application/src/Entity/Meta/Right.php | 2 +- .../src/Entity/Source/AbstractSource.php | 25 +++++++++-- application/src/Entity/Source/GroupSource.php | 2 +- application/src/Entity/Source/NameSource.php | 2 +- .../src/Entity/Source/SourceInterface.php | 3 +- application/src/Entity/Source/UserSource.php | 2 +- application/src/Entity/User.php | 6 ++- .../Security/Source/UserSourceFacade.php | 19 +++++++- .../unit/Entity/Source/AbstractSourceTest.php | 44 +++++++++++++++++++ application/tests/unit/Entity/UserTest.php | 20 +++------ 21 files changed, 105 insertions(+), 148 deletions(-) delete mode 100644 application/src/Entity/Attribut/BlacklistAttribut.php delete mode 100644 application/src/Entity/Attribut/BlacklistAttributInterface.php delete mode 100644 application/src/Entity/Attribut/PlainPasswordAttribute.php delete mode 100644 application/src/Entity/Attribut/WhitelistAttribut.php delete mode 100644 application/src/Entity/Attribut/WhitelistAttributInterface.php create mode 100644 application/tests/unit/Entity/Source/AbstractSourceTest.php diff --git a/application/src/Entity/Attribut/BlacklistAttribut.php b/application/src/Entity/Attribut/BlacklistAttribut.php deleted file mode 100644 index eafad7f..0000000 --- a/application/src/Entity/Attribut/BlacklistAttribut.php +++ /dev/null @@ -1,24 +0,0 @@ -blacklist = $value; - } - - public function getBlacklist(): ?bool - { - return $this->blacklist; - } -} diff --git a/application/src/Entity/Attribut/BlacklistAttributInterface.php b/application/src/Entity/Attribut/BlacklistAttributInterface.php deleted file mode 100644 index 1ca7497..0000000 --- a/application/src/Entity/Attribut/BlacklistAttributInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -plainPassword; - } - - public function setPlainPassword(string $password): void - { - $this->plainPassword = $password; - } -} diff --git a/application/src/Entity/Attribut/WhitelistAttribut.php b/application/src/Entity/Attribut/WhitelistAttribut.php deleted file mode 100644 index 2331de0..0000000 --- a/application/src/Entity/Attribut/WhitelistAttribut.php +++ /dev/null @@ -1,24 +0,0 @@ -whitelist = $value; - } - - public function getWhitelist(): ?bool - { - return $this->whitelist; - } -} diff --git a/application/src/Entity/Attribut/WhitelistAttributInterface.php b/application/src/Entity/Attribut/WhitelistAttributInterface.php deleted file mode 100644 index 66067f6..0000000 --- a/application/src/Entity/Attribut/WhitelistAttributInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -initAllRights(); diff --git a/application/src/Entity/Meta/LawInterface.php b/application/src/Entity/Meta/LawInterface.php index 2f02b96..b96b3ca 100644 --- a/application/src/Entity/Meta/LawInterface.php +++ b/application/src/Entity/Meta/LawInterface.php @@ -9,6 +9,6 @@ use App\Entity\Method\RelationGrantedInterface; /** * @author kevinfrantz */ -interface LawInterface extends RightsAttributInterface, RelationGrantedInterface, RelationAttributInterface,MetaInterface +interface LawInterface extends RightsAttributInterface, RelationGrantedInterface, MetaInterface { } diff --git a/application/src/Entity/Meta/RecieverGroup.php b/application/src/Entity/Meta/RecieverGroup.php index a1eed1d..453300f 100644 --- a/application/src/Entity/Meta/RecieverGroup.php +++ b/application/src/Entity/Meta/RecieverGroup.php @@ -16,7 +16,7 @@ use App\Entity\Attribut\RelationAttributInterface; * @ORM\Table(name="meta_reciever_group") * @ORM\Entity() */ -class RecieverGroup extends AbstractMeta implements RecieverGroupInterface +final class RecieverGroup extends AbstractMeta implements RecieverGroupInterface { use RelationAttribut,RecieverAttribut; diff --git a/application/src/Entity/Meta/Relation.php b/application/src/Entity/Meta/Relation.php index 9e40b23..84fc8d4 100644 --- a/application/src/Entity/Meta/Relation.php +++ b/application/src/Entity/Meta/Relation.php @@ -21,7 +21,7 @@ use Doctrine\Common\Collections\Collection; * @ORM\Table(name="meta_relation") * @ORM\Entity() */ -class Relation extends AbstractMeta implements RelationInterface +final class Relation extends AbstractMeta implements RelationInterface { use IdAttribut, SourceAttribut, @@ -76,6 +76,6 @@ class Relation extends AbstractMeta implements RelationInterface $this->law = new Law(); $this->parents = new ArrayCollection(); $this->childs = new ArrayCollection(); - $this->law->setNode($this); + //$this->law->setNode($this); } } diff --git a/application/src/Entity/Meta/Right.php b/application/src/Entity/Meta/Right.php index 845e384..d78b574 100644 --- a/application/src/Entity/Meta/Right.php +++ b/application/src/Entity/Meta/Right.php @@ -20,7 +20,7 @@ use App\Entity\Attribut\RelationAttribut; * @ORM\Table(name="meta_right") * @ORM\Entity(repositoryClass="App\Repository\RightRepository") */ -class Right extends AbstractMeta implements RightInterface +final class Right extends AbstractMeta implements RightInterface { use TypeAttribut,LawAttribut, RelationAttribut, GrantAttribut,ConditionAttribut,RecieverGroupAttribut,LayerAttribut; diff --git a/application/src/Entity/Source/AbstractSource.php b/application/src/Entity/Source/AbstractSource.php index 4b859da..80dfbd8 100644 --- a/application/src/Entity/Source/AbstractSource.php +++ b/application/src/Entity/Source/AbstractSource.php @@ -1,5 +1,4 @@ relation = new Relation(); $this->relation->setSource($this); + $this->law = new Law(); + $this->groups = new ArrayCollection(); } } diff --git a/application/src/Entity/Source/GroupSource.php b/application/src/Entity/Source/GroupSource.php index ac23307..1096a83 100644 --- a/application/src/Entity/Source/GroupSource.php +++ b/application/src/Entity/Source/GroupSource.php @@ -12,7 +12,7 @@ use App\Entity\Source\Attribut\MembersAttribut; * @ORM\Table(name="source_group") * @ORM\Entity */ -class GroupSource extends AbstractSource implements MembersAttributInterface +final class GroupSource extends AbstractSource implements MembersAttributInterface { use MembersAttribut; diff --git a/application/src/Entity/Source/NameSource.php b/application/src/Entity/Source/NameSource.php index f4bbe99..38dfbf7 100644 --- a/application/src/Entity/Source/NameSource.php +++ b/application/src/Entity/Source/NameSource.php @@ -12,7 +12,7 @@ use App\Entity\Source\NameSourceInterface; * @ORM\Table(name="source_name") * @ORM\Entity(repositoryClass="App\Repository\NameSourceRepository") */ -class NameSource extends AbstractSource implements NameSourceInterface +final class NameSource extends AbstractSource implements NameSourceInterface { use NameAttribut; diff --git a/application/src/Entity/Source/SourceInterface.php b/application/src/Entity/Source/SourceInterface.php index 2327bc8..3008418 100644 --- a/application/src/Entity/Source/SourceInterface.php +++ b/application/src/Entity/Source/SourceInterface.php @@ -4,11 +4,12 @@ namespace App\Entity\Source; use App\Entity\Attribut\IdAttributInterface; use App\Entity\EntityInterface; use App\Entity\Source\Attribut\GroupSourcesAttributInterface; +use App\Entity\Attribut\LawAttributInterface; /** * * @author kevinfrantz */ -interface SourceInterface extends IdAttributInterface, EntityInterface, GroupSourcesAttributInterface +interface SourceInterface extends IdAttributInterface, EntityInterface, GroupSourcesAttributInterface, LawAttributInterface { } diff --git a/application/src/Entity/Source/UserSource.php b/application/src/Entity/Source/UserSource.php index eb9c88e..8ea7a6f 100644 --- a/application/src/Entity/Source/UserSource.php +++ b/application/src/Entity/Source/UserSource.php @@ -13,7 +13,7 @@ use App\Entity\UserInterface; * @ORM\Table(name="source_user") * @ORM\Entity(repositoryClass="App\Repository\UserSourceRepository") */ -class UserSource extends AbstractSource implements UserSourceInterface +final class UserSource extends AbstractSource implements UserSourceInterface { use UserAttribut,NameSourceAttribut; diff --git a/application/src/Entity/User.php b/application/src/Entity/User.php index 12fd8a4..3fcfd79 100644 --- a/application/src/Entity/User.php +++ b/application/src/Entity/User.php @@ -46,12 +46,14 @@ class User extends BaseUser implements UserInterface */ protected $version; + /** + * @todo Initialize all needed attributs + */ public function __construct() { parent::__construct(); $this->isActive = true; $this->source = new UserSource(); - LawModificator::grantAllRights($this->source->getNode()->getLaw(), $this->source->getNode()); - //var_dump($this->source->getNode()->getLaw()->getRights()->get(0)); + //LawModificator::grantAllRights($this->source->getNode()->getLaw(), $this->source->getNode()); } } diff --git a/application/src/Structur/Facade/Security/Source/UserSourceFacade.php b/application/src/Structur/Facade/Security/Source/UserSourceFacade.php index 1bc1910..0dfeb31 100644 --- a/application/src/Structur/Facade/Security/Source/UserSourceFacade.php +++ b/application/src/Structur/Facade/Security/Source/UserSourceFacade.php @@ -1,6 +1,7 @@ source = new class extends \App\Entity\Source\AbstractSource{}; + $this->source->setId(self::ID); + } + + public function testId(){ + $this->assertEquals($this->source->getId(),self::ID); + } + + public function testLaw(){ + $this->assertInstanceOf(LawInterface::class,$this->source->getLaw()); + } + + public function testRelation(){ + $this->assertInstanceOf(RelationInterface::class,$this->source->getRelation()); + } + + public function testGroups(){ + $this->assertInstanceOf(Collection::class,$this->source->getGroupSources()); + } +} + diff --git a/application/tests/unit/Entity/UserTest.php b/application/tests/unit/Entity/UserTest.php index 5b2f5d8..f8869fa 100644 --- a/application/tests/unit/Entity/UserTest.php +++ b/application/tests/unit/Entity/UserTest.php @@ -4,9 +4,8 @@ namespace tests\unit\Entity; use PHPUnit\Framework\TestCase; use App\Entity\User; -use App\Entity\Meta\Law; -use App\Entity\Meta\Relation; use App\Entity\Source\UserSource; +use App\Entity\UserInterface; /** * @author kevinfrantz @@ -19,24 +18,25 @@ class UserTest extends TestCase const USERNAME = 'tester'; /** - * @var User + * @var UserInterface */ protected $user; public function setUp(): void { $this->user = new User(); + $this->user->setUsername(self::USERNAME); + $this->user->setPassword(self::PASSWORD); + } public function testUsername(): void { - $this->user->setUsername(self::USERNAME); $this->assertEquals(self::USERNAME, $this->user->getUsername()); } public function testPassword(): void { - $this->user->setPassword(self::PASSWORD); $this->assertEquals(self::PASSWORD, $this->user->getPassword()); } @@ -44,14 +44,4 @@ class UserTest extends TestCase { $this->assertInstanceOf(UserSource::class, $this->user->getSource()); } - - public function testNode(): void - { - $this->assertInstanceOf(Relation::class, $this->user->getSource()->getNode()); - } - - public function testLaw(): void - { - $this->assertInstanceOf(Law::class, $this->user->getSource()->getNode()->getLaw()); - } }