-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Notifier] Check Discord embed limitations #47859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
fabpot
merged 1 commit into
symfony:6.2
from
alamirault:feature/47688-add-discord-exception-limits
Oct 22, 2022
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
CHANGELOG | ||
========= | ||
|
||
6.2 | ||
--- | ||
|
||
* Check embed limitations | ||
|
||
5.3 | ||
--- | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordAuthorEmbedObjectTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Notifier\Bridge\Discord\Tests\Embeds; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordAuthorEmbedObject; | ||
use Symfony\Component\Notifier\Exception\LengthException; | ||
|
||
final class DiscordAuthorEmbedObjectTest extends TestCase | ||
{ | ||
public function testCanBeInstantiated() | ||
{ | ||
$author = (new DiscordAuthorEmbedObject()) | ||
->name('Doe') | ||
->url('http://ur.l') | ||
->iconUrl('http://icon-ur.l') | ||
->proxyIconUrl('http://proxy-icon-ur.l'); | ||
|
||
$this->assertSame([ | ||
'name' => 'Doe', | ||
'url' => 'http://ur.l', | ||
'icon_url' => 'http://icon-ur.l', | ||
'proxy_icon_url' => 'http://proxy-icon-ur.l', | ||
], $author->toArray()); | ||
} | ||
|
||
public function testThrowsWhenNameExceedsCharacterLimit() | ||
{ | ||
$this->expectException(LengthException::class); | ||
$this->expectExceptionMessage('Maximum length for the name is 256 characters.'); | ||
|
||
(new DiscordAuthorEmbedObject())->name(str_repeat('h', 257)); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordEmbedTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Notifier\Bridge\Discord\Tests\Embeds; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordEmbed; | ||
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFieldEmbedObject; | ||
use Symfony\Component\Notifier\Exception\LengthException; | ||
|
||
final class DiscordEmbedTest extends TestCase | ||
{ | ||
public function testCanBeInstantiated() | ||
{ | ||
$embed = (new DiscordEmbed()) | ||
->title('foo') | ||
->description('bar') | ||
->addField((new DiscordFieldEmbedObject()) | ||
->name('baz') | ||
->value('qux') | ||
); | ||
|
||
$this->assertSame([ | ||
'title' => 'foo', | ||
'description' => 'bar', | ||
'fields' => [ | ||
[ | ||
'name' => 'baz', | ||
'value' => 'qux', | ||
], | ||
], | ||
], $embed->toArray()); | ||
} | ||
|
||
public function testThrowsWhenTitleExceedsCharacterLimit() | ||
{ | ||
$this->expectException(LengthException::class); | ||
$this->expectExceptionMessage('Maximum length for the title is 256 characters.'); | ||
|
||
(new DiscordEmbed())->title(str_repeat('h', 257)); | ||
} | ||
|
||
public function testThrowsWhenDescriptionExceedsCharacterLimit() | ||
{ | ||
$this->expectException(LengthException::class); | ||
$this->expectExceptionMessage('Maximum length for the description is 4096 characters.'); | ||
|
||
(new DiscordEmbed())->description(str_repeat('h', 4097)); | ||
} | ||
|
||
public function testThrowsWhenFieldsLimitReached() | ||
{ | ||
$embed = new DiscordEmbed(); | ||
for ($i = 0; $i < 25; ++$i) { | ||
$embed->addField((new DiscordFieldEmbedObject()) | ||
->name('baz') | ||
->value('qux') | ||
); | ||
} | ||
|
||
$this->expectException(\LogicException::class); | ||
$this->expectExceptionMessage('Maximum number of fields should not exceed 25.'); | ||
|
||
$embed->addField((new DiscordFieldEmbedObject()) | ||
->name('fail') | ||
->value('fail') | ||
); | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordFieldEmbedObjectTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Notifier\Bridge\Discord\Tests\Embeds; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFieldEmbedObject; | ||
use Symfony\Component\Notifier\Exception\LengthException; | ||
|
||
final class DiscordFieldEmbedObjectTest extends TestCase | ||
{ | ||
public function testCanBeInstantiated() | ||
{ | ||
$field = (new DiscordFieldEmbedObject()) | ||
->name('foo') | ||
->value('bar') | ||
->inline(true); | ||
|
||
$this->assertSame([ | ||
'name' => 'foo', | ||
'value' => 'bar', | ||
'inline' => true, | ||
], $field->toArray()); | ||
} | ||
|
||
public function testThrowsWhenNameExceedsCharacterLimit() | ||
{ | ||
$this->expectException(LengthException::class); | ||
$this->expectExceptionMessage('Maximum length for the name is 256 characters.'); | ||
|
||
(new DiscordFieldEmbedObject())->name(str_repeat('h', 257)); | ||
} | ||
|
||
public function testThrowsWhenValueExceedsCharacterLimit() | ||
{ | ||
$this->expectException(LengthException::class); | ||
$this->expectExceptionMessage('Maximum length for the value is 1024 characters.'); | ||
|
||
(new DiscordFieldEmbedObject())->value(str_repeat('h', 1025)); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Symfony/Component/Notifier/Bridge/Discord/Tests/Embeds/DiscordFooterEmbedObjectTest.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony package. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Symfony\Component\Notifier\Bridge\Discord\Tests\Embeds; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Symfony\Component\Notifier\Bridge\Discord\Embeds\DiscordFooterEmbedObject; | ||
use Symfony\Component\Notifier\Exception\LengthException; | ||
|
||
final class DiscordFooterEmbedObjectTest extends TestCase | ||
{ | ||
public function testCanBeInstantiated() | ||
{ | ||
$author = (new DiscordFooterEmbedObject()) | ||
->text('foo') | ||
->iconUrl('http://icon-ur.l') | ||
->proxyIconUrl('http://proxy-icon-ur.l'); | ||
|
||
$this->assertSame([ | ||
'text' => 'foo', | ||
'icon_url' => 'http://icon-ur.l', | ||
'proxy_icon_url' => 'http://proxy-icon-ur.l', | ||
], $author->toArray()); | ||
} | ||
|
||
public function testThrowsWhenTextExceedsCharacterLimit() | ||
{ | ||
$this->expectException(LengthException::class); | ||
$this->expectExceptionMessage('Maximum length for the text is 2048 characters.'); | ||
|
||
(new DiscordFooterEmbedObject())->text(str_repeat('h', 2049)); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.