Exemplo n.º 1
0
 /**
  * Создание закупки
  */
 public function testCreatePurchase()
 {
     $purchase_name = 'Наименование тестовой закупки';
     $purchase_description = 'Описание тестовой закупки';
     $pricing_grid_id = 12;
     $expiration_time = date('Y-m-d H:i:s', time() + 3600 * 24 * 7);
     $purchase_model = \App\Models\PurchaseModel::create(['name' => $purchase_name, 'description' => $purchase_description, 'pricing_grid_id' => $pricing_grid_id, 'expiration_time' => $expiration_time]);
     $this->assertInstanceOf('\\App\\Models\\PurchaseModel', $purchase_model);
     $this->assertEquals($purchase_name, $purchase_model->name);
     $this->assertEquals($purchase_description, $purchase_model->description);
     $this->assertEquals($pricing_grid_id, $purchase_model->pricing_grid_id);
     $this->assertEquals($expiration_time, $purchase_model->expiration_time);
     self::$purchase_id = (int) $purchase_model->id;
 }
 public function postSave(Request $request)
 {
     $post_fields_arr = $request->all();
     $validator = \Validator::make($post_fields_arr, ['name' => 'required|max:255', 'description' => 'max:255', 'expiration_time' => 'required']);
     if ($validator->fails()) {
         return 'Невалидные данные';
     }
     $post_fields_arr['user_id'] = $this->user->id;
     if (isset($post_fields_arr['id'])) {
         $purchase_model = \App\Models\PurchaseModel::find($post_fields_arr['id']);
         if (!$purchase_model) {
             return 'Ошибка: нет закупки с таким ID - ' . $post_fields_arr['id'];
         }
         $purchase_model->name = $post_fields_arr['name'];
         $purchase_model->description = $post_fields_arr['description'];
         $purchase_model->save();
     } else {
         \App\Models\PurchaseModel::create($post_fields_arr);
     }
     return redirect('/seller/purchases');
 }