Best Cucumber Common Library code snippet using Rule.fromArray
LayoutResolverServiceTest.php
Source:LayoutResolverServiceTest.php
...45 ->expects(self::once())46 ->method('rollbackTransaction');47 $this->layoutResolverService->createRule(48 new RuleCreateStruct(),49 RuleGroup::fromArray(50 [51 'id' => Uuid::uuid4(),52 'status' => Value::STATUS_PUBLISHED,53 ],54 ),55 );56 }57 /**58 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::updateRule59 */60 public function testUpdateRule(): void61 {62 $this->expectException(Exception::class);63 $this->expectExceptionMessage('Test exception text');64 $this->layoutResolverHandler65 ->method('loadRule')66 ->willReturn(PersistenceRule::fromArray(['id' => 42]));67 $this->layoutResolverHandler68 ->method('updateRule')69 ->willThrowException(new Exception('Test exception text'));70 $this->transactionHandler71 ->expects(self::once())72 ->method('rollbackTransaction');73 $this->layoutResolverService->updateRule(74 Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]),75 new RuleUpdateStruct(),76 );77 }78 /**79 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::updateRuleMetadata80 */81 public function testUpdateRuleMetadata(): void82 {83 $this->expectException(Exception::class);84 $this->expectExceptionMessage('Test exception text');85 $this->layoutResolverHandler86 ->method('loadRule')87 ->willReturn(PersistenceRule::fromArray(['id' => 42]));88 $this->layoutResolverHandler89 ->method('updateRuleMetadata')90 ->willThrowException(new Exception('Test exception text'));91 $this->transactionHandler92 ->expects(self::once())93 ->method('rollbackTransaction');94 $this->layoutResolverService->updateRuleMetadata(95 Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_PUBLISHED]),96 new RuleMetadataUpdateStruct(),97 );98 }99 /**100 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::copyRule101 */102 public function testCopyRule(): void103 {104 $this->expectException(Exception::class);105 $this->expectExceptionMessage('Test exception text');106 $this->layoutResolverHandler107 ->method('loadRule')108 ->willReturn(PersistenceRule::fromArray(['id' => 42]));109 $this->layoutResolverHandler110 ->method('loadRuleGroup')111 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));112 $this->layoutResolverHandler113 ->method('copyRule')114 ->willThrowException(new Exception('Test exception text'));115 $this->transactionHandler116 ->expects(self::once())117 ->method('rollbackTransaction');118 $this->layoutResolverService->copyRule(119 Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Rule::STATUS_PUBLISHED]),120 RuleGroup::fromArray(121 [122 'id' => Uuid::uuid4(),123 'status' => Value::STATUS_PUBLISHED,124 ],125 ),126 );127 }128 /**129 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::moveRule130 */131 public function testMoveRule(): void132 {133 $this->expectException(Exception::class);134 $this->expectExceptionMessage('Test exception text');135 $this->layoutResolverHandler136 ->method('loadRule')137 ->willReturn(PersistenceRule::fromArray(['id' => 42]));138 $this->layoutResolverHandler139 ->method('loadRuleGroup')140 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));141 $this->layoutResolverHandler142 ->method('moveRule')143 ->willThrowException(new Exception('Test exception text'));144 $this->transactionHandler145 ->expects(self::once())146 ->method('rollbackTransaction');147 $this->layoutResolverService->moveRule(148 Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Rule::STATUS_PUBLISHED]),149 RuleGroup::fromArray(150 [151 'id' => Uuid::uuid4(),152 'status' => Value::STATUS_PUBLISHED,153 ],154 ),155 );156 }157 /**158 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::createDraft159 */160 public function testCreateDraft(): void161 {162 $this->expectException(Exception::class);163 $this->expectExceptionMessage('Test exception text');164 $this->layoutResolverHandler165 ->method('loadRule')166 ->willReturn(PersistenceRule::fromArray(['id' => 42]));167 $this->layoutResolverHandler168 ->method('ruleExists')169 ->willReturn(false);170 $this->layoutResolverHandler171 ->method('deleteRule')172 ->willThrowException(new Exception('Test exception text'));173 $this->transactionHandler174 ->expects(self::once())175 ->method('rollbackTransaction');176 $this->layoutResolverService->createDraft(Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_PUBLISHED]));177 }178 /**179 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::discardDraft180 */181 public function testDiscardDraft(): void182 {183 $this->expectException(Exception::class);184 $this->expectExceptionMessage('Test exception text');185 $this->layoutResolverHandler186 ->method('loadRule')187 ->willReturn(PersistenceRule::fromArray(['id' => 42]));188 $this->layoutResolverHandler189 ->method('deleteRule')190 ->willThrowException(new Exception('Test exception text'));191 $this->transactionHandler192 ->expects(self::once())193 ->method('rollbackTransaction');194 $this->layoutResolverService->discardDraft(Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]));195 }196 /**197 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::publishRule198 */199 public function testPublishRule(): void200 {201 $this->expectException(Exception::class);202 $this->expectExceptionMessage('Test exception text');203 $this->layoutResolverHandler204 ->method('loadRule')205 ->willReturn(PersistenceRule::fromArray(['id' => 42]));206 $this->layoutResolverHandler207 ->method('deleteRule')208 ->willThrowException(new Exception('Test exception text'));209 $this->transactionHandler210 ->expects(self::once())211 ->method('rollbackTransaction');212 $this->layoutResolverService->publishRule(Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]));213 }214 /**215 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::restoreFromArchive216 */217 public function testRestoreFromArchive(): void218 {219 $this->expectException(Exception::class);220 $this->expectExceptionMessage('Test exception text');221 $this->layoutResolverHandler222 ->method('loadRule')223 ->willReturn(PersistenceRule::fromArray(['id' => 42, 'status' => Value::STATUS_ARCHIVED]));224 $this->layoutResolverHandler225 ->method('loadRule')226 ->willReturn(PersistenceRule::fromArray(['id' => 42, 'status' => Value::STATUS_DRAFT]));227 $this->layoutResolverHandler228 ->method('deleteRule')229 ->willThrowException(new Exception('Test exception text'));230 $this->transactionHandler231 ->expects(self::once())232 ->method('rollbackTransaction');233 $this->layoutResolverService->restoreFromArchive(Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Rule::STATUS_ARCHIVED]));234 }235 /**236 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::deleteRule237 */238 public function testDeleteRule(): void239 {240 $this->expectException(Exception::class);241 $this->expectExceptionMessage('Test exception text');242 $this->layoutResolverHandler243 ->method('loadRule')244 ->willReturn(PersistenceRule::fromArray(['id' => 42]));245 $this->layoutResolverHandler246 ->method('deleteRule')247 ->willThrowException(new Exception('Test exception text'));248 $this->transactionHandler249 ->expects(self::once())250 ->method('rollbackTransaction');251 $this->layoutResolverService->deleteRule(Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Rule::STATUS_DRAFT]));252 }253 /**254 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::enableRule255 */256 public function testEnableRule(): void257 {258 $this->expectException(Exception::class);259 $this->expectExceptionMessage('Test exception text');260 $this->layoutResolverHandler261 ->method('loadRule')262 ->willReturn(263 PersistenceRule::fromArray(264 [265 'layoutUuid' => Uuid::uuid4()->toString(),266 'enabled' => false,267 ],268 ),269 );270 $this->layoutResolverHandler271 ->method('updateRuleMetadata')272 ->willThrowException(new Exception('Test exception text'));273 $this->transactionHandler274 ->expects(self::once())275 ->method('rollbackTransaction');276 $this->layoutResolverService->enableRule(Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_PUBLISHED]));277 }278 /**279 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::disableRule280 */281 public function testDisableRule(): void282 {283 $this->expectException(Exception::class);284 $this->expectExceptionMessage('Test exception text');285 $this->layoutResolverHandler286 ->method('loadRule')287 ->willReturn(288 PersistenceRule::fromArray(289 [290 'enabled' => true,291 ],292 ),293 );294 $this->layoutResolverHandler295 ->method('updateRuleMetadata')296 ->willThrowException(new Exception('Test exception text'));297 $this->transactionHandler298 ->expects(self::once())299 ->method('rollbackTransaction');300 $this->layoutResolverService->disableRule(Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_PUBLISHED]));301 }302 /**303 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::createRuleGroup304 */305 public function testCreateRuleGroup(): void306 {307 $this->expectException(Exception::class);308 $this->expectExceptionMessage('Test exception text');309 $this->layoutResolverHandler310 ->method('loadRuleGroup')311 ->willReturn(new PersistenceRuleGroup());312 $this->layoutResolverHandler313 ->method('createRuleGroup')314 ->willThrowException(new Exception('Test exception text'));315 $this->transactionHandler316 ->expects(self::once())317 ->method('rollbackTransaction');318 $createStruct = new RuleGroupCreateStruct();319 $createStruct->name = 'Test group';320 $this->layoutResolverService->createRuleGroup(321 $createStruct,322 RuleGroup::fromArray(323 [324 'id' => Uuid::uuid4(),325 'status' => Value::STATUS_PUBLISHED,326 ],327 ),328 );329 }330 /**331 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::updateRuleGroup332 */333 public function testUpdateRuleGroup(): void334 {335 $this->expectException(Exception::class);336 $this->expectExceptionMessage('Test exception text');337 $this->layoutResolverHandler338 ->method('loadRuleGroup')339 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));340 $this->layoutResolverHandler341 ->method('updateRuleGroup')342 ->willThrowException(new Exception('Test exception text'));343 $this->transactionHandler344 ->expects(self::once())345 ->method('rollbackTransaction');346 $this->layoutResolverService->updateRuleGroup(347 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]),348 new RuleGroupUpdateStruct(),349 );350 }351 /**352 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::updateRuleGroupMetadata353 */354 public function testUpdateRuleGroupMetadata(): void355 {356 $this->expectException(Exception::class);357 $this->expectExceptionMessage('Test exception text');358 $this->layoutResolverHandler359 ->method('loadRuleGroup')360 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));361 $this->layoutResolverHandler362 ->method('updateRuleGroupMetadata')363 ->willThrowException(new Exception('Test exception text'));364 $this->transactionHandler365 ->expects(self::once())366 ->method('rollbackTransaction');367 $this->layoutResolverService->updateRuleGroupMetadata(368 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_PUBLISHED]),369 new RuleGroupMetadataUpdateStruct(),370 );371 }372 /**373 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::copyRuleGroup374 */375 public function testCopyRuleGroup(): void376 {377 $this->expectException(Exception::class);378 $this->expectExceptionMessage('Test exception text');379 $this->layoutResolverHandler380 ->method('loadRuleGroup')381 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));382 $this->layoutResolverHandler383 ->method('copyRuleGroup')384 ->willThrowException(new Exception('Test exception text'));385 $this->transactionHandler386 ->expects(self::once())387 ->method('rollbackTransaction');388 $this->layoutResolverService->copyRuleGroup(389 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => RuleGroup::STATUS_PUBLISHED]),390 RuleGroup::fromArray(391 [392 'id' => Uuid::uuid4(),393 'status' => Value::STATUS_PUBLISHED,394 ],395 ),396 );397 }398 /**399 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::moveRuleGroup400 */401 public function testMoveRuleGroup(): void402 {403 $this->expectException(Exception::class);404 $this->expectExceptionMessage('Test exception text');405 $this->layoutResolverHandler406 ->method('loadRuleGroup')407 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));408 $this->layoutResolverHandler409 ->method('moveRuleGroup')410 ->willThrowException(new Exception('Test exception text'));411 $this->transactionHandler412 ->expects(self::once())413 ->method('rollbackTransaction');414 $this->layoutResolverService->moveRuleGroup(415 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => RuleGroup::STATUS_PUBLISHED]),416 RuleGroup::fromArray(417 [418 'id' => Uuid::uuid4(),419 'status' => Value::STATUS_PUBLISHED,420 ],421 ),422 );423 }424 /**425 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::createRuleGroupDraft426 */427 public function testCreateRuleGroupDraft(): void428 {429 $this->expectException(Exception::class);430 $this->expectExceptionMessage('Test exception text');431 $this->layoutResolverHandler432 ->method('loadRuleGroup')433 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));434 $this->layoutResolverHandler435 ->method('ruleGroupExists')436 ->willReturn(false);437 $this->layoutResolverHandler438 ->method('deleteRuleGroup')439 ->willThrowException(new Exception('Test exception text'));440 $this->transactionHandler441 ->expects(self::once())442 ->method('rollbackTransaction');443 $this->layoutResolverService->createRuleGroupDraft(444 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_PUBLISHED]),445 );446 }447 /**448 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::discardRuleGroupDraft449 */450 public function testDiscardRuleGroupDraft(): void451 {452 $this->expectException(Exception::class);453 $this->expectExceptionMessage('Test exception text');454 $this->layoutResolverHandler455 ->method('loadRuleGroup')456 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));457 $this->layoutResolverHandler458 ->method('deleteRuleGroup')459 ->willThrowException(new Exception('Test exception text'));460 $this->transactionHandler461 ->expects(self::once())462 ->method('rollbackTransaction');463 $this->layoutResolverService->discardRuleGroupDraft(464 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]),465 );466 }467 /**468 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::publishRuleGroup469 */470 public function testPublishRuleGroup(): void471 {472 $this->expectException(Exception::class);473 $this->expectExceptionMessage('Test exception text');474 $this->layoutResolverHandler475 ->method('loadRuleGroup')476 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));477 $this->layoutResolverHandler478 ->method('deleteRuleGroup')479 ->willThrowException(new Exception('Test exception text'));480 $this->transactionHandler481 ->expects(self::once())482 ->method('rollbackTransaction');483 $this->layoutResolverService->publishRuleGroup(484 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]),485 );486 }487 /**488 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::restoreRuleGroupFromArchive489 */490 public function testRestoreRuleGroupFromArchive(): void491 {492 $this->expectException(Exception::class);493 $this->expectExceptionMessage('Test exception text');494 $this->layoutResolverHandler495 ->method('loadRuleGroup')496 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42, 'status' => Value::STATUS_ARCHIVED]));497 $this->layoutResolverHandler498 ->method('loadRuleGroup')499 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42, 'status' => Value::STATUS_DRAFT]));500 $this->layoutResolverHandler501 ->method('deleteRuleGroup')502 ->willThrowException(new Exception('Test exception text'));503 $this->transactionHandler504 ->expects(self::once())505 ->method('rollbackTransaction');506 $this->layoutResolverService->restoreRuleGroupFromArchive(507 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => RuleGroup::STATUS_ARCHIVED]),508 );509 }510 /**511 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::deleteRuleGroup512 */513 public function testDeleteRuleGroup(): void514 {515 $this->expectException(Exception::class);516 $this->expectExceptionMessage('Test exception text');517 $this->layoutResolverHandler518 ->method('loadRuleGroup')519 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));520 $this->layoutResolverHandler521 ->method('deleteRuleGroup')522 ->willThrowException(new Exception('Test exception text'));523 $this->transactionHandler524 ->expects(self::once())525 ->method('rollbackTransaction');526 $this->layoutResolverService->deleteRuleGroup(527 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => RuleGroup::STATUS_DRAFT]),528 );529 }530 /**531 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::enableRuleGroup532 */533 public function testEnableRuleGroup(): void534 {535 $this->expectException(Exception::class);536 $this->expectExceptionMessage('Test exception text');537 $this->layoutResolverHandler538 ->method('loadRuleGroup')539 ->willReturn(540 PersistenceRuleGroup::fromArray(541 [542 'enabled' => false,543 ],544 ),545 );546 $this->layoutResolverHandler547 ->method('updateRuleGroupMetadata')548 ->willThrowException(new Exception('Test exception text'));549 $this->transactionHandler550 ->expects(self::once())551 ->method('rollbackTransaction');552 $this->layoutResolverService->enableRuleGroup(553 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_PUBLISHED]),554 );555 }556 /**557 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::disableRuleGroup558 */559 public function testDisableRuleGroup(): void560 {561 $this->expectException(Exception::class);562 $this->expectExceptionMessage('Test exception text');563 $this->layoutResolverHandler564 ->method('loadRuleGroup')565 ->willReturn(566 PersistenceRuleGroup::fromArray(567 [568 'enabled' => true,569 ],570 ),571 );572 $this->layoutResolverHandler573 ->method('updateRuleGroupMetadata')574 ->willThrowException(new Exception('Test exception text'));575 $this->transactionHandler576 ->expects(self::once())577 ->method('rollbackTransaction');578 $this->layoutResolverService->disableRuleGroup(579 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_PUBLISHED]),580 );581 }582 /**583 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::addTarget584 */585 public function testAddTarget(): void586 {587 $this->expectException(Exception::class);588 $this->expectExceptionMessage('Test exception text');589 $this->layoutResolverHandler590 ->method('loadRule')591 ->willReturn(PersistenceRule::fromArray(['id' => 42]));592 $this->layoutResolverHandler593 ->method('loadRuleTargets')594 ->willReturn([]);595 $this->layoutResolverHandler596 ->method('addTarget')597 ->willThrowException(new Exception('Test exception text'));598 $this->transactionHandler599 ->expects(self::once())600 ->method('rollbackTransaction');601 $targetCreateStruct = new TargetCreateStruct();602 $targetCreateStruct->type = 'route';603 $this->layoutResolverService->addTarget(604 Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]),605 $targetCreateStruct,606 );607 }608 /**609 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::updateTarget610 */611 public function testUpdateTarget(): void612 {613 $this->expectException(Exception::class);614 $this->expectExceptionMessage('Test exception text');615 $this->layoutResolverHandler616 ->method('loadTarget')617 ->willReturn(new PersistenceTarget());618 $this->layoutResolverHandler619 ->method('updateTarget')620 ->willThrowException(new Exception('Test exception text'));621 $this->transactionHandler622 ->expects(self::once())623 ->method('rollbackTransaction');624 $this->layoutResolverService->updateTarget(625 Target::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT, 'targetType' => new Route()]),626 new TargetUpdateStruct(),627 );628 }629 /**630 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::deleteTarget631 */632 public function testDeleteTarget(): void633 {634 $this->expectException(Exception::class);635 $this->expectExceptionMessage('Test exception text');636 $this->layoutResolverHandler637 ->method('loadTarget')638 ->willReturn(new PersistenceTarget());639 $this->layoutResolverHandler640 ->method('deleteTarget')641 ->willThrowException(new Exception('Test exception text'));642 $this->transactionHandler643 ->expects(self::once())644 ->method('rollbackTransaction');645 $this->layoutResolverService->deleteTarget(Target::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]));646 }647 /**648 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::addCondition649 */650 public function testAddCondition(): void651 {652 $this->expectException(Exception::class);653 $this->expectExceptionMessage('Test exception text');654 $this->layoutResolverHandler655 ->method('loadRule')656 ->willReturn(PersistenceRule::fromArray(['id' => 42]));657 $this->layoutResolverHandler658 ->method('addRuleCondition')659 ->willThrowException(new Exception('Test exception text'));660 $this->transactionHandler661 ->expects(self::once())662 ->method('rollbackTransaction');663 $conditionCreateStruct = new ConditionCreateStruct();664 $conditionCreateStruct->type = 'route_parameter';665 $this->layoutResolverService->addCondition(666 Rule::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]),667 $conditionCreateStruct,668 );669 }670 /**671 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::addRuleGroupCondition672 */673 public function testAddRuleGroupCondition(): void674 {675 $this->expectException(Exception::class);676 $this->expectExceptionMessage('Test exception text');677 $this->layoutResolverHandler678 ->method('loadRuleGroup')679 ->willReturn(PersistenceRuleGroup::fromArray(['id' => 42]));680 $this->layoutResolverHandler681 ->method('addRuleGroupCondition')682 ->willThrowException(new Exception('Test exception text'));683 $this->transactionHandler684 ->expects(self::once())685 ->method('rollbackTransaction');686 $conditionCreateStruct = new ConditionCreateStruct();687 $conditionCreateStruct->type = 'route_parameter';688 $this->layoutResolverService->addRuleGroupCondition(689 RuleGroup::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]),690 $conditionCreateStruct,691 );692 }693 /**694 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::updateCondition695 */696 public function testUpdateCondition(): void697 {698 $this->expectException(Exception::class);699 $this->expectExceptionMessage('Test exception text');700 $this->layoutResolverHandler701 ->method('loadRuleCondition')702 ->willReturn(new PersistenceRuleCondition());703 $this->layoutResolverHandler704 ->method('updateCondition')705 ->willThrowException(new Exception('Test exception text'));706 $this->transactionHandler707 ->expects(self::once())708 ->method('rollbackTransaction');709 $this->layoutResolverService->updateCondition(710 RuleCondition::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT, 'conditionType' => new RouteParameter()]),711 new ConditionUpdateStruct(),712 );713 }714 /**715 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::updateRuleGroupCondition716 */717 public function testUpdateRuleGroupCondition(): void718 {719 $this->expectException(Exception::class);720 $this->expectExceptionMessage('Test exception text');721 $this->layoutResolverHandler722 ->method('loadRuleGroupCondition')723 ->willReturn(new PersistenceRuleGroupCondition());724 $this->layoutResolverHandler725 ->method('updateCondition')726 ->willThrowException(new Exception('Test exception text'));727 $this->transactionHandler728 ->expects(self::once())729 ->method('rollbackTransaction');730 $this->layoutResolverService->updateRuleGroupCondition(731 RuleGroupCondition::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT, 'conditionType' => new RouteParameter()]),732 new ConditionUpdateStruct(),733 );734 }735 /**736 * @covers \Netgen\Layouts\Core\Service\LayoutResolverService::deleteCondition737 */738 public function testDeleteCondition(): void739 {740 $this->expectException(Exception::class);741 $this->expectExceptionMessage('Test exception text');742 $this->layoutResolverHandler743 ->method('loadRuleCondition')744 ->willReturn(new PersistenceRuleCondition());745 $this->layoutResolverHandler746 ->method('deleteCondition')747 ->willThrowException(new Exception('Test exception text'));748 $this->transactionHandler749 ->expects(self::once())750 ->method('rollbackTransaction');751 $this->layoutResolverService->deleteCondition(RuleCondition::fromArray(['id' => Uuid::uuid4(), 'status' => Value::STATUS_DRAFT]));752 }753}...
LayoutResolverTest.php
Source:LayoutResolverTest.php
...53 public function testResolveRules(): void54 {55 $this->targetTypeRegistry = new TargetTypeRegistry([new TargetType1(42), new TargetType2(84)]);56 $this->createLayoutResolver();57 $rule1 = Rule::fromArray(58 [59 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),60 'priority' => 2,61 'enabled' => true,62 'targets' => new ArrayCollection(),63 'conditions' => new ArrayCollection(),64 ],65 );66 $rule2 = Rule::fromArray(67 [68 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),69 'priority' => 4,70 'enabled' => true,71 'targets' => new ArrayCollection(),72 'conditions' => new ArrayCollection(),73 ],74 );75 $rule3 = Rule::fromArray(76 [77 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),78 'priority' => 5,79 'enabled' => true,80 'targets' => new ArrayCollection(),81 'conditions' => new ArrayCollection(),82 ],83 );84 $rule4 = Rule::fromArray(85 [86 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),87 'priority' => 4,88 'enabled' => true,89 'targets' => new ArrayCollection(),90 'conditions' => new ArrayCollection(),91 ],92 );93 $this->layoutResolverServiceMock94 ->method('matchRules')95 ->withConsecutive(96 [self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42)],97 [self::isInstanceOf(RuleGroup::class), self::identicalTo('target2'), self::identicalTo(84)],98 )99 ->willReturnOnConsecutiveCalls(100 new RuleList([$rule1, $rule2]),101 new RuleList([$rule3, $rule4]),102 );103 $resolvedRules = $this->layoutResolver->resolveRules($this->requestStack->getCurrentRequest());104 self::assertCount(4, $resolvedRules);105 // We can't be sure in what order two rules with same priority will be returned,106 // so just assert the first one and the last one107 self::assertSame($rule3, $resolvedRules[0]);108 self::assertSame($rule1, $resolvedRules[3]);109 }110 /**111 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules112 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules113 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRules114 */115 public function testResolveRulesWithInvalidRule(): void116 {117 $this->targetTypeRegistry = new TargetTypeRegistry([new TargetType1(42)]);118 $this->createLayoutResolver();119 $rule1 = Rule::fromArray(120 [121 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),122 'priority' => 2,123 'enabled' => true,124 'targets' => new ArrayCollection(),125 'conditions' => new ArrayCollection(),126 ],127 );128 $rule2 = Rule::fromArray(129 [130 'layout' => null,131 'priority' => 4,132 'enabled' => true,133 'targets' => new ArrayCollection(),134 'conditions' => new ArrayCollection(),135 ],136 );137 $this->layoutResolverServiceMock138 ->method('matchRules')139 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42))140 ->willReturn(new RuleList([$rule1, $rule2]));141 self::assertSame([$rule1], $this->layoutResolver->resolveRules($this->requestStack->getCurrentRequest()));142 }143 /**144 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules145 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules146 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRules147 */148 public function testResolveRulesWithDisabledRule(): void149 {150 $this->targetTypeRegistry = new TargetTypeRegistry([new TargetType1(42)]);151 $this->createLayoutResolver();152 $rule1 = Rule::fromArray(153 [154 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),155 'priority' => 2,156 'enabled' => true,157 'targets' => new ArrayCollection(),158 'conditions' => new ArrayCollection(),159 ],160 );161 $rule2 = Rule::fromArray(162 [163 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),164 'priority' => 4,165 'enabled' => false,166 'targets' => new ArrayCollection(),167 'conditions' => new ArrayCollection(),168 ],169 );170 $this->layoutResolverServiceMock171 ->method('matchRules')172 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42))173 ->willReturn(new RuleList([$rule1, $rule2]));174 self::assertSame([$rule1], $this->layoutResolver->resolveRules($this->requestStack->getCurrentRequest()));175 }176 /**177 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules178 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules179 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRules180 */181 public function testResolveRulesWithNoValidRules(): void182 {183 $this->targetTypeRegistry = new TargetTypeRegistry([new TargetType1(42)]);184 $this->createLayoutResolver();185 $rule1 = Rule::fromArray(186 [187 'layout' => null,188 'priority' => 2,189 'enabled' => true,190 'targets' => new ArrayCollection(),191 'conditions' => new ArrayCollection(),192 ],193 );194 $rule2 = Rule::fromArray(195 [196 'layout' => null,197 'priority' => 4,198 'enabled' => true,199 'targets' => new ArrayCollection(),200 'conditions' => new ArrayCollection(),201 ],202 );203 $this->layoutResolverServiceMock204 ->method('matchRules')205 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42))206 ->willReturn(new RuleList([$rule1, $rule2]));207 self::assertSame([], $this->layoutResolver->resolveRules($this->requestStack->getCurrentRequest()));208 }209 /**210 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules211 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules212 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRules213 */214 public function testResolveRulesWithNoTargetValue(): void215 {216 $this->targetTypeRegistry = new TargetTypeRegistry(217 [218 new TargetType1(),219 new TargetType2(84),220 ],221 );222 $this->createLayoutResolver();223 $rule1 = Rule::fromArray(224 [225 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),226 'priority' => 5,227 'enabled' => true,228 'targets' => new ArrayCollection(),229 'conditions' => new ArrayCollection(),230 ],231 );232 $rule2 = Rule::fromArray(233 [234 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),235 'priority' => 7,236 'enabled' => true,237 'targets' => new ArrayCollection(),238 'conditions' => new ArrayCollection(),239 ],240 );241 $this->layoutResolverServiceMock242 ->method('matchRules')243 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target2'), self::identicalTo(84))244 ->willReturn(new RuleList([$rule1, $rule2]));245 self::assertSame([$rule2, $rule1], $this->layoutResolver->resolveRules($this->requestStack->getCurrentRequest()));246 }247 /**248 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules249 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules250 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRules251 */252 public function testResolveRulesWithNoTargetValues(): void253 {254 $this->targetTypeRegistry = new TargetTypeRegistry(255 [256 new TargetType1(),257 new TargetType2(),258 ],259 );260 $this->createLayoutResolver();261 $this->layoutResolverServiceMock262 ->expects(self::never())263 ->method('matchRules');264 self::assertSame([], $this->layoutResolver->resolveRules($this->requestStack->getCurrentRequest()));265 }266 /**267 * @param string[] $conditionTypes268 *269 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::conditionsMatch270 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules271 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules272 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRules273 *274 * @dataProvider resolveRulesWithPartialRuleConditionsDataProvider275 */276 public function testResolveRulesWithConditionsAndPartialConditionMatching(array $conditionTypes, bool $resolved): void277 {278 $this->targetTypeRegistry = new TargetTypeRegistry([new TargetType1(42)]);279 $this->createLayoutResolver();280 $conditions = [];281 foreach ($conditionTypes as $conditionType) {282 $conditions[] = RuleCondition::fromArray(['conditionType' => $conditionType]);283 }284 $rule1 = Rule::fromArray(285 [286 'layout' => $resolved ? Layout::fromArray(['id' => Uuid::uuid4()]) : null,287 'enabled' => true,288 'targets' => new ArrayCollection(),289 'priority' => 4,290 'conditions' => new ArrayCollection([RuleCondition::fromArray(['conditionType' => new ConditionType2(false)])]),291 ],292 );293 $rule2 = Rule::fromArray(294 [295 'layout' => $resolved ? Layout::fromArray(['id' => Uuid::uuid4()]) : null,296 'enabled' => true,297 'targets' => new ArrayCollection(),298 'priority' => 2,299 'conditions' => new ArrayCollection($conditions),300 ],301 );302 $this->layoutResolverServiceMock303 ->expects(self::once())304 ->method('matchRules')305 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42))306 ->willReturn(new RuleList([$rule1, $rule2]));307 self::assertSame(308 $resolved ? [$rule2] : [],309 $this->layoutResolver->resolveRules($this->requestStack->getCurrentRequest(), ['condition2']),310 );311 }312 /**313 * @param string[] $conditionTypes314 *315 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::conditionsMatch316 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules317 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules318 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRules319 *320 * @dataProvider resolveRulesWithRuleConditionsDataProvider321 */322 public function testResolveRulesWithConditions(array $conditionTypes, bool $resolved): void323 {324 $this->targetTypeRegistry = new TargetTypeRegistry([new TargetType1(42)]);325 $this->createLayoutResolver();326 $conditions = [];327 foreach ($conditionTypes as $conditionType) {328 $conditions[] = RuleCondition::fromArray(['conditionType' => $conditionType]);329 }330 $rule = Rule::fromArray(331 [332 'layout' => $resolved ? Layout::fromArray(['id' => Uuid::uuid4()]) : null,333 'enabled' => true,334 'targets' => new ArrayCollection(),335 'conditions' => new ArrayCollection($conditions),336 ],337 );338 $this->layoutResolverServiceMock339 ->expects(self::once())340 ->method('matchRules')341 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42))342 ->willReturn(new RuleList([$rule]));343 self::assertSame(344 $resolved ? [$rule] : [],345 $this->layoutResolver->resolveRules($this->requestStack->getCurrentRequest()),346 );347 }348 /**349 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules350 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules351 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRule352 */353 public function testResolveRule(): void354 {355 $this->targetTypeRegistry = new TargetTypeRegistry(356 [357 new TargetType1(42),358 new TargetType2(84),359 ],360 );361 $this->createLayoutResolver();362 $rule1 = Rule::fromArray(363 [364 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),365 'priority' => 2,366 'enabled' => true,367 'targets' => new ArrayCollection(),368 'conditions' => new ArrayCollection(),369 ],370 );371 $rule2 = Rule::fromArray(372 [373 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),374 'priority' => 4,375 'enabled' => true,376 'targets' => new ArrayCollection(),377 'conditions' => new ArrayCollection(),378 ],379 );380 $rule3 = Rule::fromArray(381 [382 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),383 'priority' => 5,384 'enabled' => true,385 'targets' => new ArrayCollection(),386 'conditions' => new ArrayCollection(),387 ],388 );389 $rule4 = Rule::fromArray(390 [391 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),392 'priority' => 4,393 'enabled' => true,394 'targets' => new ArrayCollection(),395 'conditions' => new ArrayCollection(),396 ],397 );398 $this->layoutResolverServiceMock399 ->method('matchRules')400 ->withConsecutive(401 [self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42)],402 [self::isInstanceOf(RuleGroup::class), self::identicalTo('target2'), self::identicalTo(84)],403 )404 ->willReturnOnConsecutiveCalls(405 new RuleList([$rule1, $rule2]),406 new RuleList([$rule3, $rule4]),407 );408 self::assertSame($rule3, $this->layoutResolver->resolveRule($this->requestStack->getCurrentRequest()));409 }410 /**411 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules412 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules413 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRule414 */415 public function testResolveRuleWithInvalidRule(): void416 {417 $this->targetTypeRegistry = new TargetTypeRegistry([new TargetType1(42)]);418 $this->createLayoutResolver();419 $rule1 = Rule::fromArray(420 [421 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),422 'priority' => 2,423 'enabled' => true,424 'targets' => new ArrayCollection(),425 'conditions' => new ArrayCollection(),426 ],427 );428 $rule2 = Rule::fromArray(429 [430 'layout' => null,431 'priority' => 4,432 'enabled' => true,433 'targets' => new ArrayCollection(),434 'conditions' => new ArrayCollection(),435 ],436 );437 $this->layoutResolverServiceMock438 ->method('matchRules')439 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42))440 ->willReturn(new RuleList([$rule1, $rule2]));441 self::assertSame($rule1, $this->layoutResolver->resolveRule($this->requestStack->getCurrentRequest()));442 }443 /**444 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules445 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules446 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRule447 */448 public function testResolveRuleWithNoValidRules(): void449 {450 $this->targetTypeRegistry = new TargetTypeRegistry([new TargetType1(42)]);451 $this->createLayoutResolver();452 $rule1 = Rule::fromArray(453 [454 'layout' => null,455 'priority' => 2,456 'enabled' => true,457 'targets' => new ArrayCollection(),458 'conditions' => new ArrayCollection(),459 ],460 );461 $rule2 = Rule::fromArray(462 [463 'layout' => null,464 'priority' => 4,465 'enabled' => true,466 'targets' => new ArrayCollection(),467 'conditions' => new ArrayCollection(),468 ],469 );470 $this->layoutResolverServiceMock471 ->method('matchRules')472 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42))473 ->willReturn(new RuleList([$rule1, $rule2]));474 self::assertNull($this->layoutResolver->resolveRule($this->requestStack->getCurrentRequest()));475 }476 /**477 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules478 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules479 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRule480 */481 public function testResolveRuleWithNoTargetValue(): void482 {483 $this->targetTypeRegistry = new TargetTypeRegistry(484 [485 new TargetType1(),486 new TargetType2(84),487 ],488 );489 $this->createLayoutResolver();490 $rule1 = Rule::fromArray(491 [492 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),493 'priority' => 5,494 'enabled' => true,495 'targets' => new ArrayCollection(),496 'conditions' => new ArrayCollection(),497 ],498 );499 $rule2 = Rule::fromArray(500 [501 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),502 'priority' => 7,503 'enabled' => true,504 'targets' => new ArrayCollection(),505 'conditions' => new ArrayCollection(),506 ],507 );508 $this->layoutResolverServiceMock509 ->method('matchRules')510 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target2'), self::identicalTo(84))511 ->willReturn(new RuleList([$rule1, $rule2]));512 self::assertSame($rule2, $this->layoutResolver->resolveRule($this->requestStack->getCurrentRequest()));513 }514 /**515 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules516 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules517 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRule518 */519 public function testResolveRuleWithNoTargetValues(): void520 {521 $this->targetTypeRegistry = new TargetTypeRegistry(522 [523 new TargetType1(),524 new TargetType2(),525 ],526 );527 $this->createLayoutResolver();528 $this->layoutResolverServiceMock529 ->expects(self::never())530 ->method('matchRules');531 self::assertNull($this->layoutResolver->resolveRule($this->requestStack->getCurrentRequest()));532 }533 /**534 * @param string[] $conditionTypes535 *536 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::conditionsMatch537 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules538 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules539 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRule540 *541 * @dataProvider resolveRulesWithPartialRuleConditionsDataProvider542 */543 public function testResolveRuleWithConditionsAndPartialConditionMatching(array $conditionTypes, bool $resolved): void544 {545 $this->targetTypeRegistry = new TargetTypeRegistry([new TargetType1(42)]);546 $this->createLayoutResolver();547 $conditions = [];548 foreach ($conditionTypes as $conditionType) {549 $conditions[] = RuleCondition::fromArray(['conditionType' => $conditionType]);550 }551 $rule = Rule::fromArray(552 [553 'layout' => $resolved ? Layout::fromArray(['id' => Uuid::uuid4()]) : null,554 'enabled' => true,555 'targets' => new ArrayCollection(),556 'conditions' => new ArrayCollection($conditions),557 ],558 );559 $this->layoutResolverServiceMock560 ->expects(self::once())561 ->method('matchRules')562 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42))563 ->willReturn(new RuleList([$rule]));564 self::assertSame(565 $resolved ? $rule : null,566 $this->layoutResolver->resolveRule(567 $this->requestStack->getCurrentRequest(),568 ['condition2'],569 ),570 );571 }572 /**573 * @param string[] $conditionTypes574 *575 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::conditionsMatch576 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::innerResolveRules577 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveGroupRules578 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::resolveRule579 *580 * @dataProvider resolveRulesWithRuleConditionsDataProvider581 */582 public function testResolveRuleWithConditions(array $conditionTypes, bool $resolved): void583 {584 $this->targetTypeRegistry = new TargetTypeRegistry([new TargetType1(42)]);585 $this->createLayoutResolver();586 $conditions = [];587 foreach ($conditionTypes as $conditionType) {588 $conditions[] = RuleCondition::fromArray(['conditionType' => $conditionType]);589 }590 $rule = Rule::fromArray(591 [592 'layout' => $resolved ? Layout::fromArray(['id' => Uuid::uuid4()]) : null,593 'enabled' => true,594 'targets' => new ArrayCollection(),595 'conditions' => new ArrayCollection($conditions),596 ],597 );598 $this->layoutResolverServiceMock599 ->expects(self::once())600 ->method('matchRules')601 ->with(self::isInstanceOf(RuleGroup::class), self::identicalTo('target1'), self::identicalTo(42))602 ->willReturn(new RuleList([$rule]));603 self::assertSame($resolved ? $rule : null, $this->layoutResolver->resolveRule($this->requestStack->getCurrentRequest()));604 }605 /**606 * @param string[] $conditionTypes607 *608 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::conditionsMatch609 * @covers \Netgen\Layouts\Layout\Resolver\LayoutResolver::matches610 *611 * @dataProvider matchesDataProvider612 */613 public function testMatches(array $conditionTypes, bool $isMatch): void614 {615 $conditions = [];616 foreach ($conditionTypes as $conditionType) {617 $conditions[] = RuleCondition::fromArray(['conditionType' => $conditionType]);618 }619 $rule = Rule::fromArray(620 [621 'layout' => Layout::fromArray(['id' => Uuid::uuid4()]),622 'enabled' => true,623 'targets' => new ArrayCollection(),624 'conditions' => new ArrayCollection($conditions),625 ],626 );627 self::assertSame($isMatch, $this->layoutResolver->matches($rule, Request::create('/')));628 }629 public function resolveRulesWithRuleConditionsDataProvider(): array630 {631 return [632 [[], true],633 [[new ConditionType3(true)], true],634 [[new ConditionType3(false)], false],635 [[new ConditionType1(true), new ConditionType2(false)], false],...
ValidatorTest.php
Source:ValidatorTest.php
...23 public function testInValidation()24 {25 $validator = new Validator(['test']);26 27 $this->assertTrue($validator->validate(Context::fromArray(['test'])));28 $this->assertTrue($validator->validate(Context::fromArray(['test', 'smth'])));29 $this->assertFalse($validator->validate(Context::fromArray([])));30 $this->assertFalse($validator->validate(Context::fromArray(['smth'])));31 }32 public function testNotInValidation()33 {34 $validator = new Validator(['!test']);35 $this->assertFalse($validator->validate(Context::fromArray(['test'])));36 $this->assertFalse($validator->validate(Context::fromArray(['test', 'smth'])));37 $this->assertTrue($validator->validate(Context::fromArray([])));38 $this->assertTrue($validator->validate(Context::fromArray(['smth'])));39 }40 public function testInOneOfContextValidation()41 {42 $validator = new Validator(['*first', '*second']);43 $this->assertTrue($validator->validate(Context::fromArray(['first'])));44 $this->assertTrue($validator->validate(Context::fromArray(['second'])));45 $this->assertFalse($validator->validate(Context::fromArray([])));46 $this->assertFalse($validator->validate(Context::fromArray(['other'])));47 }48 public function testSubTokens()49 {50 $validator = new Validator(['token.test', '!token']);51 $this->assertTrue($validator->validate(Context::fromArray(['token.test'])));52 $this->assertTrue($validator->validate(Context::fromArray(['token.test.smth'])));53 $this->assertFalse($validator->validate(Context::fromArray(['token'])));54 }55 public function testRegex()56 {57 $validator = new Validator(['+~token\.[ab]']);58 $this->assertTrue($validator->validate(Context::fromArray(['token.a'])));59 $this->assertTrue($validator->validate(Context::fromArray(['token.b'])));60 $this->assertFalse($validator->validate(Context::fromArray(['token'])));61 }62 public function testNotInRegex()63 {64 $validator = new Validator(['!~token\.[ab]']);65 $this->assertFalse($validator->validate(Context::fromArray(['token.a'])));66 $this->assertFalse($validator->validate(Context::fromArray(['token.b'])));67 $this->assertTrue($validator->validate(Context::fromArray(['token'])));68 }69 public function testExactly()70 {71 $validator = new Validator(['+@token']);72 $this->assertFalse($validator->validate(Context::fromArray(['token.a'])));73 $this->assertFalse($validator->validate(Context::fromArray(['token.b'])));74 $this->assertTrue($validator->validate(Context::fromArray(['token'])));75 }76 public function testInAll()77 {78 $rule = Validator::everywhere();79 $this->assertTrue($rule->validate(Context::fromArray(['first'])));80 $this->assertTrue($rule->validate(Context::fromArray(['second'])));81 $this->assertTrue($rule->validate(Context::fromArray([])));82 $this->assertTrue($rule->validate(Context::fromArray(['other'])));83 }84 public function testInNone()85 {86 $rule = new Validator();87 $this->assertFalse($rule->validate(Context::fromArray(['first'])));88 $this->assertFalse($rule->validate(Context::fromArray(['second'])));89 $this->assertTrue($rule->validate(Context::fromArray([])));90 $this->assertFalse($rule->validate(Context::fromArray(['other'])));91 }92 public function testCallableValidator()93 {94 $validator = new DelegateValidator(function ($context) {95 return in_array('bar', $context->stack) && !in_array('foo', $context->stack);96 });97 $this->assertFalse($validator->validate(Context::fromArray(['test'])));98 $this->assertTrue($validator->validate(Context::fromArray(['bar'])));99 $this->assertTrue($validator->validate(Context::fromArray(['bar', 'smth'])));100 $this->assertFalse($validator->validate(Context::fromArray(['bar', 'foo'])));101 }102}...
fromArray
Using AI Code Generation
1$rule = new Rule();2$rule->fromArray($ruleArray);3$rule->save();4$rule = new Rule();5$rule->fromArray($ruleArray);6$rule->save();7$rule = new Rule();8$rule->fromArray($ruleArray);9$rule->save();10$rule = new Rule();11$rule->fromArray($ruleArray);12$rule->save();13$rule = new Rule();14$rule->fromArray($ruleArray);15$rule->save();16$rule = new Rule();17$rule->fromArray($ruleArray);18$rule->save();19$rule = new Rule();20$rule->fromArray($ruleArray);21$rule->save();22$rule = new Rule();23$rule->fromArray($ruleArray);24$rule->save();25$rule = new Rule();26$rule->fromArray($ruleArray);27$rule->save();28$rule = new Rule();29$rule->fromArray($ruleArray);30$rule->save();31$rule = new Rule();32$rule->fromArray($ruleArray);33$rule->save();34$rule = new Rule();35$rule->fromArray($ruleArray);36$rule->save();37$rule = new Rule();38$rule->fromArray($ruleArray);39$rule->save();
fromArray
Using AI Code Generation
1$myRule = new Rule();2$myRule->fromArray($myArray);3echo $myRule->toString();4$myRule = new Rule();5$myRule->fromString($myString);6echo $myRule->toString();7$myRule = new Rule();8$myRule->fromXML($myXML);9echo $myRule->toString();10$myRule = new Rule();11$myRule->fromJSON($myJSON);12echo $myRule->toString();13$myRule = new Rule();14$myRule->fromFile($myFilePath);15echo $myRule->toString();16$myRule = new Rule();17$myRule->fromString($myString);18echo $myRule->toString();19$myRule = new Rule();20$myRule->fromString($myString);21echo $myRule->toXML();22$myRule = new Rule();23$myRule->fromString($myString);24echo $myRule->toJSON();25$myRule = new Rule();26$myRule->fromString($myString);27$myRule->toFile($myFilePath);28$myRule = new Rule();29$myRule->fromString($myString);30echo $myRule->getRuleID();31$myRule = new Rule();32$myRule->fromString($myString);33$myRule->setRuleID($myRuleID);34$myRule = new Rule();35$myRule->fromString($myString);
fromArray
Using AI Code Generation
1$rule = new Rule();2$rule->fromArray([3]);4$rule->save();5$ruleCollection = new RuleCollection();6$ruleCollection->fromArray([7]);8$ruleCollection->save();9$action = new Action();10$action->fromArray([11]);12$action->save();13$actionCollection = new ActionCollection();14$actionCollection->fromArray([
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with fromArray on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!