Skip to content

Commit

Permalink
Fix failing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Dec 19, 2024
1 parent 17a37f1 commit eb4fc89
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
1 change: 0 additions & 1 deletion src/Fieldtypes/ImportMappingsFieldtype.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ public function extraRules(): array

return collect($this->field->value())
->reject(fn ($row) => empty($row['key']))
->filter(fn ($row) => $fields->has($row['key']))
->flatMap(function (array $row, string $field) use ($fields) {
$rules = $fields
->get($field)
Expand Down
2 changes: 1 addition & 1 deletion src/Imports/Blueprint.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function (string $attribute, mixed $value, Closure $fail) {
'type' => 'radio',
'display' => __('Unique Field'),
'instructions' => __('importer::messages.unique_field_instructions'),
'options' => $import?->mappingFields()->all()
'options' => $import?->destinationBlueprint()->fields()->all()
->filter(fn ($field) => in_array($field->type(), ['text', 'integer', 'slug']))
->map(fn ($field) => ['key' => $field->handle(), 'value' => $field->display()])
->values(),
Expand Down
25 changes: 23 additions & 2 deletions tests/Imports/UpdateImportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Storage;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Facades\Blink;
use Statamic\Facades\Collection;
use Statamic\Facades\Taxonomy;
use Statamic\Facades\User;
Expand Down Expand Up @@ -229,9 +230,19 @@ public function validation_error_is_thrown_for_terms_import_without_slug_mapping
{
Taxonomy::make('tags')->save();

Storage::disk('local')->put('statamic/imports/tags/tags.csv', '');

$import = Import::make()->name('Users')->config([
'type' => 'csv',
'path' => Storage::disk('local')->path('statamic/imports/tags/tags.csv'),
'destination' => ['type' => 'terms', 'taxonomy' => 'tags', 'blueprint' => 'tag'],
]);

$import->save();

$this
->actingAs(User::make()->makeSuper()->save())
->patch("/cp/utilities/importer/{$this->import->id()}", [
->patch("/cp/utilities/importer/{$import->id()}", [
'name' => 'Posts',
'file' => ['posts.csv'],
'destination' => ['type' => 'terms', 'taxonomy' => ['tags'], 'blueprint' => 'tag'],
Expand All @@ -258,9 +269,19 @@ public function validation_error_is_thrown_for_users_import_without_email_mappin
],
]);

Storage::disk('local')->put('statamic/imports/users/users.csv', '');

$import = Import::make()->name('Users')->config([
'type' => 'csv',
'path' => Storage::disk('local')->path('statamic/imports/users/users.csv'),
'destination' => ['type' => 'users'],
]);

$import->save();

$this
->actingAs(User::make()->makeSuper()->save())
->patch("/cp/utilities/importer/{$this->import->id()}", [
->patch("/cp/utilities/importer/{$import->id()}", [
'name' => 'Posts',
'file' => ['posts.csv'],
'destination' => ['type' => 'users'],
Expand Down

0 comments on commit eb4fc89

Please sign in to comment.