Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor #34

Merged
merged 1 commit into from
Aug 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions app/Http/Controllers/EloquentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ public function task2()
public function task3()
{
// TODO Eloquent Задание 3: Добавить в модель Item scope для фильтрации активных продуктов (scopeActive())
// Одна строка кода
// вместо []
// Одна строка кода вместо []
$products = [];

return view('eloquent.task2', [
Expand All @@ -34,8 +33,7 @@ public function task3()
public function task4($id)
{
// TODO Eloquent Задание 4: Найти Item по id и передать во view либо отдать 404 страницу
// Одна строка кода
// вместо []
// Одна строка кода вместо []
$product = [];

return view('eloquent.task4', [
Expand All @@ -62,7 +60,7 @@ public function task6($id, Request $request)

public function task7(Request $request)
{
// TODO Eloquent Задание 7: В запросе будет параметр products который будет содержать массив с id
// TODO Eloquent Задание 7: В запросе будет параметр products, который будет содержать массив с id
// [1,2,3,4 ...] выполнить массовое удаление записей модели Item с учетом id в $request

return redirect('/');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class CreatePostsTable extends Migration
public function up()
{
//TODO Migrations Задание 1: Создать таблицу categories с 2 полями id и title (не забыть про timestamps)
//

Schema::create('posts', function (Blueprint $table) {
$table->id();
Expand Down
2 changes: 1 addition & 1 deletion resources/views/table.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<!-- TODO Blade Задание 6: В эту view с контроллера передается collection c users в переменной data -->
<!-- Выполнить foreach loop в одну строку -->
<!-- Используйте view shared/user.blade.php для item (переменная user во item view) -->
<!-- Используйте view shared/empty.blade.php для состояния когда нет элементов в колекции -->
<!-- Используйте view shared/empty.blade.php для состояния когда нет элементов в коллекции -->


<!-- TODO Blade Задание 7: Здесь сделайте классический foreach loop -->
Expand Down
8 changes: 3 additions & 5 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
//TODO Route Задание 1: По GET урлу /hello отобразить view - /resources/views/hello.blade (без контроллера)
// Одна строка кода


//TODO Route Задание 2: По GET урлу / обратиться к IndexController, метод index
// Одна строка кода


//TODO Route Задание 3: По GET урлу /page/contact отобразить view - /resources/views/pages/contact.blade
// с наименованием роута - contact
// Одна строка кода
Expand All @@ -23,7 +25,6 @@
// Одна строка кода



//TODO Route Задание 6: Выполнить редирект с урла /bad на урл /good
// Одна строка кода

Expand All @@ -32,7 +33,6 @@
// Одна строка кода



//TODO Route Задание 8: Организовать группу роутов (Route::group()) объединенных префиксом - dashboard

// Задачи внутри группы роутов dashboard
Expand All @@ -47,6 +47,4 @@
// Задачи внутри группы роутов security
//TODO Задание 12: Добавить роут GET /admin/auth -> Admin/IndexController -> auth



require __DIR__ . '/default.php';
require __DIR__ . '/default.php';
22 changes: 13 additions & 9 deletions tests/Feature/ModelTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

use App\Models\Item;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;

class ModelTest extends TestCase
Expand All @@ -15,6 +13,7 @@ class ModelTest extends TestCase
public function test_task_1()
{
$item = ['title' => 'Test'];

Item::create($item);

$this->assertDatabaseHas('products', $item);
Expand All @@ -30,8 +29,8 @@ public function test_task_2()

$response = $this->get('/eloquent/task2');

$response->assertDontSee($item3->title);
$response->assertDontSee($item1->title);
$response->assertDontSee($item3->title);

$response->assertSee('1.' . $item5->title);
$response->assertSee('2.' . $item4->title);
Expand All @@ -40,10 +39,13 @@ public function test_task_2()

public function test_task_3()
{
$item = Item::factory()->create(['active' => false]);
$item1 = Item::factory()->create(['active' => true]);
$item2 = Item::factory()->create(['active' => false]);

$response = $this->get('/eloquent/task3');
$response->assertDontSee($item->title);

$response->assertSee($item1->title);
$response->assertDontSee($item2->title);
}

public function test_task_4()
Expand All @@ -55,16 +57,17 @@ public function test_task_4()
$response = $this->get('/eloquent/task4/' . $item->id);
$response->assertStatus(200);
$response->assertViewHas('product', $item);

}

public function test_task_5() {
public function test_task_5()
{
$response = $this->post('/eloquent/task5', ['title' => 'Test']);
$response->assertRedirect();
$this->assertDatabaseHas('products', ['title' => 'Test']);
}

public function test_task_6() {
public function test_task_6()
{
$item = new Item();
$item->title = 'Old title';
$item->save();
Expand All @@ -78,7 +81,8 @@ public function test_task_6() {
$this->assertDatabaseHas('products', ['title' => 'New title']);
}

public function test_task_7() {
public function test_task_7()
{
$products = Item::factory(4)->create();
$this->assertDatabaseCount('products', 4);

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/RouteTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public function test_task_13()
private function getUserRequestData()
{
return [
'name' => 'Name '.rand(1, 1000),
'name' => 'Name ' . random_int(1, 1000),
'email' => uniqid() . '@example.com',
'password' => '123'
];
Expand Down
Loading