Fix featured image test. Improve featured image acquisition.

Fixes #2298 

The test was correctly detecting an issue with the featured image acquisition logic. This patch fixes the issue and also improves the code to search the attachments array if it exists.