TwoFAccountExportRequestTest.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. <?php
  2. namespace Tests\Api\v1\Requests;
  3. use App\Api\v1\Requests\TwoFAccountExportRequest;
  4. use Illuminate\Foundation\Testing\WithoutMiddleware;
  5. use Illuminate\Support\Facades\Auth;
  6. use Illuminate\Support\Facades\Validator;
  7. use PHPUnit\Framework\Attributes\CoversClass;
  8. use PHPUnit\Framework\Attributes\DataProvider;
  9. use PHPUnit\Framework\Attributes\Test;
  10. use Tests\TestCase;
  11. /**
  12. * TwoFAccountExportRequestTest test class
  13. */
  14. #[CoversClass(TwoFAccountExportRequest::class)]
  15. class TwoFAccountExportRequestTest extends TestCase
  16. {
  17. use WithoutMiddleware;
  18. #[Test]
  19. public function test_user_is_authorized()
  20. {
  21. Auth::shouldReceive('check')
  22. ->once()
  23. ->andReturn(true);
  24. $request = new TwoFAccountExportRequest;
  25. $this->assertTrue($request->authorize());
  26. }
  27. #[Test]
  28. #[DataProvider('provideValidData')]
  29. public function test_valid_data(array $data) : void
  30. {
  31. $request = new TwoFAccountExportRequest;
  32. $request->merge($data);
  33. $validator = Validator::make($data, $request->rules());
  34. $this->assertFalse($validator->fails());
  35. }
  36. /**
  37. * Provide Valid data for validation test
  38. */
  39. public static function provideValidData() : array
  40. {
  41. return [
  42. [[
  43. 'ids' => '1',
  44. 'otpauth' => '1',
  45. ]],
  46. [[
  47. 'ids' => '1',
  48. 'otpauth' => 1,
  49. ]],
  50. [[
  51. 'ids' => '1',
  52. 'otpauth' => true,
  53. ]],
  54. [[
  55. 'ids' => '1',
  56. ]],
  57. [[
  58. 'ids' => '1',
  59. 'otpauth' => '0',
  60. ]],
  61. [[
  62. 'ids' => '1',
  63. 'otpauth' => 0,
  64. ]],
  65. [[
  66. 'ids' => '1',
  67. 'otpauth' => false,
  68. ]],
  69. ];
  70. }
  71. #[Test]
  72. #[DataProvider('provideInvalidData')]
  73. public function test_invalid_data(array $data) : void
  74. {
  75. $request = new TwoFAccountExportRequest;
  76. $request->merge($data);
  77. $validator = Validator::make($data, $request->rules());
  78. $this->assertTrue($validator->fails());
  79. }
  80. /**
  81. * Provide invalid data for validation test
  82. */
  83. public static function provideInvalidData() : array
  84. {
  85. return [
  86. [[
  87. 'ids' => '1',
  88. 'otpauth' => null,
  89. ]],
  90. [[
  91. 'ids' => '1',
  92. 'otpauth' => '',
  93. ]],
  94. [[
  95. 'ids' => '1',
  96. 'otpauth' => 2,
  97. ]],
  98. [[
  99. 'ids' => '1',
  100. 'otpauth' => 'string',
  101. ]],
  102. [[
  103. 'ids' => '1',
  104. 'otpauth' => 0.1,
  105. ]],
  106. [[
  107. 'ids' => '1',
  108. 'otpauth' => '01/01/2020',
  109. ]],
  110. [[
  111. 'ids' => '1',
  112. 'otpauth' => '01',
  113. ]],
  114. ];
  115. }
  116. }