2017-06-02 2 views
0

Ich bin sehr neu im Testen, aber jetzt habe ich festgestellt, dass es wesentlich ist, meine Tests zu automatisieren.Laravel-Test Fehler beim Bestätigen, dass zwei Strings gleich sind

Ich habe einen Test, der funktioniert, bis es auf den Link '/ cart' kommt es auf den Link '/ cart' kein Problem, aber jeder andere Link, den ich versuche, später klicken immer wieder auf die Wagen.

Hier ist mein Fehler nach dem Versuch, aus dem Warenkorb zu navigieren.

Failed asserting that two strings are equal. 
--- Expected 
+++ Actual 
@@ @@ 
-'http://ngwenya-mtb.dev/events' 
+'http://ngwenya-mtb.dev/cart' 

Und hier ist mein Testskript

use Illuminate\Foundation\Testing\WithoutMiddleware; 
use Illuminate\Foundation\Testing\DatabaseMigrations; 
use Illuminate\Foundation\Testing\DatabaseTransactions; 

class ExampleTest extends TestCase { 




//use Illuminate\Foundation\Testing\WithoutMiddleware; 
//use DatabaseTransactions; 
//use withoutMiddleware; 
//use DatabaseMigrations; 
/** 
* 
* A basic functional test example. 
* Please choose a unique email address for your new participant 
* @return void 
*/ 
public function testNewUserRegistration() { 

    $this->visit('http://ngwenya-mtb.dev/') 
     // View Event 
     ->click('View event details') 
     ->seePageIs('/event?id=30') 

     ->click('#enter-race47') 
     ->press('Enter yourself to this race') 

     ->seePageIs('/events/courses/register/addtocart') 
     //->withSession(['This email is already registered' => 'alert-danger']) 

     ///////////////////////////////////////////// 
     // Fill the register for for new user 
     ///////////////////////////////////////////// 
     ->type('Bingo', 'first_name') 
     ->type('11111111', 'password') 
     ->type('11111111', 'password_confirmation') 
     ->type(''.substr(md5(time()), 0, 12).'@tesing.com', 'email') 
     //->check('terms') 
     ->select('Male', 'gender') 
     ->select('1985', 'year') 
     ->select('07', 'month') 
     ->select('21', 'day') 
     ->select('Small', 'shirt_size') 
     ->select('Swaziland ID', 'id_type') 
     ->type('badassnumber', 'id_number') 
     ->select('Swazi', 'nationality') 
     //Contact details Physical 
     ->type('Dawlish', 'town_physical') 
     ->select('Swaziland', 'country_physical') 
     ->type('864741', 'phone_cell') 
     //Emergency contact details 1 
     ->type('Simon', 'emergency_contact_1') 
     ->type('Brother', 'emergency_relationship_1') 
     ->type('864741', 'emergency_phone_1'); 


     $this->press('Register'); 
     $this->seePageIs('/cart'); 


     ///////////////////////////////////////////// 
     // Add a new user 
     ///////////////////////////////////////////// 

     $this->visit('http://ngwenya-mtb.dev/'); 
     $this->click('#events-link') 

     ->seePageIs('/events'); 
     dd($this->response->getContent());exit; 
     $this->click('#event-30'); 
     $this->seePageIs('/event?id=30'); 

     $this->click('#enter-race48'); 
     $this->press('Enter someone else to this race'); 
     $this->seePageIs('/events/courses/register/addtocart');    
    } 

} 

Alles funktioniert gut bis zu diesem Kommentar

///////////////////////////////////////////// 
// Add a new user 
///////////////////////////////////////////// 

Hier ist meine Registrierung Controller

<?php 

namespace App\Http\Controllers; 

use Vinkla\Hashids\HashidsManager; 
use Illuminate\Routing\Controller as BaseController; 
use Sentinel\FormRequests\RegisterRequest; 
use Sentinel\FormRequests\EmailRequest; 
use Sentinel\FormRequests\ResetPasswordRequest; 
use Sentinel\Repositories\Group\SentinelGroupRepositoryInterface; 
use Sentinel\Repositories\User\SentinelUserRepositoryInterface; 
use Sentinel\Traits\SentinelRedirectionTrait; 
use Sentinel\Traits\SentinelViewfinderTrait; 
use Sentry; 
use View; 
use Request; 
use Event; 
use Redirect; 
use Session; 
use Config; 
use App\Models\Users; 
use Illuminate\Support\Facades\Input; 
use Gloudemans\Shoppingcart\Facades\Cart; 

class RegistrationController extends BaseController 
{ 
    /** 
    * Traits 
    */ 
    use SentinelRedirectionTrait; 
    use SentinelViewfinderTrait; 

    /** 
    * Constructor 
    */ 
    public function __construct(
     SentinelUserRepositoryInterface $userRepository, 
     SentinelGroupRepositoryInterface $groupRepository, 
     HashidsManager $hashids 
    ) { 
     $this->userRepository  = $userRepository; 
     $this->groupRepository  = $groupRepository; 
     $this->hashids    = $hashids; 
    } 

    /** 
    * Show the registration form, if registration is allowed 
    * 
    * @return Response 
    */ 
    public function registration() 
    { 
     // Is this user already signed in? If so redirect to the post login route 
     if (Sentry::check()) { 
      return $this->redirectTo('session_store'); 
     } 

     //If registration is currently disabled, show a message and redirect home. 
     if (! config('sentinel.registration', false)) { 
      return $this->redirectTo(['route' => 'home'], ['error' => trans('Sentinel::users.inactive_reg')]); 
     } 

     // All clear - show the registration form. 
     return $this->viewFinder(config('sentinel.view.user_register', 'Sentinel::users.register')); 
    } 

    /** 
    * Process a registration request 
    * 
    * @return Response 
    */ 
    public function register(RegisterRequest $request) 
    { 

     // Gather input 
     $data = $request->all(); 

     // collect cart items 
     $email = Input::get('email'); 
     $course_id = Input::get('course_id'); 
     $event_name = Input::get('event_name'); 
     $entry_fee = Input::get('entry_fee'); 

     // check user exists 
     if (Users::where('email', '=', $email)->exists()) { 
      // user found 
      $request->session()->flash('alert-danger', 'Warning: This email is already registered.'); 
      Input::flash(); 
      return View::make('sentinel.users.register') 
        ->with('course_id',$course_id) 
        ->with('event_name',$event_name) 
        ->with('entry_fee',$entry_fee); 
     } 

     // Add user and course to cart 
     if ($course_id) { 
      $firstUserRowId = Cart::add($course_id, $event_name , 1, $entry_fee, [ 
        'first_name' => Input::get('first_name'), 
        'last_name' => Input::get('last_name'), 
        'email' => Input::get('email'), 
        'no_email' => 0, 
        'master_user' => 1, 
        'gender' => Input::get('gender'), 
        'dob' => Input::get('dob'), 
        'shirt_size' => Input::get('shirt_size'), 
        'id_type' => Input::get('id_type'), 
        'id_number' => Input::get('id_number'), 
        'nationality' => Input::get('nationality'), 
        'phone_cell' => Input::get('phone_cell'), 
        'town_physical' => Input::get('town_physical'), 
        'country_physical' => Input::get('country_physical'), 
        'emergency_contact_1' => Input::get('emergency_contact_1'), 
        'emergency_relationship_1' => Input::get('emergency_relationship_1'), 
        'emergency_phone_1' => Input::get('emergency_phone_1'), 
       ]);    
     } 



     // get email from request 
     $email = $request->only('email'); 
     foreach ($email as $userModel) {} 

     // Edit date of birth from request 
     $year = Input::get('year'); 
     $month = Input::get('month'); 
     $day = Input::get('day');  
     $dob = $year.'-'.$month.'-'.$day; 
     $data['dob'] = $dob; 

     // Attempt Registration 
     $result = $this->userRepository->store($data);       

     // Log user in 
     FunctionsController::loginUser($userModel); 

     // It worked! Use config to determine where we should go. 
     return $this->redirectViaResponse('registration_complete', $result); 
    } 

    /** 
    * Activate a new user 
    * 
    * @param int $id 
    * @param string $code 
    * 
    * @return Response 
    */ 
    public function activate($hash, $code) 
    { 
     // Decode the hashid 
     $id = $this->hashids->decode($hash)[0]; 

     // Attempt the activation 
     $result = $this->userRepository->activate($id, $code); 

     // It worked! Use config to determine where we should go. 
     return $this->redirectViaResponse('registration_activated', $result); 
    } 

    /** 
    * Show the 'Resend Activation' form 
    * 
    * @return View 
    */ 
    public function resendActivationForm() 
    { 
     return $this->viewFinder('Sentinel::users.resend'); 
    } 

    /** 
    * Process resend activation request 
    * @return Response 
    */ 
    public function resendActivation(EmailRequest $request) 
    { 
     // Resend the activation email 
     $result = $this->userRepository->resend(['email' => e($request->get('email'))]); 

     // It worked! Use config to determine where we should go. 
     return $this->redirectViaResponse('registration_resend', $result); 
    } 

    /** 
    * Display the "Forgot Password" form 
    * 
    * @return \Illuminate\View\View 
    */ 
    public function forgotPasswordForm() 
    { 
     return $this->viewFinder('Sentinel::users.forgot'); 
    } 


    /** 
    * Process Forgot Password request 
    * @return Response 
    */ 
    public function sendResetPasswordEmail(EmailRequest $request) 
    { 
     // Send Password Reset Email 
     $result = $this->userRepository->triggerPasswordReset(e($request->get('email'))); 

     // It worked! Use config to determine where we should go. 
     return $this->redirectViaResponse('registration_reset_triggered', $result); 
    } 

    /** 
    * A user is attempting to reset their password 
    * 
    * @param $id 
    * @param $code 
    * 
    * @return Redirect|View 
    */ 
    public function passwordResetForm($hash, $code) 
    { 
     // Decode the hashid 
     $id = $this->hashids->decode($hash)[0]; 

     // Validate Reset Code 
     $result = $this->userRepository->validateResetCode($id, $code); 

     if (! $result->isSuccessful()) { 
      return $this->redirectViaResponse('registration_reset_invalid', $result); 
     } 

     return $this->viewFinder('Sentinel::users.reset', [ 
      'hash' => $hash, 
      'code' => $code 
     ]); 
    } 

    /** 
    * Process a password reset form submission 
    * 
    * @param $hash 
    * @param $code 
    * @return Response 
    */ 
    public function resetPassword(ResetPasswordRequest $request, $hash, $code) 
    { 
     // Decode the hashid 
     $id = $this->hashids->decode($hash)[0]; 

     // Gather input data 
     $data = $request->only('password', 'password_confirmation'); 

     // Change the user's password 
     $result = $this->userRepository->resetPassword($id, $code, e($data['password'])); 

     // It worked! Use config to determine where we should go. 
     return $this->redirectViaResponse('registration_reset_complete', $result); 
    } 
} 
+0

Bitte zeigen Sie uns Ihre Controller-Methode, die das Registrierungsformular bearbeitet. – Jamesking56

+0

Danke. Ich habe den Controller hinzugefügt. Die Funktion ist 'public function register (RegisterRequest $ request)' – warmwhisky

+0

Können Sie die '$ this-> redirectViaResponse' Methode anzeigen? – Jamesking56

Antwort

0

Es scheint, dass wenn du klickst und einen Link "Registrieren" Sie Ihre Umleitung fehlgeschlagen, so überprüfen Sie, ob Sie mehrere "Registrieren" Links/Schaltflächen haben, und wenn sie auf die richtige URL zeigen

Und für einfachste Debugging, sollten Sie weniger Behauptungen pro Test machen, Sie werden in Sichtweite gewinnen :)

+0

Hey, danke für die Antwort. Register scheint zu funktionieren, da die Datenbank mit den Benutzerdetails aktualisiert wird und dann zum Einkaufswagen weitergeleitet wird. Ist es ein Problem mit der Weiterleitung zum Warenkorb? – warmwhisky

+0

Wenn Sie nach dem Ausfüllen des Formulars manuell auf Registrieren klicken, wird Ihr Formular auf der/cart-Seite gesendet? Oder haben Sie eine Zwischenseite? –

+0

Nein, es gibt keine Zwischenseite. Es führt dann die Registrierung zum Einkaufswagen. – warmwhisky

Verwandte Themen