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