|
3 | 3 | namespace Tests\Actions; |
4 | 4 |
|
5 | 5 | use Facades\Tests\Factories\EntryFactory; |
| 6 | +use Illuminate\Support\Facades\Config; |
6 | 7 | use PHPUnit\Framework\Attributes\Test; |
7 | 8 | use Statamic\Actions\Localize; |
8 | 9 | use Statamic\Facades\Collection; |
@@ -62,6 +63,95 @@ public function it_is_hidden_for_single_site_collections() |
62 | 63 | $this->assertFalse($action->visibleTo($entry)); |
63 | 64 | } |
64 | 65 |
|
| 66 | + #[Test] |
| 67 | + public function it_is_visible_to_bulk_when_any_entry_is_missing_a_localization() |
| 68 | + { |
| 69 | + $alfa = EntryFactory::id('alfa')->collection('test')->slug('alfa')->locale('en')->create(); |
| 70 | + $bravo = EntryFactory::id('bravo')->collection('test')->slug('bravo')->locale('en')->create(); |
| 71 | + EntryFactory::id('bravo-fr')->collection('test')->slug('bravo')->locale('fr')->origin('bravo')->create(); |
| 72 | + EntryFactory::id('bravo-de')->collection('test')->slug('bravo')->locale('de')->origin('bravo')->create(); |
| 73 | + |
| 74 | + $items = collect([$alfa, $bravo]); |
| 75 | + $action = (new Localize)->context(['view' => 'list'])->items($items); |
| 76 | + |
| 77 | + $this->assertTrue($action->visibleToBulk($items)); |
| 78 | + } |
| 79 | + |
| 80 | + #[Test] |
| 81 | + public function it_is_hidden_from_bulk_when_all_entries_are_fully_localized() |
| 82 | + { |
| 83 | + $alfa = EntryFactory::id('alfa')->collection('test')->slug('alfa')->locale('en')->create(); |
| 84 | + EntryFactory::id('alfa-fr')->collection('test')->slug('alfa')->locale('fr')->origin('alfa')->create(); |
| 85 | + EntryFactory::id('alfa-de')->collection('test')->slug('alfa')->locale('de')->origin('alfa')->create(); |
| 86 | + |
| 87 | + $items = collect([$alfa]); |
| 88 | + $action = (new Localize)->context(['view' => 'list'])->items($items); |
| 89 | + |
| 90 | + $this->assertFalse($action->visibleToBulk($items)); |
| 91 | + } |
| 92 | + |
| 93 | + #[Test] |
| 94 | + public function it_is_hidden_from_bulk_when_selection_includes_non_entries() |
| 95 | + { |
| 96 | + $entry = EntryFactory::id('alfa')->collection('test')->slug('alfa')->locale('en')->create(); |
| 97 | + $items = collect([$entry, 'not-an-entry']); |
| 98 | + $action = (new Localize)->context(['view' => 'list'])->items($items); |
| 99 | + |
| 100 | + $this->assertFalse($action->visibleToBulk($items)); |
| 101 | + } |
| 102 | + |
| 103 | + #[Test] |
| 104 | + public function it_is_hidden_from_bulk_when_entries_are_from_different_collections() |
| 105 | + { |
| 106 | + Collection::make('other')->sites(['en', 'fr', 'de'])->save(); |
| 107 | + |
| 108 | + $alfa = EntryFactory::id('alfa')->collection('test')->slug('alfa')->locale('en')->create(); |
| 109 | + $bravo = EntryFactory::id('bravo')->collection('other')->slug('bravo')->locale('en')->create(); |
| 110 | + $items = collect([$alfa, $bravo]); |
| 111 | + $action = (new Localize)->context(['view' => 'list'])->items($items); |
| 112 | + |
| 113 | + $this->assertFalse($action->visibleToBulk($items)); |
| 114 | + } |
| 115 | + |
| 116 | + #[Test] |
| 117 | + public function it_is_hidden_from_bulk_when_multisite_is_disabled() |
| 118 | + { |
| 119 | + Config::set('statamic.system.multisite', false); |
| 120 | + |
| 121 | + $entry = EntryFactory::id('alfa')->collection('test')->slug('alfa')->locale('en')->create(); |
| 122 | + $items = collect([$entry]); |
| 123 | + $action = (new Localize)->context(['view' => 'list'])->items($items); |
| 124 | + |
| 125 | + $this->assertFalse($action->visibleToBulk($items)); |
| 126 | + } |
| 127 | + |
| 128 | + #[Test] |
| 129 | + public function it_is_hidden_from_bulk_for_single_site_collections() |
| 130 | + { |
| 131 | + Collection::make('single')->sites(['en'])->save(); |
| 132 | + $entry = EntryFactory::id('alfa')->collection('single')->slug('alfa')->locale('en')->create(); |
| 133 | + $items = collect([$entry]); |
| 134 | + $action = (new Localize)->context(['view' => 'list'])->items($items); |
| 135 | + |
| 136 | + $this->assertFalse($action->visibleToBulk($items)); |
| 137 | + } |
| 138 | + |
| 139 | + #[Test] |
| 140 | + public function it_authorizes_users_who_can_edit_the_entry() |
| 141 | + { |
| 142 | + $this->setTestRoles([ |
| 143 | + 'editor' => ['edit test entries', 'access en site'], |
| 144 | + 'viewer' => ['view test entries', 'access en site'], |
| 145 | + ]); |
| 146 | + |
| 147 | + $userWithPermission = tap(User::make()->assignRole('editor'))->save(); |
| 148 | + $userWithoutPermission = tap(User::make()->assignRole('viewer'))->save(); |
| 149 | + $entry = EntryFactory::id('alfa')->collection('test')->slug('alfa')->locale('en')->create(); |
| 150 | + |
| 151 | + $this->assertTrue((new Localize)->authorize($userWithPermission, $entry)); |
| 152 | + $this->assertFalse((new Localize)->authorize($userWithoutPermission, $entry)); |
| 153 | + } |
| 154 | + |
65 | 155 | #[Test] |
66 | 156 | public function it_localizes_entries_missing_the_selected_site() |
67 | 157 | { |
@@ -93,4 +183,21 @@ public function it_only_offers_sites_that_are_missing_for_selected_entries() |
93 | 183 | 'de' => 'German', |
94 | 184 | ], $siteField->get('options')); |
95 | 185 | } |
| 186 | + |
| 187 | + #[Test] |
| 188 | + public function it_rejects_sites_that_are_not_offered() |
| 189 | + { |
| 190 | + $en = EntryFactory::id('alfa')->collection('test')->slug('alfa')->locale('en')->create(); |
| 191 | + EntryFactory::id('alfa-fr')->collection('test')->slug('alfa')->locale('fr')->origin('alfa')->create(); |
| 192 | + |
| 193 | + $action = (new Localize)->context(['view' => 'list'])->items([$en]); |
| 194 | + |
| 195 | + $this->assertFalse( |
| 196 | + $action->fields()->addValues(['site' => 'fr'])->validator()->validator()->passes() |
| 197 | + ); |
| 198 | + |
| 199 | + $this->assertTrue( |
| 200 | + $action->fields()->addValues(['site' => 'de'])->validator()->validator()->passes() |
| 201 | + ); |
| 202 | + } |
96 | 203 | } |
0 commit comments