Skip to content
Open
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
34 changes: 16 additions & 18 deletions tests/Entries/EntryRepositoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ public function it_updates_the_order_of_all_entries_in_a_collection()
(new Entry)->id(3)->collection($collection)->slug('charlie')->save();
(new Entry)->id(4)->collection($collection)->slug('delta')->save();

$orderBeforeStructureSave = EntryModel::all()->mapWithKeys(fn ($e) => [$e->id => $e->order])->all();

$collection->structure()->in('en')->tree([
['entry' => 4],
['entry' => 2],
Expand All @@ -103,12 +105,10 @@ public function it_updates_the_order_of_all_entries_in_a_collection()

// Assert that the order is unchanged, to make sure that saving
// the structure isn't what caused the order to be updated.
$this->assertEquals([
1 => 1,
2 => 1,
3 => 1,
4 => 1,
], EntryModel::all()->mapWithKeys(fn ($e) => [$e->id => $e->order])->all());
$this->assertEquals(
$orderBeforeStructureSave,
EntryModel::all()->mapWithKeys(fn ($e) => [$e->id => $e->order])->all()
);

(new EntryRepository(new Stache))->updateOrders($collection);

Expand All @@ -134,6 +134,8 @@ public function it_updates_the_order_of_specific_entries_in_a_collection()
(new Entry)->id(3)->collection($collection)->slug('charlie')->save();
(new Entry)->id(4)->collection($collection)->slug('delta')->save();

$orderBeforeStructureSave = EntryModel::all()->mapWithKeys(fn ($e) => [$e->id => $e->order])->all();

$collection->structure()->in('en')->tree([
['entry' => 4],
['entry' => 2],
Expand All @@ -143,21 +145,17 @@ public function it_updates_the_order_of_specific_entries_in_a_collection()

// Assert that the order is unchanged, to make sure that saving
// the structure isn't what caused the order to be updated.
$this->assertEquals([
1 => 1,
2 => 1,
3 => 1,
4 => 1,
], EntryModel::all()->mapWithKeys(fn ($e) => [$e->id => $e->order])->all());
$this->assertEquals(
$orderBeforeStructureSave,
EntryModel::all()->mapWithKeys(fn ($e) => [$e->id => $e->order])->all()
);

(new EntryRepository(new Stache))->updateOrders($collection, [2, 3]);

$this->assertEquals([
1 => 1,
2 => 2,
3 => 4,
4 => 1,
], EntryModel::all()->mapWithKeys(fn ($e) => [$e->id => $e->order])->all());
$this->assertEquals(
[2 => 2, 3 => 4] + $orderBeforeStructureSave,
EntryModel::all()->mapWithKeys(fn ($e) => [$e->id => $e->order])->all()
);
}

#[Test]
Expand Down