public function openPageByAction(FunctionalTester $I) { $I->amOnAction('PostsController@index'); $I->seeCurrentUrlEquals('/posts'); $I->seeCurrentRouteIs('posts.index'); }
<?php /** * ------------------------------------ * Reply deletion * ------------------------------------ */ $I = new FunctionalTester($scenario); Route::enableFilters(); $I->wantTo('Delete a reply as a visitor, normal member and admin.'); $topic = $I->postATopic(['title' => 'My Awsome Topic.']); $reply = $I->have('Reply', ['topic_id' => $topic->id]); // Testing as a visitor $I->am('as a visitor'); $I->amOnRoute('topics.show', $topic->id); $I->dontSeeElement('#reply-delete-' . $reply->id); $I->amOnRoute('topics.delete', $topic->id); $I->seeCurrentRouteIs('login-required'); // Test as a normal member $I->am('as a member'); $I->signIn(); $I->dontSeeElement('#reply-delete-' . $reply->id); $I->amOnRoute('topics.delete', $topic->id); $I->seeCurrentRouteIs('admin-required'); // Testing as a admin user $I->am('a Phphub admin'); $I->signInAsAdmin(); $I->amOnRoute('topics.show', $topic->id); $I->seeElement('#reply-delete-' . $reply->id); $I->click('#reply-delete-' . $reply->id); $I->dontSeeRecord('replies', ['id' => $reply->id]);
<?php $I = new FunctionalTester($scenario); $I->wantTo('Add a product to cart'); $product = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'published', 1); $I->amOnRoute('shop.product.show', $product->slug); $I->click('Add to Cart'); $I->seeCurrentRouteIs('shop.cart.show'); $I->see('Product added to cart', '.alert'); $I->see($product->title, '.CartTable-product-title');
public function login_with_not_activated_account(FunctionalTester $I) { $I->am('Unlogged user with a not activated account'); $I->wantTo('Login'); $I->expectTo('see an error message explaining that my account is not activated, with a link to resend the activation email'); /*************************************************************************************************************** * settings **************************************************************************************************************/ // we create a user $this->_credentials = ['last_name' => 'NOM', 'first_name' => 'Prénom', 'email' => '*****@*****.**', 'password' => 'password']; $user = \Sentinel::register($this->_credentials); /*************************************************************************************************************** * run test **************************************************************************************************************/ $I->amOnPage('/'); $I->seeCurrentRouteIs('home'); $I->click(trans('template.front.header.my_account')); $I->seeCurrentRouteIs('login.index'); $I->fillField('email', '*****@*****.**'); $I->fillField('password', 'password'); $I->click(trans('auth.login.action.login')); $I->seeCurrentRouteIs('login.index'); $I->see(trans('global.modal.alert.title.error'), 'h3'); $I->see(trans('auth.message.activation.failure')); $I->see(strip_tags(trans('auth.message.activation.email.resend', ['url' => route('account.activation_email', ['email' => $user->email]), 'email' => $user->email]))); }
<?php $I = new FunctionalTester($scenario); $I->wantTo('Update Blog Tests'); // Not signed tests $I->amOnRoute('blog.edit', 47); $I->seeCurrentUrlEquals('/auth/login'); // Sign in $I->signIn(); // Update Blog $I->amOnRoute('blog.edit', 47); $I->see('Edit Blog'); $I->fillField('form input[name=title]', 'New Blog by FunctionalTester'); $I->selectOption('form select[name=category_id]', '2'); $I->fillField('form textarea[name=body]', 'bodybodybody \\n by FunctionalTester'); $I->click('form [type=submit]'); $I->seeCurrentUrlMatches('~^/blog/(\\d+)$~'); $I->seeCurrentRouteIs('blog.show', 47);
/** * ------------------------------------ * User editing * ------------------------------------ */ $I = new FunctionalTester($scenario); Route::enableFilters(); $I->wantTo('Editing user profile as a Visitor and the Owner.'); $user = $I->have('User'); // --------------- As a visitor -------------- $I->am('as a Visitor'); $I->amOnRoute('users.show', $user->id); $I->dontSeeElement('#user-edit-button'); $I->amOnRoute('users.edit', $user->id); $I->seeCurrentRouteIs('login-required'); // --------------- As a member -------------- $user = $I->signIn(); $I->am('as the Owner'); $I->amOnRoute('users.show', $user->id); $I->seeElement('#user-edit-button'); $I->click('#user-edit-button'); $I->seeCurrentRouteIs('users.edit', $user->id); $I->fillField(['name' => 'city'], 'My city'); $I->fillField(['name' => 'company'], 'My company'); $I->fillField(['name' => 'twitter_account'], 'My twitter_account'); $I->fillField(['name' => 'personal_website'], 'My personal_website'); $I->fillField(['name' => 'signature'], 'My signature'); $I->fillField(['name' => 'introduction'], 'My introduction'); $I->click('#user-edit-submit'); $I->see('My city');
public function access_to_the_leading_team_page(FunctionalTester $I) { $I->am('Anybody'); $I->wantTo('access to the leading team page'); $I->expectTo('see that the user shown in the category they belong'); /*************************************************************************************************************** * settings **************************************************************************************************************/ // we create a member of the student leading board $credentials = ['last_name' => 'Student', 'first_name' => 'President', 'email' => '*****@*****.**', 'status_id' => config('user.status_key.student_president'), 'board_id' => config('user.board_key.student_leading_board'), 'password' => 'test']; Sentinel::register($credentials, true); // we create a member of the student leading board $credentials = ['last_name' => 'Deactivated', 'first_name' => 'Student vice-president', 'email' => '*****@*****.**', 'status_id' => config('user.status_key.user'), 'board_id' => config('user.board_key.student_leading_board'), 'password' => 'test']; Sentinel::register($credentials); // we create a member of the leading board $credentials = ['last_name' => 'Regular', 'first_name' => 'President', 'email' => '*****@*****.**', 'status_id' => config('user.status_key.president'), 'board_id' => config('user.board_key.leading_board'), 'password' => 'test']; Sentinel::register($credentials, true); // we create a member of the executive committee $credentials = ['last_name' => 'Communication', 'first_name' => 'Responsible', 'email' => '*****@*****.**', 'status_id' => config('user.status_key.communication_commission'), 'board_id' => config('user.board_key.executive_committee'), 'password' => 'test']; Sentinel::register($credentials, true); // we create an employee $credentials = ['last_name' => 'Coach', 'first_name' => 'Employee', 'email' => '*****@*****.**', 'status_id' => config('user.status_key.employee'), 'password' => 'test']; Sentinel::register($credentials, true); /*************************************************************************************************************** * run test **************************************************************************************************************/ $I->amOnPage('/'); $I->seeCurrentRouteIs('home'); $I->click(trans('template.front.header.leading_team')); $I->see('Student', '.student_leading_board'); $I->see('President', '.student_leading_board'); $I->see(trans('users.config.status.student_president'), '.student_leading_board'); $I->dontSee('Deactivated', '.student_leading_board'); $I->dontSee('Student vice-president', '.student_leading_board'); $I->dontSee(trans('users.config.status.user'), '.student_leading_board'); $I->see('Regular', '.leading_board'); $I->see('President', '.leading_board'); $I->see(trans('users.config.status.president'), '.leading_board'); $I->see('Communication', '.executive_committee'); $I->see('Responsible', '.executive_committee'); $I->see(trans('users.config.status.communication_commission'), '.executive_committee'); $I->see('Coach', '.employee'); $I->see('Employee', '.employee'); $I->see(trans('users.config.status.employee'), '.employee'); }
<?php $I = new FunctionalTester($scenario); $I->wantTo('Add a product to cart that has bad extras'); // Create the models $product = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'inStock', 1); // Extra 1 - This extra has a few options and will be selected $extra1 = $I->makeModel(DanPowell\Shop\Models\Extra::class, [], 'inStock', 1); $extra1 = $product->extras()->save($extra1); $option1 = $I->makeModel(DanPowell\Shop\Models\Option::class, [], 'text', 1); $option1 = $extra1->options()->save($option1); $I->amOnRoute('shop.product.show', $product->slug); // Select the extra 1, but DON'T fill out the option value $I->checkOption('extra[' . $extra1->id . ']'); $I->submitForm('#addToCart', []); $I->dontSee('Product added to cart', '.alert'); $I->seeCurrentRouteIs('shop.product.show'); $I->seeFormHasErrors();
<?php $I = new FunctionalTester($scenario); $I->wantTo('Update Article Tests'); // Not signed tests $I->amOnRoute('article.edit', 19); $I->seeCurrentUrlEquals('/auth/login'); // Sign in $I->signIn(); // Update Article $I->amOnRoute('article.edit', 19); $I->see('Edit Article'); $I->fillField('form input[name=title]', 'New Article by FunctionalTester'); $I->selectOption('form select[name=category_id]', '1'); $I->fillField('form textarea[name=body]', 'bodybodybody \\n by FunctionalTester'); $I->click('form [type=submit]'); $I->seeCurrentUrlMatches('~^/article/(\\d+)$~'); $I->seeCurrentRouteIs('article.show', 19);
public function routesWithTrailingSlashes(FunctionalTester $I) { $I->amOnPage('/contact-us////////'); $I->see('Contact Us'); $I->seeCurrentRouteIs('front.contact'); }
public function checkHomePageContainsDataSetInAdmin(FunctionalTester $I) { $I->am('Admin'); $I->wantTo('check on the home page that the data saved from the admin panel are shown'); $I->expectTo('see the saved data on the home page'); /*************************************************************************************************************** * settings **************************************************************************************************************/ // we create the admin role $admin_role = $this->_createAdminRole(); // we attach it to the logged user $admin_role->users()->attach($this->_user); // we create a slide $this->_createSlide(); /*************************************************************************************************************** * run test **************************************************************************************************************/ $I->amOnPage('/'); $I->seeCurrentRouteIs('home'); $I->see($this->_slide->title, 'h2'); $I->see($this->_slide->quote, '.quote'); $I->seeElement('//img[@src="' . url('img/slides/' . $this->_slide->picto) . '"]'); $I->seeElement('//div[@data-background-image="' . url('img/slides/' . $this->_slide->background_image) . '"]'); $I->see(json_decode(file_get_contents(storage_path('app/home/content.json')))->title, 'h2'); $I->see(json_decode(file_get_contents(storage_path('app/home/content.json')))->description); $I->seeElement('//a[@href="' . json_decode(file_get_contents(storage_path('app/home/content.json')))->video_link . '"]'); }
<?php $I = new FunctionalTester($scenario); $I->wantTo('Create an order'); // Add a product to the cart $product = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'published', 1); $I->amOnRoute('shop.product.show', $product->slug); $I->click('Add to Cart'); // Checkout $I->click('Checkout'); $order = $I->makeModel(DanPowell\Shop\Models\Order::class, [], null, 1); $I->submitForm('#createOrder', $order->toArray()); $I->seeCurrentRouteIs('shop.order.confirm'); // Continue to confirmation //$I->click('Continue to confirmation'); // Check delivery option exists in config // Check delivery option matches cart total // Check billing & delivery country exists in config
public function delete_current_role_denied(FunctionalTester $I) { $I->am('Admin'); $I->wantTo('delete the Admin role'); $I->expectTo('see an error message explaining that deleting the role we use is not possible'); $admin = $this->_createAdminRole(); $admin->users()->attach($this->_user); $I->amOnRoute('permissions.index'); $I->submitForm('#delete_' . $admin->id, []); $I->seeCurrentRouteIs('permissions.index'); $I->see(trans('global.modal.alert.title.error'), 'h3'); $I->see(strip_tags(trans('permissions.message.delete.denied', ['name' => $admin->name]))); $I->see($admin->name, '.table-list'); }
<?php $I = new FunctionalTester($scenario); $I->wantTo('Update Topic Tests'); // Not signed tests $I->amOnRoute('topic.edit', 1); $I->seeCurrentUrlEquals('/auth/login'); // Sign in $I->signIn(); // Update topic $I->amOnRoute('topic.edit', 1); $I->see('Edit Topic'); $I->fillField('form input[name=title]', 'New Topic by FunctionalTester'); $I->selectOption('form select[name=node_id]', '4'); $I->fillField('form textarea[name=body]', 'bodybodybody \\n by FunctionalTester'); $I->click('form [type=submit]'); $I->seeCurrentUrlMatches('~^/topic/(\\d+)$~'); $I->seeCurrentRouteIs('topic.show', 1);
<?php $I = new FunctionalTester($scenario); $I->wantTo('Add a duplicate product to cart that has low stock'); $product = $I->createModel(DanPowell\Shop\Models\Product::class, [], 'inStock', 1); $I->amOnRoute('shop.product.show', $product->slug); $I->submitForm('#addToCart', ['quantity' => 6]); $I->seeCurrentRouteIs('shop.cart.show'); $I->see('Product added to cart', '.alert'); $I->amOnRoute('shop.product.show', $product->slug); $I->submitForm('#addToCart', ['quantity' => 6]); $I->seeCurrentRouteIs('shop.product.show', $product->slug); $I->dontSee('Product added to cart', '.alert'); $I->see('not enough product stock'); $I->seeFormHasErrors();