/** * @test */ public function notifiesObserversOfNewlyAddedRules() { $mockObserver = $this->getMock('PHPAccessControl\\Rule\\RuleListObserver'); $mockObserver->expects($this->once())->method('notifyRuleAdded')->with($this->equalTo(CreateRule::allow(Situation::UserViewPost()))); $this->ruleList->addObserver($mockObserver); $this->ruleList->addRule(CreateRule::allow(Situation::UserViewPost())); }
/** * @test */ public function mostSpecificMatchingRulesAreTheOnesWithMoreGeneralSituationIfNoneWithSameSituation() { // given $rule = CreateRule::allow(Situation::UserViewPost()); $this->ruleList->addRule($rule); // when $mostSpecificMatchingRules = $this->ruleFinder->findMostSpecificMatchingRulesFor(Situation::UserViewPostWithCategoryIdEquals5()); // then $this->assertEquals(array($rule), $mostSpecificMatchingRules); }
/** * @test */ public function canDetermineIfItAppliesToASpecification() { $rule = new SituationBasedRule(Situation::UserViewPost(), true); $this->assertTrue($rule->appliesTo(Situation::UserViewPostWithCategoryIdEquals5())); $this->assertTrue($rule->appliesTo(Situation::UserViewPostWithWordCountGreaterThan100())); }
/** * @test */ public function allowedWinsFromDenied() { $this->rules->addRule(CreateRule::deny(Situation::userViewPost())); $this->rules->addRule(CreateRule::allow(Situation::userViewPost())); $this->assertTrue($this->permissionResolver->isAllowedByInheritance(Situation::userViewPost())); }
/** * @test */ public function isSpecialCaseOfSituationIfSubjectAndObjectAreSpecialCasesAndTheActionIsTheSame() { $this->assertTrue(Situation::UserViewPostWithCategoryIdEquals5()->isSpecialCaseOf(Situation::UserViewPost())); $this->assertFalse(Situation::UserViewPost()->isSpecialCaseOf(Situation::UserViewPostWithCategoryIdEquals5())); }