Skip to content
Snippets Groups Projects
Commit 4e11d068 authored by Rajab Natshah's avatar Rajab Natshah
Browse files

Issue #3243594: Add new permissions to Site Admin user role to access "View...

Issue #3243594: Add new permissions to Site Admin user role to access "View JSON" and "View API Docs" entity operations
parent 14ca1d48
No related branches found
No related tags found
No related merge requests found
......@@ -52,6 +52,8 @@ permissions:
- "access varbase settings"
- "access varbase users reports"
- "access video_browser entity browser pages"
- "access view api docs entity operation"
- "access view json entity operation"
- "access webform overview"
- "add JS snippets for google analytics"
- "add terms in blog_categories"
......
......@@ -4,6 +4,8 @@ use WebDriver\Exception;
use Drupal\DrupalExtension\Context\RawDrupalContext;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Mink\Exception\ElementHtmlException;
use Behat\Mink\Element\Element;
use Behat\Gherkin\Node\TableNode;
/**
* Defines application features from the specific context.
......@@ -1654,6 +1656,73 @@ JS;
$this->getSession()->getPage()->find('xpath', '//*[contains(@class, "paragraphs-add-dialog") and contains(@class, "ui-dialog-content")]//*[contains(@name, "' . $value . '")]')->click();
}
/**
* Retrieve a table row containing specified entity with operations.
*
* @param \Behat\Mink\Element\Element
* @param string
* The text to search for in the table row.
*
* @return \Behat\Mink\Element\NodeElement
*
* @throws \Exception
*/
public function getEntityRow(Element $element, $search) {
$rows = $element->findAll('css', 'tr');
if (empty($rows)) {
throw new \Exception(sprintf('Entity not found on the page %s', $this->getSession()->getCurrentUrl()));
}
foreach ($rows as $row) {
if (strpos($row->getText(), $search) !== false) {
return $row;
}
}
throw new \Exception(sprintf('Failed to find an entity containing "%s" on the page %s', $search, $this->getSession()->getCurrentUrl()));
}
/**
* Check if an entity has a specific operation link.
*
* Varbase Context #varbase.
*
* Example 1: Then I should see the "Edit" operation for the "Homepage" entity
* Example 2: Then I should see "Layout" operation for the "Homepage"
* Example 3: Then see "Edit" operation for "Homepage"
* Example 4: Then should see "Delete" operation for the "Blog" entity
* Example 5: Then I should see "Clone" operation for the "Homepage" entity
*
* @Then /^(?:|I )(?:|should )see (?:|the )"([^"]*)" operation for the "([^"]*)" (?:|entity|content|media|file|term|user)$/
*/
public function iShouldSeetheOperationForTheEntity($operation, $entity) {
$row = $this->getEntityRow($this->getSession()->getPage(), $entity);
$operation_elment = $row->find('xpath',"//*[contains(@headers, 'view-operations-table-column')]//*[text()='{$operation}']");
if (empty($operation_elment)) {
throw new \Exception(sprintf('Found an entity containing "%s", but it did not have the operation "%s".', $entity, $operation));
}
}
/**
* Check if an entity not having a specific operation link.
*
* Varbase Context #varbase.
*
* Example 1: Then I should not see the "View API" operation for the "Homepage" entity
* Example 2: Then I should not see "View API Docs" operation for the "Homepage"
* Example 3: Then not see "Delete" operation for "Homepage"
* Example 4: Then should not see "Delete" operation for the "Blog" entity
* Example 5: Then I should not see "Clone" operation for the "Homepage" entity
*
* @Then /^(?:|I )(?:|should )not see (?:|the )"([^"]*)" operation for the "([^"]*)" (?:|entity|content|media|file|term|user)$/
*/
public function iShouldNotSeetheOperationForTheEntity($operation, $entity) {
$row = $this->getEntityRow($this->getSession()->getPage(), $entity);
$operation_elment = $row->find('xpath',"//*[contains(@headers, 'view-operations-table-column')]//*[text()='{$operation}']");
if (!empty($operation_elment)) {
throw new \Exception(sprintf('Found an entity containing "%s", but it have the operation "%s".', $entity, $operation));
}
}
/**
* Matching element exists on the page after a wait.
*
......
......@@ -52,3 +52,126 @@ So that I can use them to enable or disable API service for Varbase APIs.
Then I should see "OpenAPI Resources"
And I should see "Rest"
And I should see "JSON:API"
@local @development @staging @production
Scenario: Upload a Media entity test for API
Given I am a logged in user with the "test_site_admin" user
When I go to "/media/add/image"
And I wait
Then I should see "Allowed types: png gif jpg jpeg."
When I attach the file "flag-earth.jpg" to "edit-field-media-image-0-upload"
And I wait
And I press the "Save" button
And I wait
And I fill in "Media entity test" for "field_media_image[0][alt]"
And I fill in "Media entity test" for "field_media_image[0][title]"
And I fill in "Media entity test" for "name[0][value]"
And I press the "Save" button
And I wait
Then I should see "Media entity test"
@local @development @staging @production
Scenario: Add a term "space" tag term for JSON:API to test.
Given I am a logged in user with the "test_site_admin" user
When I go to "/admin/structure/taxonomy/manage/tags/add"
And I wait
Then I should see "Add term"
When I fill in "space" for "Name"
And I press the "Save" button
And I wait
And I go to "/admin/structure/taxonomy/manage/tags/overview"
Then I should see "Tags"
And I should see "space"
@javascript @check @local @development @staging @production
Scenario: Check that Site Admin users can access "View JSON" and "View API Docs" entity operations
Given I am a logged in user with the "test_site_admin" user
When I go to "/admin/content"
And I wait
Then I should see "Content"
And I should see the "View JSON" operation for the "Homepage" content
And I should see the "View API Docs" operation for the "Homepage" content
And I should see the "Edit" operation for the "Homepage" content
And I should see the "Layout" operation for the "Homepage" content
And I should see the "View JSON" operation for the "Blog" content
And I should see the "View API Docs" operation for the "Blog" content
When I go to "/admin/content/media"
And I wait
Then I should see "Media"
And I should see the "View JSON" operation for the "Media entity test" media
And I should see the "View API Docs" operation for the "Media entity test" media
And I should see the "Edit" operation for the "Media entity test" media
When I go to "/admin/structure/taxonomy/manage/tags/overview"
And I wait
Then I should see "Tags"
And I should see "space"
And I should not see the "View JSON" operation for the "space" term
And I should not see the "View API Docs" operation for the "space" term
When I go to "/admin/structure/entityqueue"
And I wait
Then I should see "Entityqueues"
And I should not see the "View JSON" operation for the "Media Hero Slider" entity
And I should not see the "View API Docs" operation for the "Media Hero Slider" entity
But I should not see the "Edit items" operation for the "Media Hero Slider" entity
@javascript @check @local @development @staging @production
Scenario: Check that Content Admin users can not access "View JSON" and "View API Docs" entity operations
Given I am a logged in user with the "test_content_admin" user
When I go to "/admin/content"
And I wait
Then I should see "Content"
And I should not see the "View JSON" operation for the "Homepage" content
And I should not see the "View API Docs" operation for the "Homepage" content
But I should see the "Edit" operation for the "Homepage" content
And I should see the "Layout" operation for the "Homepage" content
When I go to "/admin/content/media"
And I wait
Then I should see "Media"
And I should not see the "View JSON" operation for the "Media entity test" media
And I should not see the "View API Docs" operation for the "Media entity test" media
But I should see the "Edit" operation for the "Media entity test" media
When I go to "/admin/structure/taxonomy/manage/tags/overview"
And I wait
Then I should see "Tags"
And I should see "space"
And I should not see the "View JSON" operation for the "space" term
And I should not see the "View API Docs" operation for the "space" term
When I go to "/admin/structure/entityqueue"
And I wait
Then I should see "Entityqueues"
And I should not see the "View JSON" operation for the "Media Hero Slider" entity
And I should not see the "View API Docs" operation for the "Media Hero Slider" entity
But I should not see the "Edit items" operation for the "Media Hero Slider" entity
@javascript @check @local @development @staging @production
Scenario: Check that Editor users can access "View JSON" and "View API Docs" entity operations
Given I am a logged in user with the "test_editor" user
When I go to "/admin/content"
And I wait
Then I should see "Content"
And I should not see the "View JSON" operation for the "Homepage" content
And I should not see the "View API Docs" operation for the "Homepage" content
But I should see the "Edit" operation for the "Homepage" content
And I should see the "Layout" operation for the "Homepage" content
When I go to "/admin/content/media"
And I wait
Then I should see "Media"
And I should not see the "View JSON" operation for the "Media entity test" media
And I should not see the "View API Docs" operation for the "Media entity test" media
But I should see the "Edit" operation for the "Media entity test" media
When I go to "/admin/structure/taxonomy/manage/tags/overview"
And I wait
Then I should see "Tags"
And I should see "space"
And I should not see the "View JSON" operation for the "space" term
And I should not see the "View API Docs" operation for the "space" term
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment