Skip to content

Commit

Permalink
Laravel 10 + Honeypot/Newsletter data fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalbaljet committed Nov 13, 2023
1 parent f9906a9 commit 1e2fa9a
Show file tree
Hide file tree
Showing 8 changed files with 1,264 additions and 3,236 deletions.
12 changes: 9 additions & 3 deletions app/Http/Controllers/NewsletterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

use Illuminate\Http\Request;
use ProtoneMedia\Splade\Facades\Toast;
use Spatie\Honeypot\Honeypot;
use Spatie\MailcoachSdk\Facades\Mailcoach;

class NewsletterController
{
public function create()
public function create(Honeypot $honeypot)
{
return view('newsletter', []);
return view('newsletter', [
'honeypot' => [
$honeypot->nameFieldName() => '',
$honeypot->validFromFieldName() => $honeypot->encryptedValidFrom(),
],
]);
}

public function store(Request $request)
Expand All @@ -21,7 +27,7 @@ public function store(Request $request)

Mailcoach::createSubscriber(
emailListUuid: config('mailcoach-sdk.list'),
attributes: [$data + ['tags' => 'Splade.dev']]
attributes: $data + ['tags' => ['Splade.dev']]
);

Toast::success('You have been subscribed to the newsletter!');
Expand Down
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"license": "MIT",
"require": {
"php": "^8.1.0",
"graham-campbell/markdown": "^14.0",
"graham-campbell/markdown": "^15.0",
"guzzlehttp/guzzle": "^7.2",
"laravel/framework": "^9.19",
"laravel/framework": "^10.0",
"laravel/tinker": "^2.7",
"predis/predis": "^2.0",
"protonemedia/laravel-mixins": "^3.3",
Expand All @@ -31,8 +31,8 @@
"laravel/pint": "^1.2",
"mockery/mockery": "^1.4.4",
"nunomaduro/collision": "^6.1",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ignition": "^1.0"
"phpunit/phpunit": "^10.0",
"spatie/laravel-ignition": "^2.0"
},
"autoload": {
"psr-4": {
Expand Down
833 changes: 388 additions & 445 deletions composer.lock

Large diffs are not rendered by default.

3,599 changes: 821 additions & 2,778 deletions package-lock.json

Large diffs are not rendered by default.

16 changes: 11 additions & 5 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Feature">
<directory>tests/Feature</directory>
</testsuite>
</testsuites>
<coverage processUncoveredFiles="true">
<source>
<include>
<directory suffix=".php">./app</directory>
<directory>app</directory>
</include>
</coverage>
</source>
<php>
<env name="APP_ENV" value="testing"/>
<env name="BCRYPT_ROUNDS" value="4"/>
Expand All @@ -20,5 +23,8 @@
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="TELESCOPE_ENABLED" value="false"/>
<env name="MAILCOACH_API_TOKEN" value="mailcoach-token" />
<env name="MAILCOACH_API_ENDPOINT" value="mailcoach-endpoint" />
<env name="MAILCOACH_LIST_UUID" value="mailcoach-list" />
</php>
</phpunit>
1 change: 1 addition & 0 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class="absolute z-10 md:transform md:-rotate-45 bg-gradient-to-r from-[#632bd1]
<a class="inline-block text-center rounded-md border border-transparent bg-[#632bd1] px-4 py-2 text-sm font-medium text-white shadow-md transition hover:bg-[#4D21A2] focus:outline-none focus:ring-2 focus:ring-[#7B4BDA] focus:ring-offset-2" target="_blank" href="https://www.youtube.com/watch?v=9V9BUHtvwXI">Introduction Video</a>
<a class="inline-block text-center rounded-md border border-transparent bg-[#632bd1] px-4 py-2 text-sm font-medium text-white shadow-md transition hover:bg-[#4D21A2] focus:outline-none focus:ring-2 focus:ring-[#7B4BDA] focus:ring-offset-2" target="_blank" href="https://discord.gg/qGJ4MkMQWm">Discord</a>
<a class="inline-block text-center rounded-md border border-transparent bg-[#632bd1] px-4 py-2 text-sm font-medium text-white shadow-md transition hover:bg-[#4D21A2] focus:outline-none focus:ring-2 focus:ring-[#7B4BDA] focus:ring-offset-2" target="_blank" href="https://twitter.com/pascalbaljet">Twitter</a>
<Link modal class="inline-block text-center rounded-md border border-transparent bg-[#632bd1] px-4 py-2 text-sm font-medium text-white shadow-md transition hover:bg-[#4D21A2] focus:outline-none focus:ring-2 focus:ring-[#7B4BDA] focus:ring-offset-2" target="_blank" href="{{ route('newsletter.create') }}">Newsletter</Link>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/newsletter.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<div class="min-h-screen flex items-center justify-center">
<div class="max-w-2xl mx-auto">
<x-splade-modal max-width="lg">
<x-splade-form class="space-y-4" :action="route('newsletter.store')">
<x-splade-form class="space-y-4" :default="$honeypot" :action="route('newsletter.store')">
<h1 class="text-2xl font-bold">
Subscribe to the Splade Newsletter!
</h1>
Expand Down
29 changes: 29 additions & 0 deletions tests/Feature/NewsletterTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace Tests\Feature;

use Spatie\MailcoachSdk\Facades\Mailcoach;
use Tests\TestCase;

class NewsletterTest extends TestCase
{
/** @test */
public function it_allows_you_to_subscribe_to_the_newsletter()
{
config(['honeypot.enabled' => false]);

Mailcoach::shouldReceive('createSubscriber')
->once()
->with(
'mailcoach-list',
[
'email' => '[email protected]',
'tags' => ['Splade.dev'],
],
);

$this->post(route('newsletter.store'), [
'email' => '[email protected]',
])->assertRedirect(route('home'));
}
}

0 comments on commit 1e2fa9a

Please sign in to comment.