Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Tests\Feature;
- use App\Collection;
- use App\User;
- use Tests\TestCase;
- use Illuminate\Foundation\Testing\DatabaseMigrations;
- class CollectionAuthorizedTest extends TestCase
- {
- use DatabaseMigrations;
- /**
- * Test Setup will create a user, login the user before all the tests
- *
- */
- public function setUp()
- {
- parent::setUp();
- factory(User::class)->create([
- 'username' => 'TestingAuthCollection',
- 'email' => 'testingauthcollection@testing.com',
- 'password' => bcrypt('testauthcollection')
- ]);
- $this->followingRedirects()
- ->post('/login', ['email' => 'testingauthcollection@testing.com', 'password' => 'testauthcollection']);
- }
- /**
- * Test tear down will remove the user from the database
- *
- */
- public function tearDown()
- {
- $userdelete = User::where('username', 'TestingAuthCollection')->first();
- $userdelete->delete();
- parent::tearDown();
- }
- /**
- *
- * Test Collection Visible
- *
- * This test will create 5 new collections
- * with 5 new users each with a unique owner_id
- * Once the user logs in it will see the name
- * of all the collections (all 5).
- *
- */
- public function testAllCollectionsVisible()
- {
- $collections = factory('App\Collection', 5)->create();
- foreach ($collections as $collection) {
- $user = User::where('id', $collection->owner_id)->first();
- $this->followingRedirects()
- ->actingAs($user)
- ->post(route('login'), ['email' => $user['email'], 'password' => 'secret'])
- ->assertStatus(200)
- ->assertSee(e($collection->name));
- }
- }
- /**
- *
- * Test Create Collection
- *
- * This test will create a new user and perform
- * a post /login and also a post /collections
- * with name of collection as 'testingcreate' and description as 'testcreate phpunit'
- * The test should see the name of the collection.
- *
- */
- public function testCreateCollection()
- {
- $this->followingRedirects()
- ->post('/collections', ['name' => 'testingauthcreate', 'description' => 'testauthcreate phpunit'])
- ->assertSee('testingauthcreate');
- }
- /**
- *
- * Test View Collection
- *
- * This test create a new user and perform
- * a post /login and also a post /collections
- * with name of collection as 'testingview' and description as 'testview phpunit'
- * and it will collect information from the database with the name 'testingview'
- * and perform a get /collection/$collection_id->id and it should see 'testview phpunit'
- *
- */
- public function testViewCollection()
- {
- $this->followingRedirects()
- ->post('/collections', ['name' => 'testingauthview', 'description' => 'testauthview phpunit'])
- ->assertSee('testingauthview');
- $testuser = User::where('username' , 'TestingAuthCollection')->first();
- $collection_id = Collection::where('name', 'testingauthview' )->where('owner_id', $testuser->id)->first();
- $this->followingRedirects()
- ->get('/collections/' . $collection_id->id)
- ->assertSee('testingauthview')
- ->assertSee('testauthview phpunit');
- }
- /**
- *
- * Test Update Collection
- *
- * This test create a new user and perform
- * a post /login and also a post /collections
- * with name of collection as 'testingupdate' and description as 'testupdate phpunit'
- * and it will collect information from the database with the name 'testingupdate'
- * and perform a put /collection/$collection_id->id to make changes to see
- * name 'testingupdate1' and description 'testupdate phpunit1'
- *
- */
- public function testUpdateCollection()
- {
- $this->followingRedirects()
- ->post('/collections', ['name' => 'testingauthupdate', 'description' => 'testauthupdate phpunit']);
- $testuser = User::where('username' , 'TestingAuthCollection')->first();
- $collection = Collection::where('name', 'testingauthupdate')->where('owner_id', $testuser->id)->first();
- $this->followingRedirects()
- ->put('/collections/' . $collection['id'], ['name' => 'testingauthupdate1', 'description' => 'testauthupdate phpunit1'])
- ->assertSee('testingauthupdate1')
- ->assertSee('testauthupdate phpunit1');
- }
- /**
- *
- * Test Edit Collection
- *
- * this is testing if the collection is successfully
- * a post /login and also a post /collections
- * with name of collection as 'testingedit' and description as 'testedit phpunit'
- * and it will collect information from the database with the name 'testingedit'
- * and check if the data in the collection has been edited which is for for displaying
- * a form to apply changes via get method.
- *
- */
- public function testEditCollection()
- {
- $this->followingRedirects()
- ->post('/collections', ['name' => 'testingauthedit', 'description' => 'testauthedit phpunit'])
- ->assertSee('testingauthedit');
- $testuser = User::where('username' , 'TestingAuthCollection')->first();
- $collection_id = Collection::where('name', 'testingauthedit' )->where('owner_id', $testuser->id)->first();
- $this->followingRedirects()
- ->get('/collections/' . $collection_id->id .'/edit')
- ->assertSee($collection_id->name)
- ->assertSee($collection_id->description);
- }
- /**
- *
- * Test Delete Collection
- *
- * This test create a new user and perform
- * a post /login and also a post /collections
- * with name of collection as 'testingdelete' and description as 'testdelete phpunit'
- * and it will collect information from the database with the name 'testingdelete'
- * and perform a delete /collection/$collection_id->id to delete the collection
- * and the name of the collection should not be visible anymore.
- *
- */
- public function testDeleteCollection()
- {
- $this->followingRedirects()
- ->post('/collections', ['name' => 'testingauthdelete', 'description' => 'testauthdelete phpunit'])
- ->assertSee('testingauthdelete');
- $testuser = User::where('username' , 'TestingAuthCollection')->first();
- $collection_id = Collection::where('name', 'testingauthdelete')->where('owner_id', $testuser->id)->first();
- $this->followingRedirects()
- ->DELETE('/collections/' . $collection_id->id)
- ->assertDontSee('testingauthdelete');
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement