I'm in a place where I'm testing a significant migration, and I want to iterate through all the nodes on the site that are of a certain content type. Otherwise, you tend to load up the same specific nodes rather than test comprehensively.

I've seen some people set up a callback that returns JSON for this: https://designhammer.com/blog/testing-drupal-data-migrations-casperjs

But that seems one-off. What's the best way to get access to Drupal database internals via CasperJS? I will update this thread as I discover, but I thought I'd open the question to see if others have solved this problem.

It seems like Services might be the best place to start... any work been done around services? Any integration planned or any ideas?

It would seem that this would be a common enough need that even were this not supported in the module, documentation could be created on best practices here, which I can do as I learn.

Comments

glass.dimly’s picture

A couple of different approaches:

jonathan_hunt’s picture

I'd suggest trying Drush REST API. Based on this thread https://github.com/drush-ops/drush/pull/405 a sandbox contrib module is at https://www.drupal.org/project/drush_rest_api. See docs http://cgit.drupalcode.org/drush-rest-api/tree/docs/rest-api.html.

The idea is that you can expose Drush (thus, say SQL commands) to HTTP, therefore casperjs.

glass.dimly’s picture

Status: Active » Closed (works as designed)

I'm using views_datasource module and outputting json based on url arguments. My view spits out the aliased path. I loop through my array of access types.
var accessTypesToFetch = ['metered_timed', 'premium', 'free'];

I get the the source like this:

casper.getURLsByAccessType = function(accessType){
    casper.thenOpen(JSONContentURL + '/' + accessType, {method: 'get', headers: {'Accept': 'application/json'}}, function() {
        casper.test.info('fetching ' + JSONContentURL + '/' + accessType);
        content[accessType] = JSON.parse(casper.getPageContent());
    });
    casper.then(function(){
        casper.test.assertTruthy(content[accessType].length, accessType + ' content JSON is loaded and ready to be crawled.');
    });
};

Then I iterate over it and schedule a crawl.

glass.dimly’s picture

Another method would be creating a nodejs wrapper script to execute arbitrary drush commands (including PHP) and then passing variables to phantom/casper via the command line arguments. Anyone have an example of something like this?