So it's already the start of the third month for me here, and about time for me to summarise the second. My colleagues take turns to have weeks off for vacation as leaves start turning yellow and my first Swiss autumn is coming on.
This blogpost is part of the on-going MD Systems Drupal 8 Internships. In these Blogs the students report monthly about their experience with Drupal 8, the development work they do and the cooperation with our Team...
File Entity: treating uploaded files as real content
I wrote my previous blog post while I was in the middle of porting File Entity to Drupal 8. File Entity is basically a bunch of features that makes uploaded files equal to other types of content in Drupal: you can assign custom fields like Author and Description to them, each file can be viewed on a page of its own, etc. In short, File Entity allows to manage all uploaded files fully extensive but still in a simple way. Without it, an uploaded file in a Drupal system is no more than an attachment to a page or an article.
One of the features of File Entity is making files serializable for the purpose of REST applications. After successfully implementing that, we also submitted it as a patch for Core, where an issue was created for that already over a year ago. The issue remains open at present, however, as discussion goes on.
We finished porting the essential functionality of File Entity. There is also extensive test coverage so we can confirm that the project now is stable enough for real applications, and it will be integrated into our Drupal 8 projects. And thanks to our need of improved file handling in those projects, that functionality is now freely available for anyone else who's also using Drupal 8. That's the magic of Open Source!
Behat, test-driven development
We are fans of fully automated tests. With a Continuous Integration (CI) system like Jenkins, we can have all our test cases run with each code change. That way we don't have to manually execute tests, and we can focus on development while waiting a few minutes for the results.
The automated testing is especially powerful if we first write the tests, and afterwards implement the code that should pass the tests. This methodology is known as test-driven development, and is done in short iterations.
During the last phase, every change in the code should make another test pass. At the point where all tests are passing, we can be sure that what we are writing indeed meets our requirements - no less, no more.
Furthermore, we'd like to recommend using Behat, a testing framework for behavior-driven development in PHP. Behat tests define how the system should behave towards the user. The test cases are written in plain English:
Given that I am on "user/1"
When I click "Home"
Then I should be on the homepage
Anyone can understand it, and if the test is green when you run it then you can be sure that the website does what it should. Check out this simple Behat tutorial for an easy walkthrough.
Personalisation with Simplenews
My most recent project is a new feature for the newsletter module Simplenews. This module allows your visitors to easily subscribe to newsletters from your website by filling in their email address. But you might also allow people to register and log in as regular users on the site, and currently the connection between the subscriber and the user is minimal. I am now defining and implementing a more useful and logical behaviour for that relation.
Stay tuned for a follow-up on the Simplenews project when September ends, and before that check the next update of my fellow intern Christian Broekmeulen in about two weeks!