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