- mode, navigation and max_attempts columns with Go-side defaults - classes.Withheld gates every solution field of the answer feedback and the attempt result while a test attempt is open - a test's quiz detail lists no questions before the attempt starts - admin fields and lang keys for the three settings
30 lines
1.1 KiB
Go
30 lines
1.1 KiB
Go
package models
|
|
|
|
import "testing"
|
|
|
|
func TestQuizDefaults(t *testing.T) {
|
|
zero, negative := 0, -1
|
|
for name, hook := range map[string]func(*Quiz) error{
|
|
"BeforeSave": func(q *Quiz) error { return q.BeforeSave(nil) },
|
|
"BeforeValidate": func(q *Quiz) error { return q.BeforeValidate(nil) },
|
|
} {
|
|
for _, limit := range []*int{&zero, &negative} {
|
|
q := &Quiz{Title: "Q", MaxAttempts: limit}
|
|
if err := hook(q); err != nil {
|
|
t.Fatalf("%s: %v", name, err)
|
|
}
|
|
if q.Mode != ModeLearning || q.Navigation != NavigationFree || q.MaxAttempts != nil {
|
|
t.Errorf("%s with max_attempts %d = %q %q %v, want learning free nil", name, *limit, q.Mode, q.Navigation, q.MaxAttempts)
|
|
}
|
|
}
|
|
two := 2
|
|
q := &Quiz{Title: "Q", Mode: ModeTest, Navigation: NavigationOneWay, MaxAttempts: &two}
|
|
if err := hook(q); err != nil {
|
|
t.Fatalf("%s: %v", name, err)
|
|
}
|
|
if q.Mode != ModeTest || q.Navigation != NavigationOneWay || q.MaxAttempts == nil || *q.MaxAttempts != 2 {
|
|
t.Errorf("%s changed a test quiz: %q %q %v", name, q.Mode, q.Navigation, q.MaxAttempts)
|
|
}
|
|
}
|
|
}
|