Test the blueprints yaml files are valid

Hi all,

I’m new to Kirby and PHPUnit and I have a testing question. What is the easiest way to test that the blueprints yaml files are valid and there are no errors in the panel?

Thanks,
Adrian

It’s not a final solution but you can use this to make sure the yaml is valid:

http://yaml-online-parser.appspot.com/

It does however don’t check if it’s valid against the panel.

Hi @jenstornell,

Thanks for your reply. Do you know also some automation tools? I need to do this in an automation framework. If is nothing that already exists than I will start doing my own one using some yml parser libraries.

Thanks,
Adrian

No, I don’t know anything like that but you could use yaml_parse for basic yaml validation. It returns false if it fails.

Kirby includes the Spyc Yaml parser class as dependency and uses that to parse the blueprints.

So if you want to unit test your blueprints, using that library would be best. You can also use the Kirby\Panel\Models\Page\Blueprint class from the Panel code (you get access to that by requiring panel/app/bootstrap.php) to take it even further.

But please note that you can never perfectly test something like this. Things like fields and their options don’t get checked while loading the blueprint, but by the field once it is initiated. So every check is always imperfect. But you can at least validate the YAML structure. :wink:

Do you know why it does not use the built in one?

http://php.net/manual/en/function.yaml-parse.php

The php yaml parser is a pecl extension that needs to be installed separately. So you cannot count on that.

2 Likes