Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
vgwort
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
vgwort
Commits
042d4807
Commit
042d4807
authored
9 months ago
by
Alex Pott
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3447327
by alexpott: The shorttext value must be between 1 and 100 characters long
parent
e0069a76
No related branches found
Branches containing commit
Tags
2.0.0-beta12
Tags containing commit
1 merge request
!48
Fix very long titles
Pipeline
#173325
passed
9 months ago
Stage: build
Stage: validate
Stage: test
Changes
2
Pipelines
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Api/MessageText.php
+5
-2
5 additions, 2 deletions
src/Api/MessageText.php
tests/src/Unit/MessageTextTest.php
+17
-0
17 additions, 0 deletions
tests/src/Unit/MessageTextTest.php
with
22 additions
and
2 deletions
src/Api/MessageText.php
+
5
−
2
View file @
042d4807
...
...
@@ -3,6 +3,7 @@
namespace
Drupal\vgwort\Api
;
use
Drupal\Component\Render\PlainTextOutput
;
use
Drupal\Component\Utility\Unicode
;
/**
* The message text.
...
...
@@ -52,8 +53,10 @@ class MessageText implements \JsonSerializable {
* FALSE.
*/
public
function
__construct
(
string
$shorttext
,
string
$text
,
string
$text_type
=
'plainText'
,
private
readonly
bool
$lyric
=
FALSE
)
{
// @todo Is there any maximum length for this value?
$this
->
shorttext
=
PlainTextOutput
::
renderFromHtml
(
$shorttext
);
// The maximum length for the shorttext field is 100 and the minimum length
// is 1. As the title field is required we do not need to check the minimum
// length.
$this
->
shorttext
=
Unicode
::
truncate
(
PlainTextOutput
::
renderFromHtml
(
$shorttext
),
100
,
TRUE
,
FALSE
,
50
);
$this
->
addText
(
$text
,
$text_type
);
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Unit/MessageTextTest.php
+
17
−
0
View file @
042d4807
...
...
@@ -53,4 +53,21 @@ JSON;
new
MessageText
(
'The title'
,
'The text'
,
'nope'
);
}
public
function
testVeryLongTitles
():
void
{
$long_title
=
str_repeat
(
'A long title '
,
100
);
$text
=
new
MessageText
(
$long_title
,
'<strong>The text</strong>'
);
$data
=
json_decode
(
$this
->
jsonEncode
(
$text
),
TRUE
);
$this
->
assertGreaterThan
(
100
,
strlen
(
$long_title
));
$this
->
assertSame
(
97
,
strlen
(
$data
[
'shorttext'
]));
// Ensure the truncation does not break a word,
$this
->
assertMatchesRegularExpression
(
'/ long$/'
,
$data
[
'shorttext'
]);
// Ensure that long strings are truncated even if there is no work break.
$long_title
=
str_repeat
(
'enormous'
,
100
);
$text
=
new
MessageText
(
$long_title
,
'<strong>The text</strong>'
);
$data
=
json_decode
(
$this
->
jsonEncode
(
$text
),
TRUE
);
$this
->
assertGreaterThan
(
100
,
strlen
(
$long_title
));
$this
->
assertSame
(
100
,
strlen
(
$data
[
'shorttext'
]));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment