Skip to content

Commit

Permalink
Merge branch 'main' into community-standards
Browse files Browse the repository at this point in the history
  • Loading branch information
JakubKermes authored Aug 12, 2024
2 parents 6d878c8 + 2386d05 commit bbd50ab
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/elements/hooks.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,4 @@
</code-block>

</article-paragraphs>

57 changes: 57 additions & 0 deletions src/Features/Traits/Common.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

declare(strict_types=1);

namespace Blumilk\BLT\Features\Traits;

use Behat\Gherkin\Node\TableNode;
use Blumilk\BLT\Features\Traits\Optional\SpatiePermission;
use Symfony\Component\HttpFoundation\Response;

trait Common
{
use Eloquent;
use SpatiePermission;
use Authentication;
use Http;

/**
* @Given user is in session as admin
* @Given user in session has role :role
*/
public function sessionHasUserWithRole(string $role = "admin"): void
{
$roleArray = [
["name", $role],
];
$roleTable = new TableNode($roleArray);
$this->seedModelInTheDatabase("Role", $roleTable);
$userArray = [
["name", $role],
["email", "[email protected]"],
["password", "password123!@#"],
];
$userTable = new TableNode($userArray);
$this->seedModelInTheDatabase("User", $userTable);

$this->assignRoleTo($role, "User", "[email protected]", "email");

$this->userIsAuthenticatedInSessionAs($role, "name");
}

/**
* @Given admin user is getting OK response from :url
* @Given admin user is getting :status status code response from :url
* @Given user with :role role is getting OK response from :url
* @Given user with :role role is getting :status response from :url
* @Given user with :role role is getting OK response from :url using :method method
* @Given user with :role role is getting :status response from :url using :method method
*/
public function adminUserIsGettingResponse(string $url, string $method = "GET", int $status = Response::HTTP_OK, string $role = "admin"): void
{
$this->sessionHasUserWithRole($role);
$this->aUserIsRequesting($url, $method);
$this->aRequestIsSent();
$this->aResponseShouldHaveStatus($status);
}
}

0 comments on commit bbd50ab

Please sign in to comment.