CMS-4023 Rewrite logic to check if content has children

Added test