a06f331eb8
CI / benchmark (push) Has been skipped
install-script / posix-syntax (push) Successful in 6m1s
CI / build-onnx (push) Failing after 6m43s
init-smoke / dry-run (push) Failing after 15m57s
security / govulncheck (push) Has been cancelled
security / trivy-fs (push) Has been cancelled
CI / test (1.26, ubuntu-latest) (push) Has been cancelled
Scorecard supply-chain security / Scorecard analysis (push) Has been cancelled
CI / test (1.26, macos-latest) (push) Has been cancelled
CI / build-windows (push) Has been cancelled
CI / lint (push) Has been cancelled
install-script / powershell-syntax (push) Has been cancelled
install-script / install (macos-14) (push) Has been cancelled
install-script / install (ubuntu-latest) (push) Has been cancelled
81 lines
2.2 KiB
Go
81 lines
2.2 KiB
Go
package contracts
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/zzet/gortex/internal/graph"
|
|
)
|
|
|
|
func TestDrupalRoutes_ControllerAndForm(t *testing.T) {
|
|
src := []byte(`node.view:
|
|
path: '/node/{node}'
|
|
defaults:
|
|
_controller: '\Drupal\node\Controller\NodeController::view'
|
|
_title: 'View'
|
|
node.add:
|
|
path: '/node/add'
|
|
defaults:
|
|
_form: '\Drupal\node\Form\NodeAddForm'
|
|
methods: [GET, POST]
|
|
`)
|
|
ext := &HTTPExtractor{}
|
|
cs := ext.Extract("modules/node/node.routing.yml", src, nil, nil)
|
|
|
|
var view, addGet, addPost *Contract
|
|
for i := range cs {
|
|
fw, _ := cs[i].Meta["framework"].(string)
|
|
if fw != "drupal" {
|
|
continue
|
|
}
|
|
switch cs[i].ID {
|
|
case "http::ANY::/node/{p1}":
|
|
view = &cs[i]
|
|
case "http::GET::/node/add":
|
|
addGet = &cs[i]
|
|
case "http::POST::/node/add":
|
|
addPost = &cs[i]
|
|
}
|
|
}
|
|
if view == nil {
|
|
t.Fatalf("no _controller route; got %+v", cs)
|
|
}
|
|
if hc, _ := view.Meta["handler_class"].(string); hc != "NodeController" {
|
|
t.Errorf("controller handler_class = %q (want NodeController)", hc)
|
|
}
|
|
if hi, _ := view.Meta["handler_ident"].(string); hi != "view" {
|
|
t.Errorf("controller handler_ident = %q (want view)", hi)
|
|
}
|
|
if addGet == nil || addPost == nil {
|
|
t.Errorf("_form route with methods [GET, POST] should yield both verbs")
|
|
}
|
|
if addGet != nil {
|
|
if hc, _ := addGet.Meta["handler_class"].(string); hc != "NodeAddForm" {
|
|
t.Errorf("_form handler_class = %q (want NodeAddForm)", hc)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestDrupalRoutes_SameFileControllerBinding(t *testing.T) {
|
|
// The controller method declared in the same routing file resolves to its
|
|
// SymbolID (receiver-aware), not just a cross-file stamp.
|
|
src := []byte(`my.route:
|
|
path: '/x'
|
|
defaults:
|
|
_controller: '\Drupal\my\Controller\MyController::handle'
|
|
`)
|
|
nodes := []*graph.Node{{
|
|
ID: "m.routing.yml::MyController.handle", Kind: graph.KindMethod, Name: "handle",
|
|
FilePath: "m.routing.yml", StartLine: 4, EndLine: 4,
|
|
Meta: map[string]any{"receiver": "MyController"},
|
|
}}
|
|
ext := &HTTPExtractor{}
|
|
cs := ext.Extract("m.routing.yml", src, nodes, nil)
|
|
for _, c := range cs {
|
|
if c.ID == "http::ANY::/x" {
|
|
if c.SymbolID != "m.routing.yml::MyController.handle" {
|
|
t.Errorf("same-file controller SymbolID = %q (want the handle method)", c.SymbolID)
|
|
}
|
|
}
|
|
}
|
|
}
|