UserPatchPwdRequestTest.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace Tests\Api\v1\Requests;
  3. use App\Api\v1\Requests\UserPatchPwdRequest;
  4. use Illuminate\Foundation\Testing\WithoutMiddleware;
  5. use Illuminate\Support\Facades\Validator;
  6. use Illuminate\Support\Facades\Auth;
  7. use Tests\TestCase;
  8. class UserPatchPwdRequestTest extends TestCase
  9. {
  10. use WithoutMiddleware;
  11. /**
  12. * @test
  13. */
  14. public function test_user_is_authorized()
  15. {
  16. Auth::shouldReceive('check')
  17. ->once()
  18. ->andReturn(true);
  19. $request = new UserPatchPwdRequest();
  20. $this->assertTrue($request->authorize());
  21. }
  22. /**
  23. * @dataProvider provideValidData
  24. */
  25. public function test_valid_data(array $data) : void
  26. {
  27. $request = new UserPatchPwdRequest();
  28. $validator = Validator::make($data, $request->rules());
  29. $this->assertFalse($validator->fails());
  30. }
  31. /**
  32. * Provide Valid data for validation test
  33. */
  34. public function provideValidData() : array
  35. {
  36. return [
  37. [[
  38. 'currentPassword' => 'newPassword',
  39. 'password' => 'newPassword',
  40. 'password_confirmation' => 'newPassword',
  41. ]],
  42. ];
  43. }
  44. /**
  45. * @dataProvider provideInvalidData
  46. */
  47. public function test_invalid_data(array $data) : void
  48. {
  49. $request = new UserPatchPwdRequest();
  50. $validator = Validator::make($data, $request->rules());
  51. $this->assertTrue($validator->fails());
  52. }
  53. /**
  54. * Provide invalid data for validation test
  55. */
  56. public function provideInvalidData() : array
  57. {
  58. return [
  59. [[
  60. 'currentPassword' => '', // required
  61. 'password' => 'newPassword',
  62. 'password_confirmation' => 'newPassword',
  63. ]],
  64. [[
  65. 'currentPassword' => 'currentPassword',
  66. 'password' => '', // required
  67. 'password_confirmation' => 'newPassword',
  68. ]],
  69. [[
  70. 'currentPassword' => 'newPassword',
  71. 'password' => 'anotherPassword', // confirmed
  72. 'password_confirmation' => 'newPassword',
  73. ]],
  74. [[
  75. 'currentPassword' => 'pwd',
  76. 'password' => 'pwd', // min:8
  77. 'password_confirmation' => 'newPassword',
  78. ]],
  79. [[
  80. 'currentPassword' => 'pwd',
  81. 'password' => true, // string
  82. 'password_confirmation' => 'newPassword',
  83. ]],
  84. [[
  85. 'currentPassword' => 'pwd',
  86. 'password' => 10, // string
  87. 'password_confirmation' => 'newPassword',
  88. ]],
  89. ];
  90. }
  91. }