|
6 | 6 | use Backpack\CRUD\Tests\Unit\Models\Bang; |
7 | 7 | use Backpack\CRUD\Tests\Unit\Models\Comet; |
8 | 8 | use Backpack\CRUD\Tests\Unit\Models\Planet; |
| 9 | +use Backpack\CRUD\Tests\Unit\Models\PlanetNonNullable; |
9 | 10 | use Backpack\CRUD\Tests\Unit\Models\Universe; |
10 | 11 | use Backpack\CRUD\Tests\Unit\Models\User; |
11 | 12 | use Faker\Factory; |
@@ -912,6 +913,13 @@ public function testHasManyCreatableRelationship() |
912 | 913 | $this->assertEquals($inputData['universes'][0]['title'], $entry->fresh()->universes->first()->title); |
913 | 914 | $this->assertEquals(3, $entry->fresh()->universes->first()->id); |
914 | 915 | $this->assertEquals(1, Universe::all()->count()); |
| 916 | + |
| 917 | + $inputData['universes'] = null; |
| 918 | + |
| 919 | + $this->crudPanel->update($entry->id, $inputData); |
| 920 | + |
| 921 | + $this->assertEquals(0, count($entry->fresh()->universes)); |
| 922 | + $this->assertEquals(0, Universe::all()->count()); |
915 | 923 | } |
916 | 924 |
|
917 | 925 | public function testHasManySelectableRelationshipWithoutForceDelete() |
@@ -1082,4 +1090,37 @@ public function testHasManySelectableRelationshipNonNullableForeignKeyAndDefault |
1082 | 1090 | $this->assertCount(2, $comets); |
1083 | 1091 | $this->assertEquals(0, $comets->first()->user_id); |
1084 | 1092 | } |
| 1093 | + |
| 1094 | + public function testHasManySelectableRelationshipNonNullable() |
| 1095 | + { |
| 1096 | + $this->crudPanel->setModel(User::class); |
| 1097 | + $this->crudPanel->addFields($this->userInputFieldsNoRelationships, 'both'); |
| 1098 | + $this->crudPanel->addField([ |
| 1099 | + 'name' => 'planetsNonNullable', |
| 1100 | + 'force_delete' => false, |
| 1101 | + 'fallback_id' => false, |
| 1102 | + ], 'both'); |
| 1103 | + |
| 1104 | + $faker = Factory::create(); |
| 1105 | + $inputData = [ |
| 1106 | + 'name' => $faker->name, |
| 1107 | + 'email' => $faker->safeEmail, |
| 1108 | + 'password' => bcrypt($faker->password()), |
| 1109 | + 'remember_token' => null, |
| 1110 | + 'planetsNonNullable' => [1, 2], |
| 1111 | + ]; |
| 1112 | + |
| 1113 | + $entry = $this->crudPanel->create($inputData); |
| 1114 | + |
| 1115 | + $this->assertCount(2, $entry->planetsNonNullable); |
| 1116 | + |
| 1117 | + $inputData['planetsNonNullable'] = null; |
| 1118 | + |
| 1119 | + $this->crudPanel->update($entry->id, $inputData); |
| 1120 | + |
| 1121 | + $this->assertCount(0, $entry->fresh()->planetsNonNullable); |
| 1122 | + |
| 1123 | + $planets = PlanetNonNullable::all(); |
| 1124 | + $this->assertCount(0, $planets); |
| 1125 | + } |
1085 | 1126 | } |
0 commit comments