Skip to content

test: add view function coverage for framework#1589 - #161

Merged
hwbrzzl merged 1 commit into
masterfrom
ship/2026-10-26-view-pr-1589-tests
Oct 31, 2026
Merged

hwbrzzl merged 1 commit into
masterfrom
ship/2026-10-26-view-pr-1589-tests

Conversation

@goravel-agent

@goravel-agent goravel-agent commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Add application-level coverage for WithViewFuncs, View.AddFuncs, View.Funcs, and the shared view compiler wiring, with render results asserted end-to-end under both the gin and fiber drivers.
  • Five new cases in ViewTestSuite pin the app function render, the package function render, the app-over-package name override, the merged registry returned by Funcs(), and the fact that Funcs() hands back an independent copy.
  • The example app now registers template functions from both layers — inline WithViewFuncs in bootstrap/app.go, package AddFuncs in packages/viewtest/service_provider.go, three named-template fixtures, and a /view-funcs/{app,package,override} route group.

Why

This branch adds application-level coverage for goravel/framework#1589. Template functions registered by the application and by package providers both have to land on the driver's template set, and the application's registration has to be applied last so it wins a name collision. The example app now exercises that path through real routes and asserts the rendered HTML, so a regression in either driver surface fails loudly instead of passing silently.

// bootstrap/app.go: application-level template functions
WithViewFuncs(func() template.FuncMap {
	return template.FuncMap{
		"app_greeting": func(name string) string {
			return "app-hello " + name
		},
	}
}).

// packages/viewtest/service_provider.go: package-level template functions
facades.View().AddFuncs(template.FuncMap{
	"package_greeting": func(name string) string {
		return "package-hello " + name
	},
})

// routes/web.go: render a view that calls the registered function
facades.Route().Prefix("view-funcs").Group(func(router route.Router) {
	router.Get("app", func(ctx http.Context) http.Response {
		return ctx.Response().View().Make("app_func.tmpl", map[string]any{
			"name": "Goravel",
		})
	})
})

The contested name lives in one place: viewtest.GreetingFuncName is registered by both the package provider and the application, so a rename breaks the build instead of quietly dropping the override coverage, and the registry test asserts membership of the expected names rather than an exact sorted set, so a newly framework-registered function does not fail it.

The branch is rebased onto current master, so both sides of the earlier conflict survive: master's view-csrf coverage (TestRender_CsrfField, TestRender_StringMapDataWithCsrfField) and this PR's view-funcs coverage run side by side.

Dependencies track upstream rather than a fork. The github.com/protibimbok/* replace block is gone from go.mod and go.sum, so there is nothing left to drop before merging; gin and fiber now resolve from their canonical modules at the heads that landed in goravel/gin#261 (v1.18.1-0.20261030085342-4d9429b10cb3) and goravel/fiber#315 (v1.18.1-0.20261030085228-66c98dc71f1d), which are the only canonical pin until either repo cuts a v1.18.1 tag. github.com/goravel/framework stays pinned at v1.18.1-0.20261029110755-f9582c05db52 through the require + self-replace pair carried by master, so the older framework version gin and fiber ask for cannot downgrade the code compiled here.

@goravel-agent
goravel-agent requested a review from a team as a code owner October 26, 2026 04:26
@hwbrzzl
hwbrzzl force-pushed the ship/2026-10-26-view-pr-1589-tests branch 2 times, most recently from 4ca6193 to 0906c12 Compare October 27, 2026 08:53
@goravel-agent
goravel-agent force-pushed the ship/2026-10-26-view-pr-1589-tests branch from 0906c12 to 6d2af33 Compare October 31, 2026 02:37
@hwbrzzl
hwbrzzl merged commit aa4b2a4 into master Oct 31, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants