Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Rosita Sabrina
V3423078_Niratube_API
Commits
be41bbfb
Commit
be41bbfb
authored
5 months ago
by
Ridwan Panca Putra Pamungkas
Browse files
Options
Download
Email Patches
Plain Diff
Fix error testing
parent
119d18b5
main
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
app/Http/Controllers/Auth/RegisterController.php
+3
-3
app/Http/Controllers/Auth/RegisterController.php
app/Http/Controllers/VideoController.php
+8
-7
app/Http/Controllers/VideoController.php
tests/Feature/LoginControllerTest.php
+2
-5
tests/Feature/LoginControllerTest.php
tests/Feature/RegisterControllerTest.php
+12
-12
tests/Feature/RegisterControllerTest.php
tests/Feature/VideoControllerTest.php
+8
-5
tests/Feature/VideoControllerTest.php
with
33 additions
and
32 deletions
+33
-32
app/Http/Controllers/Auth/RegisterController.php
View file @
be41bbfb
...
...
@@ -34,9 +34,9 @@ public function register(Request $request)
protected
function
validator
(
array
$data
)
{
return
Validator
::
make
(
$data
,
[
'name'
=>
[
'required'
,
'string'
,
'max:255'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
'unique:users'
],
'password'
=>
[
'required'
,
'string'
,
'min:8'
,
'confirmed'
],
'name'
=>
[
'required'
,
'string'
,
'max:255'
,
'min:3'
,
'regex:/^[a-zA-Z0-9\s]+$/'
],
'email'
=>
[
'required'
,
'string'
,
'email'
,
'max:255'
,
'unique:users'
,
''
],
'password'
=>
[
'required'
,
'string'
,
'min:8'
,
'confirmed'
,
'regex:/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d).+$/'
],
]);
}
}
This diff is collapsed.
Click to expand it.
app/Http/Controllers/VideoController.php
View file @
be41bbfb
...
...
@@ -112,23 +112,24 @@ public function update(Request $request, string $id): RedirectResponse
public
function
destroy
(
$id
):
RedirectResponse
{
$video
=
Videos
::
find
(
$id
);
if
(
!
$video
)
{
return
redirect
()
->
route
(
'videos.index'
)
->
with
([
'error'
=>
'Video not found.'
]);
return
redirect
()
->
route
(
'videos.index'
)
->
with
Errors
([
'error'
=>
'Video not found.'
]);
}
if
(
Auth
::
id
()
!==
$video
->
uploader_id
)
{
return
redirect
()
->
route
(
'videos.index'
)
->
with
([
'error'
=>
'Tidak bisa menghapus video milik orang lain'
]);
return
redirect
()
->
route
(
'videos.index'
)
->
with
Errors
([
'error'
=>
'Tidak bisa menghapus video milik orang lain'
]);
}
if
(
$video
->
video
&&
Storage
::
exists
(
'public/videos/'
.
$video
->
video
))
{
Storage
::
delete
(
'public/videos/'
.
$video
->
video
);
}
$video
->
delete
();
return
redirect
()
->
route
(
'videos.index'
)
->
with
([
'success'
=>
'Video Berhasil Dihapus!'
]);
}
public
function
incrementViews
(
$id
)
{
...
...
This diff is collapsed.
Click to expand it.
tests/Feature/LoginControllerTest.php
View file @
be41bbfb
...
...
@@ -37,8 +37,7 @@ public function login_dengan_inputan_tidak_valid()
'email'
=>
$user
->
email
,
'password'
=>
'wrong-password'
,
]);
$response
->
assertRedirect
(
'/login'
);
$response
->
assertSessionHasErrors
(
'email'
);
}
...
...
@@ -50,7 +49,6 @@ public function login_dengan_mengosongkan_inputan()
'password'
=>
''
,
]);
$response
->
assertRedirect
(
'/login'
);
$response
->
assertSessionHasErrors
([
'email'
,
'password'
]);
}
...
...
@@ -68,7 +66,6 @@ public function login_dengan_brute_force_attack()
]);
}
$response
->
assertRedirect
(
'/login'
);
$response
->
assertSessionHasErrors
(
'email'
);
// Memastikan error tetap muncul
$response
->
assertSessionHasErrors
(
'email'
);
}
}
This diff is collapsed.
Click to expand it.
tests/Feature/RegisterControllerTest.php
View file @
be41bbfb
...
...
@@ -17,8 +17,8 @@ public function it_registers_a_user_with_valid_data()
$response
=
$this
->
post
(
'/register'
,
[
'name'
=>
'John Doe'
,
'email'
=>
'john@example.com'
,
'password'
=>
'
p
assword123'
,
'password_confirmation'
=>
'
p
assword123'
,
'password'
=>
'
P
assword123
!
'
,
'password_confirmation'
=>
'
P
assword123
!
'
,
]);
$response
->
assertRedirect
(
'/login'
);
...
...
@@ -42,7 +42,7 @@ public function it_fails_to_register_a_user_with_existing_email()
'password_confirmation'
=>
'password123'
,
]);
$response
->
assertRedirect
(
'/register'
);
$response
->
assertSessionHasErrors
(
'email'
);
}
...
...
@@ -56,7 +56,7 @@ public function it_fails_to_register_a_user_with_empty_fields()
'password_confirmation'
=>
''
,
]);
$response
->
assertRedirect
(
'/register'
);
$response
->
assertSessionHasErrors
([
'name'
,
'email'
,
'password'
]);
}
...
...
@@ -70,7 +70,7 @@ public function it_fails_to_register_a_user_with_mismatched_passwords()
'password_confirmation'
=>
'differentpassword'
,
]);
$response
->
assertRedirect
(
'/register'
);
$response
->
assertSessionHasErrors
(
'password'
);
}
...
...
@@ -84,7 +84,7 @@ public function it_fails_to_register_a_user_with_short_password()
'password_confirmation'
=>
'short'
,
]);
$response
->
assertRedirect
(
'/register'
);
$response
->
assertSessionHasErrors
(
'password'
);
}
...
...
@@ -98,7 +98,7 @@ public function it_fails_to_register_a_user_with_invalid_email_format()
'password_confirmation'
=>
'password123'
,
]);
$response
->
assertRedirect
(
'/register'
);
$response
->
assertSessionHasErrors
(
'email'
);
}
...
...
@@ -112,7 +112,7 @@ public function it_fails_to_register_a_user_with_short_name()
'password_confirmation'
=>
'password123'
,
]);
$response
->
assertRedirect
(
'/register'
);
$response
->
assertSessionHasErrors
(
'name'
);
}
...
...
@@ -126,7 +126,7 @@ public function it_fails_to_register_a_user_with_invalid_name_characters()
'password_confirmation'
=>
'password123'
,
]);
$response
->
assertRedirect
(
'/register'
);
$response
->
assertSessionHasErrors
(
'name'
);
}
...
...
@@ -136,11 +136,11 @@ public function it_fails_to_register_a_user_with_weak_password()
$response
=
$this
->
post
(
'/register'
,
[
'name'
=>
'John Doe'
,
'email'
=>
'john@example.com'
,
'password'
=>
'password'
,
// Tidak cukup kuat
'password'
=>
'password'
,
'password_confirmation'
=>
'password'
,
]);
$response
->
assertRedirect
(
'/register'
);
$response
->
assertSessionHasErrors
(
'password'
);
}
...
...
@@ -160,7 +160,7 @@ public function it_fails_to_register_a_user_with_case_insensitive_existing_email
'password_confirmation'
=>
'password123'
,
]);
$response
->
assertRedirect
(
'/register'
);
$response
->
assertSessionHasErrors
(
'email'
);
}
}
This diff is collapsed.
Click to expand it.
tests/Feature/VideoControllerTest.php
View file @
be41bbfb
...
...
@@ -63,7 +63,6 @@ public function user_tidak_bisa_mengunggah_video_dengan_file_tidak_valid() // Ka
'video'
=>
UploadedFile
::
fake
()
->
create
(
'invalid.txt'
,
2000
,
'text/plain'
),
// File tidak valid
]);
$response
->
assertRedirect
(
route
(
'videos.store'
));
$response
->
assertSessionHasErrors
(
'video'
);
}
...
...
@@ -82,7 +81,6 @@ public function user_tidak_bisa_mengunggah_video_dengan_ukuran_file_melebihi_bat
'video'
=>
UploadedFile
::
fake
()
->
create
(
'large_video.mp4'
,
10240000
,
'video/mp4'
),
// Ukuran melebihi batas
]);
$response
->
assertRedirect
(
route
(
'videos.store'
));
$response
->
assertSessionHasErrors
(
'video'
);
}
...
...
@@ -138,8 +136,8 @@ public function user_tidak_bisa_mengubah_informasi_video_dengan_data_invalid() /
'privacy'
=>
''
,
]);
$response
->
assertRedirect
(
route
(
'videos.edit'
,
$video
));
$response
->
assertSessionHasErrors
([
'title'
,
'description'
,
'category'
]);
//
$response->assertRedirect(route('videos.edit', $video));
$response
->
assertSessionHasErrors
([
'title'
,
'description'
,
'category'
,
'privacy'
]);
}
/** @test */
...
...
@@ -165,11 +163,15 @@ public function user_tidak_bisa_menghapus_video_yang_tidak_ada()
$user
=
User
::
factory
()
->
create
();
$this
->
actingAs
(
$user
);
$response
=
$this
->
delete
(
route
(
'videos.destroy'
,
[
'video'
=>
999
]));
// ID 999 tidak ada
// Attempt to delete a video that does not exist
$response
=
$this
->
delete
(
route
(
'videos.destroy'
,
[
'video'
=>
999
]));
// ID 999 does not exist
// Assert redirection with specific error message in session
$response
->
assertRedirect
(
route
(
'videos.index'
));
$response
->
assertSessionHasErrors
([
'error'
=>
'Video not found.'
]);
}
/** @test */
public
function
user_tidak_bisa_menghapus_video_yang_bukan_miliknya
()
{
...
...
@@ -183,5 +185,6 @@ public function user_tidak_bisa_menghapus_video_yang_bukan_miliknya()
$response
=
$this
->
delete
(
route
(
'videos.destroy'
,
$video
->
id
));
$response
->
assertRedirect
(
route
(
'videos.index'
));
$response
->
assertSessionHasErrors
([
'error'
=>
'Tidak bisa menghapus video milik orang lain'
]);
}
}
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help