diff --git a/src/OnboardingSteps.php b/src/OnboardingSteps.php index 09369c0..cf7e974 100644 --- a/src/OnboardingSteps.php +++ b/src/OnboardingSteps.php @@ -14,6 +14,11 @@ public function addStep(string $title, string $model = null): OnboardingStep { $step = new OnboardingStep($title); + return $this->addingStep($step, $model); + } + + public function addingStep(OnboardingStep $step, string $model = null): OnboardingStep + { if ($model && new $model() instanceof Onboardable) { return $this->steps[$model][] = $step; } diff --git a/tests/OnboardTest.php b/tests/OnboardTest.php index 934a013..9129bef 100644 --- a/tests/OnboardTest.php +++ b/tests/OnboardTest.php @@ -2,6 +2,7 @@ use Spatie\Onboard\OnboardingManager; +use Spatie\Onboard\OnboardingStep; use Spatie\Onboard\OnboardingSteps; use Spatie\Onboard\Tests\Team; use Spatie\Onboard\Tests\User; @@ -294,3 +295,50 @@ ->user_name->toBe($this->user->name) ->title->tobe('Step 1'); }); + +test('can add step objects', function () { + $onboardingSteps = new OnboardingSteps(); + $firstStep = (new OnboardingStep('Step 1')) + ->link('/some/url') + ->cta('Test This!'); + $secondStep = (new class ('Step 2') extends OnboardingStep {}) + ->link('/another/url') + ->cta('Test That!'); + $onboardingSteps->addingStep($firstStep); + $onboardingSteps->addingStep($secondStep); + + $onboarding = new OnboardingManager($this->user, $onboardingSteps); + + $step = $onboarding->steps()->first(); + + expect($step) + ->title->toBe('Step 1') + ->cta->toBe('Test This!'); + + expect($onboarding->steps()->last()) + ->title->toBe('Step 2') + ->cta->toBe('Test That!'); + + $firstStep->title = 'Step 11'; + $secondStep->title = 'Step 22'; + + expect($step) + ->title->toBe('Step 11') + ->toArray()->toBe([ + 'title' => 'Step 11', + 'link' => '/some/url', + 'cta' => 'Test This!', + 'complete' => false, + 'excluded' => false, + ]); + + expect($onboarding->steps()->last()) + ->title->toBe('Step 22') + ->toArray()->toBe([ + 'title' => 'Step 22', + 'link' => '/another/url', + 'cta' => 'Test That!', + 'complete' => false, + 'excluded' => false, + ]); +});