Skip to content
Snippets Groups Projects
Commit 37c32a66 authored by Adam G-H's avatar Adam G-H
Browse files

Do not depend on Lightning Page in tests.

parent fa53609c
No related branches found
No related tags found
No related merge requests found
......@@ -6,3 +6,4 @@
/drush.yml export-ignore
/phpunit.xml export-ignore
/settings.local.php export-ignore
/*.sh export-ignore
......@@ -15,10 +15,12 @@
"oomphinc/composer-installers-extender": "^1.1"
},
"require-dev": {
"drupal/drupal-extension": "^3.4",
"drupal/inline_entity_form": "^1.0",
"drupal/schema_metatag": "^1.3",
"webflo/drupal-core-require-dev": "*",
"webmozart/assert": "^1.3"
"webmozart/assert": "^1.3",
"weitzman/drupal-test-traits": "^1.2"
},
"config": {
"preferred-install": {
......@@ -84,13 +86,6 @@
"@drupal-scaffold"
],
"drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
"install-drupal": [
"rm -r -f ./docroot/sites/default/settings.php",
"drush site:install minimal --yes --config ./drush.yml",
"chmod +w ./docroot/sites/default ./docroot/sites/default/settings.php",
"drush pm:enable lightning_workflow lightning_scheduler --yes",
"cp -f phpunit.xml ./docroot/core"
],
"nuke": "rm -r -f docroot vendor",
"pull": "cp -R -f ./docroot/modules/contrib/lightning_workflow/* .",
"push": [
......
......@@ -3,4 +3,3 @@ commands:
install:
options:
account-pass: admin
db-url: 'sqlite://db.sqlite'
#!/usr/bin/env bash
SITE_DIR=$(pwd)/docroot/sites/default
SETTINGS=$SITE_DIR/settings.php
DB_URL=${DB_URL:-sqlite://db.sqlite}
# Delete previous settings.
if [[ -f $SETTINGS ]]; then
chmod +w $SITE_DIR $SETTINGS
rm $SETTINGS
fi
# Install Drupal.
drush site:install minimal --yes --config ./drush.yml --account-pass admin --db-url $DB_URL
# Install sub-components.
drush pm-enable lightning_workflow lightning_scheduler --yes
# Make settings writable.
chmod +w $SITE_DIR $SETTINGS
# Copy development settings into the site directory.
cp settings.local.php $SITE_DIR
# Add Acquia Cloud subscription info to settings.php.
echo "if (file_exists('/var/www/site-php')) {" >> $SETTINGS
echo " require '/var/www/site-php/workflownightly/workflownightly-settings.inc';" >> $SETTINGS
echo " \$settings['install_profile'] = 'standard';" >> $SETTINGS
echo "}" >> $SETTINGS
echo "else {" >> $SETTINGS
echo " require __DIR__ . '/settings.local.php';" >> $SETTINGS
echo "}" >> $SETTINGS
# Copy PHPUnit configuration into core directory.
cp -f phpunit.xml ./docroot/core
#!/usr/bin/env bash
BRANCH=$(git rev-parse --abbrev-ref HEAD)
if [[ $BRANCH != release/* ]]; then
echo "Fixtures can only be generated on branches of the format 'release/n.n.n'."
exit
fi
VERSION=${BRANCH#release/}
./install-drupal.sh
# Destroy the database.
drush sql:drop --yes
# Import the fixture from which to update.
cd docroot
php core/scripts/db-tools.php import ../tests/fixtures/$FROM.php.gz
cd ..
# Run updates.
drush updatedb --yes
drush update:lightning --no-interaction
# Export the database.
cd docroot
php core/scripts/db-tools.php dump-database-d8-mysql --schema-only='' | gzip -9 > ../tests/fixtures/$VERSION.php.gz
cd ..
......@@ -3,8 +3,8 @@ Feature: Scheduling transitions on content
@368f0045 @javascript
Scenario: Automatically publishing, then unpublishing, in the future
Given I am logged in as a user with the "create page content, view own unpublished content, edit own page content, use editorial transition create_new_draft, use editorial transition review, use editorial transition publish, use editorial transition archive, schedule editorial transition publish, schedule editorial transition archive, view latest version, administer nodes" permissions
When I visit "/node/add/page"
Given I am logged in as a user with the "create test content, view own unpublished content, edit own test content, use editorial transition create_new_draft, use editorial transition review, use editorial transition publish, use editorial transition archive, schedule editorial transition publish, schedule editorial transition archive, view latest version, administer nodes" permissions
When I visit "/node/add/test"
And I enter "Schedule This" for "Title"
And I schedule a transition to Published in 10 seconds
And I schedule a transition to Archived in 20 seconds
......
......@@ -4,7 +4,7 @@ Feature: Moderated content
content.
Background:
Given page content:
Given test content:
| title | moderation_state | promote |
| Alpha | review | 1 |
| Beta | published | 1 |
......@@ -12,7 +12,7 @@ Feature: Moderated content
@03ebc3ee @orca_public
Scenario: Publishing moderated content
Given I am logged in as a user with the "access content overview, view any unpublished content, use editorial transition review, use editorial transition publish, create page content, edit any page content, create url aliases" permissions
Given I am logged in as a user with the "access content overview, view any unpublished content, use editorial transition review, use editorial transition publish, create test content, edit any test content, create url aliases" permissions
When I visit "/admin/content"
And I click "Alpha"
And I visit the edit form
......@@ -24,7 +24,7 @@ Feature: Moderated content
@c0c17d43 @orca_public
Scenario: Unpublishing moderated content
Given I am logged in as a user with the "access content overview, use editorial transition publish, use editorial transition archive, create page content, edit any page content, create url aliases" permissions
Given I am logged in as a user with the "access content overview, use editorial transition publish, use editorial transition archive, create test content, edit any test content, create url aliases" permissions
And I visit "/admin/content"
And I click "Beta"
And I visit the edit form
......
......@@ -4,7 +4,7 @@ Feature: Diffing different revisions of content
@5b4ba63e @with-module:diff
Scenario: Diffing two node revisions
Given I am logged in as an administrator
And page content:
And test content:
| title | body | moderation_state |
| Pastafazoul | First revision | draft |
When I visit "/admin/content"
......
......@@ -3,6 +3,6 @@ Feature: A sidebar for moderating content
@1d83813d @javascript @with-module:toolbar @with-module:moderation_sidebar
Scenario: Moderating content using the sidebar
Given I am logged in as a page_reviewer
When I am viewing a page in the Draft state
Given I am logged in as a test_reviewer
When I am viewing a test in the Draft state
Then I should be able to transition to the Published state without leaving the page
......@@ -3,8 +3,8 @@ Feature: Integration of workflows with Quick Edit
@f2beeeda @javascript @with-module:quickedit @orca_public
Scenario: Quick Edit should be available for unpublished content
Given I am logged in as a user with the "access in-place editing, access contextual links, use editorial transition create_new_draft, view any unpublished content, edit any page content" permissions
And page content:
Given I am logged in as a user with the "access in-place editing, access contextual links, use editorial transition create_new_draft, view any unpublished content, edit any test content" permissions
And test content:
| title | path | moderation_state |
| Foobar | /foobar | draft |
When I visit "/foobar"
......
......@@ -4,6 +4,7 @@ namespace Drupal\Tests\lightning_workflow\ExistingSite;
use Drupal\Tests\lightning_workflow\FixtureContext;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\workflows\Entity\Workflow;
use weitzman\DrupalTestTraits\ExistingSiteBase;
/**
......@@ -21,13 +22,6 @@ class ContentTypeModerationTest extends ExistingSiteBase {
*/
private $fixtureContext;
/**
* The content type created during the test.
*
* @var \Drupal\node\NodeTypeInterface
*/
private $nodeType;
/**
* {@inheritdoc}
*/
......@@ -45,14 +39,12 @@ class ContentTypeModerationTest extends ExistingSiteBase {
$this->fixtureContext = new FixtureContext($this->container);
$this->fixtureContext->setUp();
drupal_flush_all_caches();
$this->nodeType = $this->createContentType();
}
/**
* {@inheritdoc}
*/
public function tearDown() {
$this->nodeType->delete();
$this->fixtureContext->tearDown();
parent::tearDown();
}
......@@ -61,16 +53,17 @@ class ContentTypeModerationTest extends ExistingSiteBase {
* Tests access to unpublished content.
*/
public function testUnpublishedAccess() {
$this->enableModeration();
$assert_session = $this->assertSession();
$this->createNode([
'type' => $this->nodeType->id(),
'type' => 'test',
'title' => 'Moderation Test 1',
'promote' => TRUE,
'moderation_state' => 'review',
]);
$this->drupalGet('');
$this->assertSession()->linkNotExists('Moderation Test 1');
$this->visit('/');
$assert_session->statusCodeEquals(200);
$assert_session->linkNotExists('Moderation Test 1');
$account = $this->createUser([
'access content overview',
......@@ -78,40 +71,41 @@ class ContentTypeModerationTest extends ExistingSiteBase {
]);
$this->drupalLogin($account);
$this->drupalGet('/admin/content');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->elementExists('named', ['link', 'Moderation Test 1'])->click();
$this->assertSession()->statusCodeEquals(200);
$assert_session->statusCodeEquals(200);
$this->getSession()->getPage()->clickLink('Moderation Test 1');
$assert_session->statusCodeEquals(200);
}
public function testReviewerAccess() {
$this->enableModeration();
$assert_session = $this->assertSession();
$this->createNode([
'type' => $this->nodeType->id(),
'type' => 'test',
'title' => 'Version 1',
'moderation_state' => 'draft',
]);
$account = $this->createUser();
$account->addRole('page_reviewer');
$account->addRole('test_reviewer');
$account->save();
$this->drupalLogin($account);
$this->drupalGet('/admin/content');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->elementExists('named', ['link', 'Version 1'])->click();
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->pageTextContains('Version 1');
$assert_session->statusCodeEquals(200);
$this->getSession()->getPage()->clickLink('Version 1');
$assert_session->statusCodeEquals(200);
$assert_session->pageTextContains('Version 1');
}
/**
* @depends testReviewerAccess
*/
public function testLatestUnpublishedRevisionReviewerAccess() {
$this->enableModeration();
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$this->createNode([
'type' => $this->nodeType->id(),
'type' => 'test',
'title' => 'Version 1',
'moderation_state' => 'draft',
]);
......@@ -120,72 +114,80 @@ class ContentTypeModerationTest extends ExistingSiteBase {
$this->drupalLogin($account);
$this->drupalGet('/admin/content');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->elementExists('named', ['link', 'Version 1'])->click();
$this->assertSession()->elementExists('css', 'a[rel="edit-form"]')->click();
$this->assertSession()->fieldExists('Title')->setValue('Version 2');
$this->assertSession()->selectExists('moderation_state[0][state]')->selectOption('published');
$this->assertSession()->buttonExists('Save')->press();
$this->assertSession()->elementExists('css', 'a[rel="edit-form"]')->click();
$this->assertSession()->fieldExists('Title')->setValue('Version 3');
$this->assertSession()->selectExists('moderation_state[0][state]')->selectOption('draft');
$this->assertSession()->buttonExists('Save')->press();
$assert_session->statusCodeEquals(200);
$page->clickLink('Version 1');
$assert_session->elementExists('css', 'a[rel="edit-form"]')->click();
$page->fillField('Title', 'Version 2');
$page->selectFieldOption('moderation_state[0][state]', 'published');
$page->pressButton('Save');
$assert_session->elementExists('css', 'a[rel="edit-form"]')->click();
$page->fillField('Title', 'Version 3');
$page->selectFieldOption('moderation_state[0][state]', 'draft');
$page->pressButton('Save');
$this->drupalLogout();
$account = $this->createUser();
$account->addRole('page_reviewer');
$account->addRole('test_reviewer');
$account->save();
$this->drupalLogin($account);
$this->drupalGet('/admin/content');
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->elementExists('named', ['link', 'Version 2'])->click();
$this->assertSession()->statusCodeEquals(200);
$this->assertSession()->elementExists('named', ['link', 'Latest version']);
$assert_session->statusCodeEquals(200);
$page->clickLink('Version 2');
$assert_session->statusCodeEquals(200);
$assert_session->linkExists('Latest version');
}
/**
* Tests that unmoderated content types have a "create new revision" checkbox.
*/
public function testCreateNewRevisionCheckbox() {
$account = $this->createUser();
$account->addRole('administrator');
$account->save();
$assert_session = $this->assertSession();
$account = $this->createUser([], NULL, TRUE);
$this->drupalLogin($account);
$this->createNode([
'type' => $this->nodeType->id(),
'type' => $this->createContentType()->id(),
'title' => 'Deft Zebra',
]);
$this->drupalGet('/admin/content');
$this->assertSession()->elementExists('named', ['link', 'Deft Zebra'])->click();
$this->assertSession()->elementExists('css', 'a[rel="edit-form"]')->click();
$this->assertSession()->fieldExists('Create new revision');
$this->getSession()->getPage()->clickLink('Deft Zebra');
$assert_session->elementExists('css', 'a[rel="edit-form"]')->click();
$assert_session->fieldExists('Create new revision');
}
/**
* Tests that moderated content does not provide publish/unpublish buttons.
*/
public function testEnableModerationForContentType() {
$assert_session = $this->assertSession();
$node_type = $this->createContentType()->id();
$account = $this->createUser([
'administer nodes',
'create ' . $this->nodeType->id() . ' content',
"create $node_type content",
]);
$this->drupalLogin($account);
$this->visit('/node/add/' . $this->nodeType->id());
$this->assertSession()->buttonExists('Save');
$this->assertSession()->checkboxChecked('Published');
$this->assertSession()->buttonNotExists('Save and publish');
$this->assertSession()->buttonNotExists('Save as unpublished');
$this->visit("/node/add/$node_type");
$assert_session->buttonExists('Save');
$assert_session->checkboxChecked('Published');
$assert_session->buttonNotExists('Save and publish');
$assert_session->buttonNotExists('Save as unpublished');
$this->enableModeration();
$workflow = Workflow::load('editorial');
/** @var \Drupal\content_moderation\Plugin\WorkflowType\ContentModerationInterface $workflow_type */
$workflow_type = $workflow->getTypePlugin();
$workflow_type->addEntityTypeAndBundle('node', $node_type);
$workflow->save();
$this->getSession()->reload();
$this->assertSession()->buttonExists('Save');
$this->assertSession()->fieldNotExists('status[value]');
$this->assertSession()->buttonNotExists('Save and publish');
$this->assertSession()->buttonNotExists('Save as unpublished');
$assert_session->buttonExists('Save');
$assert_session->fieldNotExists('status[value]');
$assert_session->buttonNotExists('Save and publish');
$assert_session->buttonNotExists('Save as unpublished');
}
/**
......@@ -194,47 +196,36 @@ class ContentTypeModerationTest extends ExistingSiteBase {
* @depends testEnableModerationForContentType
*/
public function testContentOverviewActions() {
$assert_session = $this->assertSession();
$page = $this->getSession()->getPage();
$account = $this->createUser([], NULL, TRUE);
$this->drupalLogin($account);
$this->enableModeration();
$this->createNode([
'type' => $this->nodeType->id(),
'type' => 'test',
'title' => 'Foo',
'moderation_state' => 'draft',
]);
$this->createNode([
'type' => $this->nodeType->id(),
'type' => 'test',
'title' => 'Bar',
'moderation_state' => 'draft',
]);
$this->createNode([
'type' => $this->nodeType->id(),
'type' => 'test',
'title' => 'Baz',
'moderation_state' => 'draft',
]);
$this->drupalGet('/admin/content');
$this->assertSession()->selectExists('moderation_state')->selectOption('Draft');
$page->selectFieldOption('moderation_state', 'Draft');
$this->assertSession()
->elementExists('css', '.views-exposed-form .form-actions input[type = "submit"]')
$assert_session->elementExists('css', '.views-exposed-form .form-actions input[type = "submit"]')
->press();
$this->assertSession()->optionNotExists('Action', 'node_publish_action');
$this->assertSession()->optionNotExists('Action', 'node_unpublish_action');
}
/**
* Enables moderation for the content type under test.
*/
private function enableModeration() {
$this->nodeType->setThirdPartySetting('lightning_workflow', 'workflow', 'editorial');
$this->container
->get('module_handler')
->invoke('lightning_workflow', 'node_type_insert', [$this->nodeType]);
$assert_session->optionNotExists('Action', 'node_publish_action');
$assert_session->optionNotExists('Action', 'node_unpublish_action');
}
}
......@@ -3,7 +3,6 @@
namespace Drupal\Tests\lightning_workflow;
use Drupal\block\Entity\Block;
use Drupal\lightning_core\ConfigHelper as Config;
use Drupal\node\Entity\NodeType;
use Drupal\Tests\lightning_core\FixtureBase;
use Drupal\user\Entity\Role;
......@@ -25,18 +24,6 @@ final class FixtureContext extends FixtureBase {
$this->save($role);
}
if (!$this->container->get('module_handler')->moduleExists('lightning_page')) {
$config = new Config(
$this->container->get('extension.list.module')->get('lightning_page'),
$this->container->get('config.factory'),
$this->container->get('entity_type.manager')
);
$config->deleteAll();
}
// Install Lightning Page separately in order to ensure that the optional
// Pathauto config that it ships is installed too.
$this->installModule('lightning_page');
// Lightning Workflow optionally integrates with Diff, and for testing
// purposes we'd like to enable that integration. In order to test with
// meaningful responsibility-based roles, we also enable Lightning Roles.
......@@ -51,14 +38,14 @@ final class FixtureContext extends FixtureBase {
// Cache the original state of the editorial workflow.
$this->config('workflows.workflow.editorial');
// Add moderation to the page content type.
/** @var \Drupal\node\NodeTypeInterface $node_type */
$node_type = NodeType::load('page')
->setThirdPartySetting('lightning_workflow', 'workflow', 'editorial');
$dependencies = $node_type->getDependencies();
$dependencies['enforced']['module'][] = 'lightning_page';
$node_type->set('dependencies', $dependencies)->save();
lightning_workflow_node_type_insert($node_type);
// Create a temporary content type specifically for testing.
$node_type = NodeType::create([
'type' => 'test',
'name' => 'Test',
]);
$node_type->setThirdPartySetting('lightning_workflow', 'workflow', 'editorial');
$this->save($node_type);
node_add_body_field($node_type);
// Cache the original state of the content view.
$this->config('views.view.content');
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment