Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2522397
SupportTest.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
SupportTest.php
View Options
<?php
namespace
Tests\Feature\Controller
;
use
App\Http\Controllers\API\SupportController
;
use
Tests\TestCase
;
class
SupportTest
extends
TestCase
{
/**
* Test submitting a support request (POST /support/request)
*/
public
function
testRequest
():
void
{
$support_email
=
\config
(
'app.support_email'
);
if
(
empty
(
$support_email
))
{
$support_email
=
'support@email.tld'
;
\config
([
'app.support_email'
=>
$support_email
]);
}
// Empty request
$response
=
$this
->
post
(
"api/v4/support/request"
,
[]);
$response
->
assertStatus
(
422
);
$json
=
$response
->
json
();
$this
->
assertCount
(
2
,
$json
);
$this
->
assertSame
(
'error'
,
$json
[
'status'
]);
$this
->
assertCount
(
3
,
$json
[
'errors'
]);
$this
->
assertSame
([
'The email field is required.'
],
$json
[
'errors'
][
'email'
]);
$this
->
assertSame
([
'The summary field is required.'
],
$json
[
'errors'
][
'summary'
]);
$this
->
assertSame
([
'The body field is required.'
],
$json
[
'errors'
][
'body'
]);
// Invalid email
$post
=
[
'email'
=>
'@test.com'
,
'summary'
=>
'Test summary'
,
'body'
=>
'Test body'
,
];
$response
=
$this
->
post
(
"api/v4/support/request"
,
$post
);
$response
->
assertStatus
(
422
);
$json
=
$response
->
json
();
$this
->
assertCount
(
2
,
$json
);
$this
->
assertSame
(
'error'
,
$json
[
'status'
]);
$this
->
assertCount
(
1
,
$json
[
'errors'
]);
$this
->
assertSame
([
'The email must be a valid email address.'
],
$json
[
'errors'
][
'email'
]);
$this
->
assertCount
(
0
,
$this
->
app
->
make
(
'swift.transport'
)->
driver
()->
messages
());
// Valid input
$post
=
[
'email'
=>
'test@test.com'
,
'summary'
=>
'Test summary'
,
'body'
=>
'Test body'
,
'user'
=>
'1234567'
,
'name'
=>
'Username'
,
];
$response
=
$this
->
post
(
"api/v4/support/request"
,
$post
);
$response
->
assertStatus
(
200
);
$json
=
$response
->
json
();
$this
->
assertCount
(
2
,
$json
);
$this
->
assertSame
(
'success'
,
$json
[
'status'
]);
$this
->
assertSame
(
'Support request submitted successfully.'
,
$json
[
'message'
]);
$emails
=
$this
->
app
->
make
(
'swift.transport'
)->
driver
()->
messages
();
$expected_body
=
"ID: 1234567
\n
Name: Username
\n
Working email address: test@test.com
\n
"
.
"Subject: Test summary
\n\n
Test body"
;
$this
->
assertCount
(
1
,
$emails
);
$this
->
assertSame
(
'Test summary'
,
$emails
[
0
]->
getSubject
());
$this
->
assertSame
([
'test@test.com'
=>
'Username'
],
$emails
[
0
]->
getFrom
());
$this
->
assertSame
([
'test@test.com'
=>
'Username'
],
$emails
[
0
]->
getReplyTo
());
$this
->
assertNull
(
$emails
[
0
]->
getCc
());
$this
->
assertSame
([
$support_email
=>
null
],
$emails
[
0
]->
getTo
());
$this
->
assertSame
(
$expected_body
,
trim
(
$emails
[
0
]->
getBody
()));
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sun, Jan 11, 4:33 PM (18 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
421987
Default Alt Text
SupportTest.php (2 KB)
Attached To
Mode
R2 kolab
Attached
Detach File
Event Timeline
Log In to Comment