Skip to content

Commit

Permalink
Add tests for resource actions.
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanmcclean committed Dec 4, 2024
1 parent 4c99dcb commit d4ffc79
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tests/Http/Controllers/CP/ResourceActionControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,19 +20,17 @@ public function setUp(): void
#[Test]
public function can_run_action()
{
$post = Post::factory()->create();

$this->assertFalse(FooAction::$hasRun);

$this
->actingAs(User::make()->makeSuper()->save())
->post('/cp/runway/post/actions', [
'action' => 'foo',
'selections' => [$post->id],
'action' => 'bar',
'selections' => ['post'],
'values' => [],
])
->assertOk()
->assertJson(['message' => 'Foo action run!']);
->assertJson(['message' => 'Bar action run!']);

$this->assertTrue(FooAction::$hasRun);
}
Expand All @@ -45,23 +43,23 @@ public function can_get_bulk_actions_list()
$this
->actingAs(User::make()->makeSuper()->save())
->post('/cp/runway/post/actions/list', [
'selections' => [$post->id],
'selections' => ['post'],
])
->assertOk()
->assertJsonPath('0.handle', 'unpublish');
}
}

class FooAction extends Action
class BarAction extends Action
{
protected static $handle = 'foo';
protected static $handle = 'bar';

public static bool $hasRun = false;

public function run($items, $values)
{
static::$hasRun = true;

return 'Foo action run!';
return 'Bar action run!';
}
}

0 comments on commit d4ffc79

Please sign in to comment.