@@ 46-55 (lines=10) @@ | ||
43 | } |
|
44 | ||
45 | /** @test */ |
|
46 | public function it_can_set_a_new_order_by_custom_column() |
|
47 | { |
|
48 | $newOrder = Collection::make(Dummy::all()->pluck('custom_column_sort'))->shuffle()->toArray(); |
|
49 | ||
50 | Dummy::setNewOrderByCustomColumn('custom_column_sort', $newOrder); |
|
51 | ||
52 | foreach (Dummy::orderBy('order_column')->get() as $i => $dummy) { |
|
53 | $this->assertEquals($newOrder[$i], $dummy->custom_column_sort); |
|
54 | } |
|
55 | } |
|
56 | ||
57 | /** @test */ |
|
58 | public function it_can_set_a_new_order_from_collection() |
|
@@ 70-79 (lines=10) @@ | ||
67 | } |
|
68 | ||
69 | /** @test */ |
|
70 | public function it_can_set_a_new_order_by_custom_column_from_collection() |
|
71 | { |
|
72 | $newOrder = Collection::make(Dummy::all()->pluck('custom_column_sort'))->shuffle(); |
|
73 | ||
74 | Dummy::setNewOrderByCustomColumn('custom_column_sort', $newOrder); |
|
75 | ||
76 | foreach (Dummy::orderBy('order_column')->get() as $i => $dummy) { |
|
77 | $this->assertEquals($newOrder[$i], $dummy->custom_column_sort); |
|
78 | } |
|
79 | } |
|
80 | ||
81 | /** @test */ |
|
82 | public function it_can_set_a_new_order_with_trashed_models() |
|
@@ 118-131 (lines=14) @@ | ||
115 | } |
|
116 | ||
117 | /** @test */ |
|
118 | public function it_can_set_a_new_order_without_trashed_models() |
|
119 | { |
|
120 | $this->setUpSoftDeletes(); |
|
121 | ||
122 | DummyWithSoftDeletes::first()->delete(); |
|
123 | ||
124 | $newOrder = Collection::make(DummyWithSoftDeletes::pluck('id'))->shuffle(); |
|
125 | ||
126 | DummyWithSoftDeletes::setNewOrder($newOrder); |
|
127 | ||
128 | foreach (DummyWithSoftDeletes::orderBy('order_column')->get() as $i => $dummy) { |
|
129 | $this->assertEquals($newOrder[$i], $dummy->id); |
|
130 | } |
|
131 | } |
|
132 | ||
133 | /** @test */ |
|
134 | public function it_can_set_a_new_order_by_custom_column_without_trashed_models() |
|
@@ 134-147 (lines=14) @@ | ||
131 | } |
|
132 | ||
133 | /** @test */ |
|
134 | public function it_can_set_a_new_order_by_custom_column_without_trashed_models() |
|
135 | { |
|
136 | $this->setUpSoftDeletes(); |
|
137 | ||
138 | DummyWithSoftDeletes::first()->delete(); |
|
139 | ||
140 | $newOrder = Collection::make(DummyWithSoftDeletes::pluck('custom_column_sort'))->shuffle(); |
|
141 | ||
142 | DummyWithSoftDeletes::setNewOrderByCustomColumn('custom_column_sort', $newOrder); |
|
143 | ||
144 | foreach (DummyWithSoftDeletes::orderBy('order_column')->get() as $i => $dummy) { |
|
145 | $this->assertEquals($newOrder[$i], $dummy->custom_column_sort); |
|
146 | } |
|
147 | } |
|
148 | ||
149 | /** @test */ |
|
150 | public function it_will_determine_to_sort_when_creating_if_sortable_attribute_does_not_exist() |