<commit_before>package org.codehaus.groovy.grails.web.taglib;

import org.codehaus.groovy.runtime.InvokerHelper
import org.codehaus.groovy.grails.commons.metaclass.ExpandoMetaClass
import org.codehaus.groovy.grails.commons.*

class LinkRenderingTagLibTests extends AbstractGrailsTagTests {

    void onInit() {
        def mappingClass = gcl.parseClass('''
class TestUrlMappings {
	static mappings = {
	  "/$controller/$action?/$id?"{
	      constraints {
			 // apply constraints here
		  }
	  }

	  "/products/$id" {
	      controller = "test"
	      action = "index"
      }
      "/surveys/$action?" {
          controller = "survey"
       }
	}
}
        ''')

        grailsApplication.addArtefact(UrlMappingsArtefactHandler.TYPE, mappingClass)
    }

    void testRenderLinkWithReverseMapping() {
        def template = '<g:link controller="survey">${name}</g:link>'

        assertOutputEquals('<a href="/surveys" >Food I Like</a>', template, [name:"Food I Like"])

        template = '<g:link controller="test" action="index" id="MacBook">${name}</g:link>'

        assertOutputEquals('<a href="/products/MacBook" >MacBook</a>', template, [name:"MacBook"])<commit_msg>more unit tests for mapping and for issue GRAILS-1145<commit_after>package org.codehaus.groovy.grails.web.taglib;

import org.codehaus.groovy.runtime.InvokerHelper
import org.codehaus.groovy.grails.commons.metaclass.ExpandoMetaClass
import org.codehaus.groovy.grails.commons.*

class LinkRenderingTagLibTests extends AbstractGrailsTagTests {

    void onInit() {
        def mappingClass = gcl.parseClass('''
class TestUrlMappings {
	static mappings = {
	  "/$controller/$action?/$id?"{
	      constraints {
			 // apply constraints here
		  }
	  }

	  "/products/$id" {
	      controller = "test"
	      action = "index"
      }
      "/surveys/$action?" {
          controller = "survey"
       }
        "/searchable" {
            controller = "searchable"
            action = "index"
        }
        "/searchable/$action?" {
            controller = "searchable"
        }
	}
}
        ''')

        grailsApplication.addArtefact(UrlMappingsArtefactHandler.TYPE, mappingClass)
    }

    void testOverlappingReverseMappings() {
        def template = '<g:link controller="searchable" action="index" >Search</g:link>'

        assertOutputEquals('<a href="/searchable" >Search</a>', template)

        template = '<g:link controller="searchable" >Search</g:link>'

        assertOutputEquals('<a href="/searchable" >Search</a>', template)


        template = '<g:link controller="searchable" action="other" >Search</g:link>'

        assertOutputEquals('<a href="/searchable/other" >Search</a>', template)


        template = '<g:form controller="searchable" action="index" >Search</g:form>'

        assertOutputEquals('<form action="/searchable" method="post" >Search</form>', template)

        template = '<g:form controller="searchable" >Search</g:form>'

        assertOutputEquals('<form action="/searchable" method="post" >Search</form>', template)


    }

    void testRenderLinkWithReverseMapping() {
        def template = '<g:link controller="survey">${name}</g:link>'

        assertOutputEquals('<a href="/surveys" >Food I Like</a>', template, [name:"Food I Like"])

        template = '<g:link controller="test" action="index" id="MacBook">${name}</g:link>'

        assertOutputEquals('<a href="/products/MacBook" >MacBook</a>', template, [name:"MacBook"])
{'fraction_non_alphanumeric': 0.15091066782307025, 'fraction_numerical': 0.0011564035848511131, 'mean_word_length': 3.287484510532838, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2500986', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1014, 'n_words': 185}