11<?php
22
3+ require_once (__DIR__ . '/../../../vendor/autoload.php ' );
4+
35import ('lib.pkp.tests.PKPTestCase ' );
46import ('plugins.generic.thoth.classes.factories.ThothAbstractFactory ' );
57
68class ThothAbstractFactoryTest extends PKPTestCase
79{
8- public function testCreateFromPublicationWrapsAbstractWithoutParagraph ()
10+ public function testCreateFromPublicationSendsAbstractWithoutParagraphUnchanged ()
911 {
1012 $ publication = new class () {
1113 public function getData ($ key )
@@ -22,7 +24,7 @@ public function getData($key)
2224 $ factory = new ThothAbstractFactory ();
2325 $ thothAbstracts = $ factory ->createFromPublication ($ publication , 'work-id ' , 'en_US ' );
2426
25- $ this ->assertSame ('<p> English abstract</p> ' , $ thothAbstracts ['EN_US ' ]->getContent ());
27+ $ this ->assertSame ('English abstract ' , $ thothAbstracts ['EN_US ' ]->getContent ());
2628 }
2729
2830 public function testCreateFromPublicationPreservesAbstractAlreadyWrappedInParagraph ()
@@ -44,4 +46,119 @@ public function getData($key)
4446
4547 $ this ->assertSame ('<p>English abstract</p> ' , $ thothAbstracts ['EN_US ' ]->getContent ());
4648 }
49+
50+ public function testCreateFromPublicationMovesListsOutsideParagraphs ()
51+ {
52+ $ publication = new class () {
53+ public function getData ($ key )
54+ {
55+ $ values = [
56+ 'locale ' => 'en_US ' ,
57+ 'abstract ' => ['en_US ' => 'Intro<ul><li>First item</li></ul>Outro ' ],
58+ ];
59+
60+ return $ values [$ key ] ?? null ;
61+ }
62+ };
63+
64+ $ factory = new ThothAbstractFactory ();
65+ $ thothAbstracts = $ factory ->createFromPublication ($ publication , 'work-id ' , 'en_US ' );
66+
67+ $ this ->assertSame (
68+ '<p>Intro</p><ul><li>First item</li></ul><p>Outro</p> ' ,
69+ $ thothAbstracts ['EN_US ' ]->getContent ()
70+ );
71+ }
72+
73+ public function testCreateFromPublicationMovesNestedListsOutsideParagraphs ()
74+ {
75+ $ publication = new class () {
76+ public function getData ($ key )
77+ {
78+ $ values = [
79+ 'locale ' => 'en_US ' ,
80+ 'abstract ' => ['en_US ' => '<p>Intro<ul><li>First item</li></ul>Outro</p> ' ],
81+ ];
82+
83+ return $ values [$ key ] ?? null ;
84+ }
85+ };
86+
87+ $ factory = new ThothAbstractFactory ();
88+ $ thothAbstracts = $ factory ->createFromPublication ($ publication , 'work-id ' , 'en_US ' );
89+
90+ $ this ->assertSame (
91+ '<p>Intro</p><ul><li>First item</li></ul><p>Outro</p> ' ,
92+ $ thothAbstracts ['EN_US ' ]->getContent ()
93+ );
94+ }
95+
96+ public function testCreateFromPublicationConvertsBreaksToParagraphs ()
97+ {
98+ $ publication = new class () {
99+ public function getData ($ key )
100+ {
101+ $ values = [
102+ 'locale ' => 'en_US ' ,
103+ 'abstract ' => ['en_US ' => '<p>First line<br />Second line</p> ' ],
104+ ];
105+
106+ return $ values [$ key ] ?? null ;
107+ }
108+ };
109+
110+ $ factory = new ThothAbstractFactory ();
111+ $ thothAbstracts = $ factory ->createFromPublication ($ publication , 'work-id ' , 'en_US ' );
112+
113+ $ this ->assertSame ('<p>First line</p><p>Second line</p> ' , $ thothAbstracts ['EN_US ' ]->getContent ());
114+ }
115+
116+ public function testCreateFromPublicationRemovesBreaksInsideInlineMarkup ()
117+ {
118+ $ publication = new class () {
119+ public function getData ($ key )
120+ {
121+ $ values = [
122+ 'locale ' => 'en_US ' ,
123+ 'abstract ' => ['en_US ' => '<p><strong>First<br />Second</strong></p> ' ],
124+ ];
125+
126+ return $ values [$ key ] ?? null ;
127+ }
128+ };
129+
130+ $ factory = new ThothAbstractFactory ();
131+ $ thothAbstracts = $ factory ->createFromPublication ($ publication , 'work-id ' , 'en_US ' );
132+
133+ $ this ->assertSame ('<p><strong>First Second</strong></p> ' , $ thothAbstracts ['EN_US ' ]->getContent ());
134+ }
135+
136+ public function testCreateFromPublicationRemovesOmpPresentationWrapper ()
137+ {
138+ $ publication = new class () {
139+ public function getData ($ key )
140+ {
141+ $ values = [
142+ 'locale ' => 'en_US ' ,
143+ 'abstract ' => [
144+ 'en_US ' => '<h2 class="label">Synopsis</h2><div class="value"> '
145+ . '<p>Publisher<br />Address<br />Country</p> '
146+ . '<p><strong>Open</strong> <a href="https://example.com">platform</a></p> '
147+ . '</div> ' ,
148+ ],
149+ ];
150+
151+ return $ values [$ key ] ?? null ;
152+ }
153+ };
154+
155+ $ factory = new ThothAbstractFactory ();
156+ $ thothAbstracts = $ factory ->createFromPublication ($ publication , 'work-id ' , 'en_US ' );
157+
158+ $ this ->assertSame (
159+ '<p>Publisher</p><p>Address</p><p>Country</p> '
160+ . '<p><strong>Open</strong> <a href="https://example.com">platform</a></p> ' ,
161+ $ thothAbstracts ['EN_US ' ]->getContent ()
162+ );
163+ }
47164}
0 commit comments