Advertisement
Guest User

Untitled

a guest
Feb 13th, 2016
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. <?php
  2.  
  3. use App\User;
  4.  
  5. class UserTest extends TestCase
  6. {
  7. /**
  8. * @var \Faker\Generator
  9. */
  10. private $faker;
  11.  
  12. /**
  13. * UserPositiveTest constructor.
  14. */
  15. public function __construct()
  16. {
  17. $this->faker = Faker\Factory::create('pt_BR');
  18. }
  19.  
  20. /**
  21. * Make a random user array.
  22. *
  23. * @param array $attributes
  24. * @return array
  25. */
  26. protected function factory($attributes = [])
  27. {
  28. return array_merge([
  29. 'name' => $this->faker->name,
  30. 'email' => $this->faker->email,
  31. 'password' => $pass = str_random(10),
  32. 'password_confirmation' => $pass,
  33. ], $attributes);
  34. }
  35.  
  36. /**
  37. * Test for Store, Login and Logout actions.
  38. */
  39. public function testStoreLoginLogout()
  40. {
  41. $user = $this->factory();
  42.  
  43. $structure = ['id', 'name', 'email'];
  44.  
  45. // store
  46. $this->json('post', '/user', $user)->seeJsonStructure($structure);
  47.  
  48. // login
  49. $this->json('post', '/login', $user)->seeJsonStructure($structure);
  50.  
  51. // login check
  52. $this->json('get', '/login')->seeJsonStructure($structure);
  53.  
  54. // logout
  55. $this->json('post', '/logout')->seeJsonEquals([]);
  56.  
  57. // login check empty
  58. $this->json('get', '/login')->seeJsonEquals([]);
  59. }
  60.  
  61. /**
  62. * Test for Update action.
  63. */
  64. public function testShow()
  65. {
  66. $user = User::orderByRaw('RAND()')->first();
  67.  
  68. $this->json('get', '/user/' . $user->id)->seeJsonEquals($user->toArray());
  69. }
  70.  
  71. /**
  72. * Test for Update action.
  73. */
  74. public function testUpdate()
  75. {
  76. $user = User::orderByRaw('RAND()')->first();
  77.  
  78. // fast login
  79. $this->be($user);
  80.  
  81. // new data
  82. $data = $this->factory([
  83. 'password' => '',
  84. 'password_confirmation' => ''
  85. ]);
  86.  
  87. // edit yourself (keep old password)
  88. $this->json('put', '/user/' . $user['id'], $data)->seeJsonEquals(User::find($user['id'])->toArray());
  89.  
  90. // TODO: password old check
  91.  
  92. // edit yourself (new password)
  93. $this->json('put', '/user/' . $user['id'], $this->factory())->seeJsonEquals(User::find($user['id'])->toArray());
  94.  
  95. // TODO: password new check
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement