Right now, in order for child distributions to use our Behat tests, they have to copy our FeatureContext. This isn't a problem until they add their own additions and then need to update it with the code they took from us! We should provide this in a 3rd party module (how about panopoly_test?) and then child distributions can simply make a child class of it. I'm not entirely sure how to package it so that the Behat command line tool will find it, so that's something we'll need to figure out.

Comments

dsnopek’s picture

dsnopek’s picture

Issue summary: View changes
cboyden’s picture

This should work, but I think it will need the Drupal Extension fix in this issue: https://www.drupal.org/node/2093737. Otherwise you can't call functions like getRegion() from a subcontext.

I just confirmed that this fix is in version 1.0.2 and it does allow you to call getMainContext()->getRegion() from a subcontext.

cboyden’s picture

Assigned: Unassigned » cboyden

Working on a patch - it's going well so far.

cboyden’s picture

Assigned: cboyden » Unassigned
Status: Active » Needs review
StatusFileSize
new25.18 KB
new23.41 KB

Two patches attached, one for the main panopoly and one for panopoly_test.

The only thing that is not yet working in a subcontext file is the fixStepArgument that allows you to use a previously-generated random value. So in this patch, it's still in FeatureContext.php.

Another useful thing to do would be set up FeatureContext.php so it can use parameters from the behat.yml file, if anyone adds them.

cboyden’s picture

You have to install Behat fresh or run a composer update to get version 1.0.2 of the Drupal extension, which fixes the getRegion issue.

cboyden’s picture

The problem with fixStepArgument is that you can't override it in a subcontext because it's defined in MinkContext, and the subcontexts do not inherit from MinkContext, only from BehatContext. There may be some OOP magic that can be done to get around this, otherwise this function has to stay in FeatureContext.php.

A similar problem will happen if you want to override any functions provided by the Drupal extension.

dsnopek’s picture

To #7: What if instead of providing a sub-context, we provided a full FeatureContext (extending DrupalContext) that child distributions would extend? So, they'd do something like:

class FeatureContext extends PanopolyContext {
  // My custom stuff here...
}

It would allow us to do pretty much anything. I'm not exactly sure how to get that loaded, though... Anyway, just a random idea!

cboyden’s picture

The thing you get with subcontexts created as *.behat.inc files is auto-loading. The FeatureContext.php can be completely bare-bones, but as long as you've got your behat.yml file set up correctly, all of the added step definitions will be loaded. So it's kind of mixing metaphors to have other step definitions for which you have to do something extra in FeatureContext.php. It does not allow a tester to drop in their own FeatureContext.php and get everything. And you have a situation where you've got mixed-up dependencies with things in panopoly_test vs. tests/behat.

So you'd have to go all one way or all another. This would mean either:

  • figure out how to override MinkContext in a subcontext, perhaps with dependency injection? or
  • give up on putting the step definitions in panopoly_test and have them all in PanopolyContext.php (or subcontexts included from there), which then has to be included in and extended by FeatureContext.

For the "included in" part, there may be something you can do with autoloading.

And, this may be another ticket, but: The .features pretty much all have dependencies on panopoly_test (for the content type), but that module will not necessarily be enabled when the tests are run. Should the scenarios enable the module before they start, then disable it at the end?

cboyden’s picture

To fix the mixed-up dependencies, it should work to have all of the test code (config, features, step definitions) included in the panopoly_test module. The FeatureContext.php will do nothing except require and extend PanopolyContext.php.

If a child distribution wants to use Panopoly test code, it should either use Panopoly's FeatureContext straight up, and run the composer.json in the panopoly_test module, OR, put tests wherever and make sure their behat.yml includes all of the locations to look for features and step definitions, and their FeatureContext can find PanopolyContext and extend it.

cboyden’s picture

Assigned: Unassigned » cboyden
cboyden’s picture

StatusFileSize
new73.96 KB
new101.82 KB

Two patches attached, one for the main Panopoly and one for panopoly_test.

The first removes all test code and config from the main repo.

The second adds all of the test code and config to panopoly_test. It also moves assets needed for the tests (i.e. files to upload) to the module and uses generic names for them. And finally, it turns FeatureContext.php into a stub that just requires and extends PanopolyContext.php, which contains the steps that can't live in the *.behat.inc files.

dsnopek’s picture

Status: Needs review » Needs work

@cboyden: Thanks for the patches! :-)

Some quick review:

  • The README.txt is removed from the profile, but not added back to panopoly_test
  • This doesn't appear to update scripts/travis-ci.sh at all, so the tests will break there

I'm about to try the tests locally to see if they're running for me in this new layout.

dsnopek’s picture

+++ b/panopoly_test.behat.inc
@@ -0,0 +1,423 @@
+  public function iWaitForAJAX() {
+    $this->getSession()->wait(5000, 'jQuery != undefined && jQuery.active === 0');
+  }
+   * @Given /^I log in with the One Time Login Url$/
+   */
+  public function iLogInWithTheOneTimeLoginUrl() {
+    if ($this->getMainContext()->loggedIn()) {

Something went wrong here! There is no start (ie. /**) to the comment.

This causes a PHP syntax error when I try to run locally.

cboyden’s picture

StatusFileSize
new102.52 KB

Ugh, not sure how that got messed up in the patch. A new patch is attached which fixes the comment and also adds README.md to the module.

cboyden’s picture

StatusFileSize
new79.1 KB

Previous patch to test did not remove extra step definitions.

cboyden’s picture

Status: Needs work » Needs review
StatusFileSize
new76.37 KB

And here's an updated patch for the main repo that fixes the Travis script.

Right now the environment is building OK, but the file-upload tests are failing. Probably requires a different files path setting in behat.travis.yml.

dsnopek’s picture

Status: Needs review » Needs work

Hrm. Actually, I think your patch for panopoly_test simply doesn't include the binary files! You've got references to test-sm.png and test-lg.png in the *.feature files, but the data for those files isn't included in the patch - just some metadata:

diff --git a/tests/test-lg.png b/tests/test-lg.png
new file mode 100644
index 0000000..d04f5f1
Binary files /dev/null and b/tests/test-lg.png differ

Try regenerating the panopoly_test patch using git diff --binary --full-index - that should put the binary data in there too.

cboyden’s picture

Status: Needs work » Needs review
StatusFileSize
new164.31 KB

Thanks for the tip - new patch attached.

dsnopek’s picture

Status: Needs review » Needs work

Thanks! I just tried running this on Travis-CI:

https://travis-ci.org/dsnopek/panopoly/builds/29515611

It's getting past the uploads now!

But it's failing on submenu_widget.feature for some reason. And it hasn't finished running yet either...

cboyden’s picture

Status: Needs work » Needs review
StatusFileSize
new164.37 KB
new76.37 KB

The main menu region was not defined in the YML. Now it's added. Also updated panopoly makefile to include the latest panopoly_test patch.

cboyden’s picture

submenu_widget is a new test - it's not finished. Right now it only tests that you can add an existing page to the main menu. Eventually it will include a real test for the submenu. Should I back it out of this patch?

dsnopek’s picture

Ah, yeah, let's try to restrict these changes to just what's necessary to move the tests and FeatureContext. That'll make it easier to follow the history of this later. :-)

cboyden’s picture

StatusFileSize
new76.37 KB
new163.11 KB

OK. New patches attached without the submenu test.

cboyden’s picture

StatusFileSize
new163.11 KB
new76.37 KB

Incorrect filename for uploaded image in wysiwyg test - fixed in this patch.

dsnopek’s picture

Status: Needs review » Reviewed & tested by the community

I ran the patch on #25 on Travis-CI:

https://travis-ci.org/dsnopek/panopoly/builds/29528644

It looks like you did the same here (with a single gremlin):

https://travis-ci.org/cboyden/panopoly/builds/29527240

And both are passing! So, I think this is ready to commit. :-))

cboyden’s picture

Woohoo!

The patch to the Panopoly makefile pulls in the patch for panopoly_test - once panopoly_test is committed, that reference needs to be taken out and pointed to the correct Git hash. That should be it for this issue.

  • dsnopek committed cfde6d7 on 7.x-1.x authored by cboyden
    Issue #2293747 by cboyden | dsnopek: Move our FeatureContext and *....
dsnopek’s picture

Title: Move our FeatureContext into panopoly_test so that child distributions can reuse it » Move our FeatureContext and *.features into panopoly_test so that child distributions can reuse them
Status: Reviewed & tested by the community » Fixed

Ah, yes, thanks for the reminder. :-)

I've committed this! Here's the Travis-CI build of final committed versions (hopefully no surprises):

https://travis-ci.org/panopoly/panopoly/builds/29538086

Thanks again - this all looks awesome!

dsnopek’s picture

Hrm! Travis-CI is hitting a weird issue with the md5 checksum not matching when it's trying to download panopoly_test -- except that it really shouldn't even be downloading panopoly_test! I've made a change that should stop it trying: #2300529: On Travis-CI, panopoly_test should be enabled AFTER completing the upgrade

The build for that is here:

https://travis-ci.org/panopoly/panopoly/builds/29548712

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.