Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- use App\User;
- class UserTest extends TestCase
- {
- /**
- * @var \Faker\Generator
- */
- private $faker;
- /**
- * UserPositiveTest constructor.
- */
- public function __construct()
- {
- $this->faker = Faker\Factory::create('pt_BR');
- }
- /**
- * Make a random user array.
- *
- * @param array $attributes
- * @return array
- */
- protected function factory($attributes = [])
- {
- return array_merge([
- 'name' => $this->faker->name,
- 'email' => $this->faker->email,
- 'password' => $pass = str_random(10),
- 'password_confirmation' => $pass,
- ], $attributes);
- }
- /**
- * Test for Store, Login and Logout actions.
- */
- public function testStoreLoginLogout()
- {
- $user = $this->factory();
- $structure = ['id', 'name', 'email'];
- // store
- $this->json('post', '/user', $user)->seeJsonStructure($structure);
- // login
- $this->json('post', '/login', $user)->seeJsonStructure($structure);
- // login check
- $this->json('get', '/login')->seeJsonStructure($structure);
- // logout
- $this->json('post', '/logout')->seeJsonEquals([]);
- // login check empty
- $this->json('get', '/login')->seeJsonEquals([]);
- }
- /**
- * Test for Update action.
- */
- public function testShow()
- {
- $user = User::orderByRaw('RAND()')->first();
- $this->json('get', '/user/' . $user->id)->seeJsonEquals($user->toArray());
- }
- /**
- * Test for Update action.
- */
- public function testUpdate()
- {
- $user = User::orderByRaw('RAND()')->first();
- // fast login
- $this->be($user);
- // new data
- $data = $this->factory([
- 'password' => '',
- 'password_confirmation' => ''
- ]);
- // edit yourself (keep old password)
- $this->json('put', '/user/' . $user['id'], $data)->seeJsonEquals(User::find($user['id'])->toArray());
- // TODO: password old check
- // edit yourself (new password)
- $this->json('put', '/user/' . $user['id'], $this->factory())->seeJsonEquals(User::find($user['id'])->toArray());
- // TODO: password new check
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement