We should validate that we're creating correct CCL in Koha using our unit tests. I've included a simple example at https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=11175#c522
The tricky part of course is that we build/mangle/manipulate/transform queries all over the place so this might be easier said than done.