Main navigation

Breadcrumb

GSoC Week 10: encrypt_content_client - testing time

By Marcin Czarnecki

Published 2 weeks ago

Last updated 1 week ago

JavaScript functional testing

I started writing functional tests for my module’s JavaScript features. The first step was to install PhantomJS on my machine. I followed this tutorial to do so, then while PhantomJS instance was running in a terminal window I ran PHPUnit with my test cases.

After many failed runs I managed to get my environment variables set correctly and was able to run JavaScript functional tests:

After getting that to work, I could move on and start writing more tests. I managed to write the following functional tests:

Keys generation:

Generate keys through GUI - with the right permissions

Try to access the page without needed permissions

Node encryption

Create a node with an empty encryption policy

Create a node with title and body fields encrypted

Node decryption

Edit node and compare decrypted fields

View single node, make sure the fields are decrypted

Writing those tests helped me add more features needed for my module to run correctly; one example was adding schema settings for module’s config values. It also helps with future development.

Taking screenshots during JavaScript tests

PhantomJS is a headless browser which means that it performs action like an actual web browser with graphical interface it’s not visible to the user. The only thing I can see is HTTP request details returned from test run’s calls.

I then discovered the feature of taking screenshots at particular moments during tests, which is a great feature for debugging.

The example above demonstrates how well screenshots can aid debugging. I was writing a test for checking what options are available and I was getting an error. Then I noticed that not options at all are displayed in that select field. After setting the Drupal’s installation type to the standard one instead of minimal I received below screenshot.

PHP functional testing

I have also written tests for custom REST resources for my module:

ECC keys resource

Get public keys for all users

Get public key of a single user

I need to find a way of testing POST methods of custom REST resources, I will do that in next week.

Drupal messages using JavaScript

Another observation from executing tests is promoting the use of Drupal messages when JavaScript actions succeed. I also created a small function that will be included in helpers.js file as I could not find this function built-in into Drupal’s JavaScript API.

Interesting issues

MouseEventConstructor is not a constructor

I found a workaround by implementing this MouseOver event manually and including in my module’s JavaScript code as a separate library called helper.js.

undefined is not an object (evaluating 'f[a].dir=f.rtl[a]?"rtl":"ltr"')

The errors above were encountered when trying to run a test which creates new article using actual GUI. This was an error given by CKEditor described here. I did not manage to fix it in this week as I will need to investigate more. This issue is connected to the issue where I could not retrieve the node’s body using jQuery without entering something in the summary field.

Plans for week 11

Continue to work on functional tests.

Add more user scenarios.

Find a way of testing POST methods of custom REST resources.

Work on a high-level documentation and more in-depth architecture document for people that want to contribute to my module.