Testing a random field

Posted 7 months ago by jaydubyasee

I have a registration form which prompts the user to enter either their day, month or year of birth. The choice of day/month/year is randomly decided by the controller each time the form loads. The system then uses this (along with other identifying information entered) to check the corresponding member record and display the next page in the registration process.

My problem is how to set up a test which simulates user input when I don't know which data item the system will ask for?

Controller

    public function showRegistrationForm()
    {
        $datePart = array_rand(['Day' => 'Day', 'Month' => 'Month', 'Year' => 'Year']);
        // random day, month or year
        $dateArray = Utils::getAllDaysMonthsYears($datePart);

        return view('auth.register')
            ->with('datePart', $datePart)
            ->with('dateArray', $dateArray);
    }

View

            <div class="form-group{{ $errors->has('dob') ? ' has-error' : '' }}">
                {{ Form::label('dob', "$datePart of birth", ['class' => ' control-label']) }}

                <div class="rounded-select dob">
                    {{Form::select('dob',
                    $dateArray,
                    old('dob'),
                    ['class' => 'form-control correct-drpdwn-height', 'required' => 'required', 'size' => 1])}}
                    {{ Form::hidden(
                        'dobPart',
                        $datePart
                        )
                    }}
                </div>

                @if ($errors->has('dob'))
                    <span class="help-block">
                        <strong>{{ $errors->first('dob') }}</strong>
                    </span>
                @endif

            </div>

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.