grails / grails-gsp

GSP (Grails Server Pages) - A server-side view rendering technology based on Groovy
Apache License 2.0
15 stars 33 forks source link

Tests for taglibs with custom namespace don't work #62

Open ppazos opened 4 years ago

ppazos commented 4 years ago

FYI: found this test but it's @Ignored https://github.com/grails/grails-gsp/blob/af8bfebd63936fe29ef7abe833386b0ed00e01f3/grails-plugin-gsp/src/test/groovy/org/grails/web/pages/TagLibNamespaceTests.groovy#L13

Task List

When the tests are executed, the one for the taglibs fail: Tag [isLoggedIn] does not exist. No tag library found for namespace: sa

The tablig is defined in the 'sa" namespace:

package com.cabolabs.security

class SimpleAuthTagLib {
   static namespace = 'sa'
   static defaultEncodeAs = [taglib:'html']
   //static encodeAsForTags = [tagName: [taglib:'html'], otherTagName: [taglib:'none']]

   def isLoggedIn = { attrs, body ->
      def man = SessionManager.getInstance()
      if (man.hasSession(session.id.toString()))
      {
         out << body()
      }
   }
}

The issue is in the def output = applyTemplate('<sa:isLoggedIn>hidden content</sa:isLoggedIn>')

https://github.com/ppazos/grails-simple-auth/blob/master/src/test/groovy/com/cabolabs/security/SimpleAuthTagLibSpec.groovy#L28

Steps to Reproduce

  1. clone https://github.com/ppazos/grails-simple-auth
  2. use grails 3.3.10
  3. grails test-app

Expected Behaviour

Should execute the taglib and return some output to compare with the expected behavior.

Actual Behaviour

ERROR: Tag [isLoggedIn] does not exist. No tag library found for namespace: sa

Environment Information

Example Application

it's a plugin: https://github.com/ppazos/grails-simple-auth

IanSolomon commented 10 months ago

@ppazos this looks to be caused by missing the gsp plugin you can add it something like compile "org.grails.plugins:gsp" to your build.gradle and it should resolve the issue in the tests. I came across a similar issue and tried that and looks to fix it. sharing this here in case it is helpful.