mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Fix unit test
This commit is contained in:
parent
26b8b7964e
commit
acdebcdba7
@ -128,7 +128,7 @@ class DBText extends DBString
|
|||||||
|
|
||||||
// If no $elipsis string is provided, use the default one.
|
// If no $elipsis string is provided, use the default one.
|
||||||
if ($add === false) {
|
if ($add === false) {
|
||||||
$add = $this->defaultEllipsis();
|
$add = $this->defaultEllipsis();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Split on sentences (don't remove period)
|
// Split on sentences (don't remove period)
|
||||||
@ -199,11 +199,11 @@ class DBText extends DBString
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($prefix === false) {
|
if ($prefix === false) {
|
||||||
$prefix = $this->getDefaultValue() . ' ';
|
$prefix = $this->defaultEllipsis() . ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($suffix === false) {
|
if ($suffix === false) {
|
||||||
$prefix = $this->getDefaultValue();
|
$suffix = $this->defaultEllipsis();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get raw text value, but XML encode it (as we'll be merging with HTML tags soon)
|
// Get raw text value, but XML encode it (as we'll be merging with HTML tags soon)
|
||||||
@ -270,5 +270,4 @@ class DBText extends DBString
|
|||||||
{
|
{
|
||||||
return new TextField($this->name, $title);
|
return new TextField($this->name, $title);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -301,7 +301,7 @@ class DBFieldTest extends SapphireTest
|
|||||||
foreach ($allFields as $stringField) {
|
foreach ($allFields as $stringField) {
|
||||||
$stringField = DBString::create_field($stringField, $value);
|
$stringField = DBString::create_field($stringField, $value);
|
||||||
for ($i = 1; $i < mb_strlen($value); $i++) {
|
for ($i = 1; $i < mb_strlen($value); $i++) {
|
||||||
$expected = mb_substr($value, 0, $i) . '...';
|
$expected = mb_substr($value, 0, $i) . '…';
|
||||||
$this->assertEquals($expected, $stringField->LimitCharacters($i));
|
$this->assertEquals($expected, $stringField->LimitCharacters($i));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -311,10 +311,10 @@ class DBFieldTest extends SapphireTest
|
|||||||
$stringObj = DBString::create_field($stringField, $value);
|
$stringObj = DBString::create_field($stringField, $value);
|
||||||
|
|
||||||
// Converted to plain text
|
// Converted to plain text
|
||||||
$this->assertEquals('üåäö&ÜÅÄ...', $stringObj->LimitCharacters(8));
|
$this->assertEquals('üåäö&ÜÅÄ…', $stringObj->LimitCharacters(8));
|
||||||
|
|
||||||
// But which will be safely cast in templates
|
// But which will be safely cast in templates
|
||||||
$this->assertEquals('üåäö&ÜÅÄ...', $stringObj->obj('LimitCharacters', [8])->forTemplate());
|
$this->assertEquals('üåäö&ÜÅÄ…', $stringObj->obj('LimitCharacters', [8])->forTemplate());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->assertEquals('ÅÄÖ', DBText::create_field('Text', 'åäö')->UpperCase());
|
$this->assertEquals('ÅÄÖ', DBText::create_field('Text', 'åäö')->UpperCase());
|
||||||
|
@ -49,9 +49,9 @@ class DBHTMLTextTest extends SapphireTest
|
|||||||
{
|
{
|
||||||
// HTML characters are stripped safely
|
// HTML characters are stripped safely
|
||||||
return [
|
return [
|
||||||
['The little brown fox jumped over the lazy cow.', 'The little brown fox...'],
|
['The little brown fox jumped over the lazy cow.', 'The little brown fox…'],
|
||||||
['<p>Short & Sweet</p>', 'Short & Sweet'],
|
['<p>Short & Sweet</p>', 'Short & Sweet'],
|
||||||
['This text contains & in it', 'This text contains &...'],
|
['This text contains & in it', 'This text contains &…'],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class DBHTMLTextTest extends SapphireTest
|
|||||||
// HTML is converted safely to plain text
|
// HTML is converted safely to plain text
|
||||||
return [
|
return [
|
||||||
// Standard words limited, ellipsis added if truncated
|
// Standard words limited, ellipsis added if truncated
|
||||||
['<p>Lorem ipsum dolor sit amet</p>', 24, 'Lorem ipsum dolor sit...'],
|
['<p>Lorem ipsum dolor sit amet</p>', 24, 'Lorem ipsum dolor sit…'],
|
||||||
|
|
||||||
// Complete words less than the character limit don't get truncated, ellipsis not added
|
// Complete words less than the character limit don't get truncated, ellipsis not added
|
||||||
['<p>Lorem ipsum</p>', 24, 'Lorem ipsum'],
|
['<p>Lorem ipsum</p>', 24, 'Lorem ipsum'],
|
||||||
@ -88,10 +88,10 @@ class DBHTMLTextTest extends SapphireTest
|
|||||||
['Nice & Easy', 24, 'Nice & Easy'],
|
['Nice & Easy', 24, 'Nice & Easy'],
|
||||||
|
|
||||||
// HTML is safely converted to plain text
|
// HTML is safely converted to plain text
|
||||||
['<p>Lorem ipsum dolor sit amet</p>', 24, 'Lorem ipsum dolor sit...'],
|
['<p>Lorem ipsum dolor sit amet</p>', 24, 'Lorem ipsum dolor sit…'],
|
||||||
['<p><span>Lorem ipsum dolor sit amet</span></p>', 24, 'Lorem ipsum dolor sit...'],
|
['<p><span>Lorem ipsum dolor sit amet</span></p>', 24, 'Lorem ipsum dolor sit…'],
|
||||||
['<p>Lorem ipsum</p>', 24, 'Lorem ipsum'],
|
['<p>Lorem ipsum</p>', 24, 'Lorem ipsum'],
|
||||||
['Lorem & ipsum dolor sit amet', 24, 'Lorem & ipsum dolor sit...']
|
['Lorem & ipsum dolor sit amet', 24, 'Lorem & ipsum dolor sit…']
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,12 +151,12 @@ class DBHTMLTextTest extends SapphireTest
|
|||||||
[
|
[
|
||||||
'<p>A long paragraph should be cut off if limit is set</p>',
|
'<p>A long paragraph should be cut off if limit is set</p>',
|
||||||
5,
|
5,
|
||||||
'A long paragraph should be...',
|
'A long paragraph should be…',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'<p>No matter <i>how many <b>tags</b></i> are in it</p>',
|
'<p>No matter <i>how many <b>tags</b></i> are in it</p>',
|
||||||
5,
|
5,
|
||||||
'No matter how many tags...',
|
'No matter how many tags…',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'<p>A sentence is. nicer than hard limits</p>',
|
'<p>A sentence is. nicer than hard limits</p>',
|
||||||
@ -299,7 +299,7 @@ class DBHTMLTextTest extends SapphireTest
|
|||||||
'This is some text. It is a test',
|
'This is some text. It is a test',
|
||||||
20,
|
20,
|
||||||
'test',
|
'test',
|
||||||
'... text. It is a <mark>test</mark>'
|
'… text. It is a <mark>test</mark>'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
// Retains case of original string
|
// Retains case of original string
|
||||||
@ -307,13 +307,13 @@ class DBHTMLTextTest extends SapphireTest
|
|||||||
50,
|
50,
|
||||||
'some test',
|
'some test',
|
||||||
'This is <mark>some</mark> <mark>test</mark> text.'
|
'This is <mark>some</mark> <mark>test</mark> text.'
|
||||||
. ' <mark>Test</mark> <mark>test</mark> what if you have...'
|
. ' <mark>Test</mark> <mark>test</mark> what if you have…'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'Here is some text & HTML included',
|
'Here is some text & HTML included',
|
||||||
20,
|
20,
|
||||||
'html',
|
'html',
|
||||||
'... text & <mark>HTML</mark> inc...'
|
'… text & <mark>HTML</mark> inc…'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'A dog ate a cat while looking at a Foobar',
|
'A dog ate a cat while looking at a Foobar',
|
||||||
@ -343,16 +343,16 @@ class DBHTMLTextTest extends SapphireTest
|
|||||||
<p>with about more stuff after the line break</p>',
|
<p>with about more stuff after the line break</p>',
|
||||||
35,
|
35,
|
||||||
'test',
|
'test',
|
||||||
'... really, this is a <mark>test</mark> sentence...'
|
'… really, this is a <mark>test</mark> sentence…'
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'<p>This is a lot of text before this but really, this is a test sentence</p>
|
'<p>This is a lot of text before this but really, this is a test sentence</p>
|
||||||
<p>with about more stuff after the line break</p>',
|
<p>with about more stuff after the line break</p>',
|
||||||
50,
|
50,
|
||||||
'with',
|
'with',
|
||||||
'... sentence<br />
|
'… sentence<br />
|
||||||
<br />
|
<br />
|
||||||
<mark>with</mark> about more stuff...'
|
<mark>with</mark> about more stuff…'
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -442,7 +442,7 @@ class DBHTMLTextTest extends SapphireTest
|
|||||||
);
|
);
|
||||||
// Test summary methods
|
// Test summary methods
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'Some content shortcode...',
|
'Some content shortcode…',
|
||||||
$obj->Summary(3)
|
$obj->Summary(3)
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
@ -450,7 +450,7 @@ class DBHTMLTextTest extends SapphireTest
|
|||||||
$obj->LimitSentences(1)
|
$obj->LimitSentences(1)
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'Some content shortco...',
|
'Some content shortco…',
|
||||||
$obj->LimitCharacters(20)
|
$obj->LimitCharacters(20)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -598,7 +598,7 @@ class DBHTMLTextTest extends SapphireTest
|
|||||||
$field->FirstSentence()
|
$field->FirstSentence()
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'Replaced short...',
|
'Replaced short…',
|
||||||
$field->Summary(2)
|
$field->Summary(2)
|
||||||
);
|
);
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
|
Loading…
Reference in New Issue
Block a user