-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the ability to add images to an existing album via the stream pag…
…e form.
- Loading branch information
Showing
4 changed files
with
156 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
<?php | ||
|
||
namespace Drupal\social\Behat; | ||
|
||
use Behat\Behat\Hook\Scope\BeforeScenarioScope; | ||
use Behat\Gherkin\Node\TableNode; | ||
use Behat\Mink\Exception\ElementNotFoundException; | ||
use Behat\MinkExtension\Context\RawMinkContext; | ||
use Drupal\DrupalExtension\Context\MinkContext; | ||
|
||
/** | ||
* Defines test steps around the usage of albums. | ||
*/ | ||
class AlbumContext extends RawMinkContext { | ||
|
||
use NodeTrait; | ||
use GroupTrait; | ||
|
||
private const CREATE_PAGE = "/node/add/album"; | ||
|
||
/** | ||
* Keep track of what we created, so we can use them for validating. | ||
*/ | ||
private array $created = []; | ||
|
||
/** | ||
* The Drupal mink context is useful for validation of content. | ||
*/ | ||
private MinkContext $minkContext; | ||
|
||
/** | ||
* Make some contexts available here so we can delegate steps. | ||
* | ||
* @BeforeScenario | ||
*/ | ||
public function gatherContexts(BeforeScenarioScope $scope) { | ||
$environment = $scope->getEnvironment(); | ||
|
||
$this->minkContext = $environment->getContext(SocialMinkContext::class); | ||
} | ||
|
||
/** | ||
* Check that an album that was just created is properly shown. | ||
* | ||
* @Then /^(?:|I )should see the album I just created$/ | ||
*/ | ||
public function thenIShouldSeeTheAlbumIJustCreated() : void { | ||
$fields = end($this->created); | ||
|
||
$this->minkContext->assertPageContainsText("Album {$fields['title']} is successfully created. Now you can add images to this album."); | ||
} | ||
|
||
/** | ||
* Fill out the album creation form and submit. | ||
* | ||
* Example: When I create an album using its creation page: | ||
* | Title | My Album | | ||
* | visibility | public | | ||
* | group | My group | | ||
* | ||
* @When /^(?:|I )create an album using its creation page:$/ | ||
*/ | ||
public function whenICreateAnAlbumUsingTheForm(TableNode $fields): void { | ||
// Go to the form. | ||
$this->visitPath(self::CREATE_PAGE); | ||
$page = $this->getSession()->getPage(); | ||
|
||
// Fill in the fields. | ||
$album = []; | ||
foreach ($fields->getRowsHash() as $field => $value) { | ||
$key = strtolower($field); | ||
$album[$key] = $value; | ||
// We must be more specific for the title field since there could be more | ||
// than one on the page (e.g. the menu title). | ||
if ($key === "title") { | ||
$fieldset = $page | ||
->find("named", ["fieldset", "Basic information"]); | ||
|
||
if ($fieldset === NULL) { | ||
throw new ElementNotFoundException($this->getSession()->getDriver(), "fieldset", "named", "Basic Information"); | ||
} | ||
|
||
$fieldset->fillField($field, $value); | ||
} | ||
elseif ($key === "group") { | ||
$group_id = $this->getNewestGroupIdFromTitle($value); | ||
if ($group_id === NULL) { | ||
throw new \Exception("Group '${$value}' does not exist."); | ||
} | ||
$page->selectFieldOption($field, $group_id); | ||
// Changing the group of an album updates the visibility settings so we | ||
// must wait for that to be complete. | ||
$this->minkContext->iWaitForAjaxToFinish(); | ||
} | ||
elseif ($key === "visibility") { | ||
$page->selectFieldOption("field_content_visibility", $value); | ||
} | ||
else { | ||
$page->fillField($field, $value); | ||
} | ||
|
||
// Changing the group of an album updates the visibility settings so we must | ||
// wait for that to be complete. | ||
if ($key === "group") { | ||
$this->minkContext->iWaitForAjaxToFinish(); | ||
} | ||
} | ||
|
||
// Submit the page. | ||
$page->pressButton("Create album"); | ||
|
||
$this->created[] = $album; | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
tests/behat/features/capabilities/post/post-album-existing.feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
@api @post @stability @PROD-25398 @database @stability-3 @album @post-album | ||
Feature: Create Post with Photo and add it to an existing Album | ||
Benefit: In order to share knowledge with people | ||
Role: As a Verified | ||
Goal/desire: I want to create Posts with photo and add it to the existing album. | ||
|
||
Scenario: Successfully add an image to the album via the stream post form | ||
|
||
Given I enable the module "social_album" | ||
Given users: | ||
| name | status | pass | roles | | ||
| PostUser | 1 | PostUser | verified | | ||
And I am logged in as "PostUser" | ||
|
||
When I create an album using its creation page: | ||
| Title | This is my first album. | | ||
Then I should see the album I just created | ||
|
||
Given I am on "/stream" | ||
Then I should see "Add images" | ||
And I should see "This is my first album." in the ".field--name-field-album" element |