1818
1919namespace PhpOffice \PhpWordTests \Writer \RTF ;
2020
21+ use PhpOffice \PhpWord \Element \Footer ;
2122use PhpOffice \PhpWord \IOFactory ;
23+ use PhpOffice \PhpWord \PhpWord ;
2224use PhpOffice \PhpWord \Writer \RTF ;
2325
2426/**
@@ -39,4 +41,96 @@ public function testSample11(): void
3941 $ expected = '\strike even ' ;
4042 self ::assertStringContainsString ($ expected , $ content );
4143 }
44+
45+ public function testBorderColor (): void
46+ {
47+ $ phpWord = new PhpWord ();
48+ $ section = $ phpWord ->addSection ();
49+ $ section ->getStyle ()
50+ ->setBorderSize (5 )
51+ ->setBorderColor ('FF00FF ' );
52+ $ writer = new RTF ($ phpWord );
53+ $ content = $ writer ->getContent ();
54+ $ expected = '{\colortbl;\red255\green0\blue255;} ' ;
55+ self ::assertStringContainsString ($ expected , $ content );
56+ }
57+
58+ public function testFooters (): void
59+ {
60+ $ phpWord = new PhpWord ();
61+ $ section = $ phpWord ->addSection ();
62+ $ phpWord ->getSettings ()->setEvenAndOddHeaders (true );
63+ $ section = $ phpWord ->addSection ();
64+ $ footerFirst = $ section ->addFooter (Footer::FIRST );
65+ $ textRunFirst = $ footerFirst ->addTextRun ();
66+ $ textRunFirst ->addText ('First Footer ' );
67+ $ footerEven = $ section ->addFooter (Footer::EVEN );
68+ $ textRunEven = $ footerEven ->addTextRun ();
69+ $ textRunEven ->addText ('Even Footer ' );
70+ $ footerAuto = $ section ->addFooter (Footer::AUTO );
71+ $ textRunAuto = $ footerAuto ->addTextRun ();
72+ $ textRunAuto ->addText ('Odd Footer ' );
73+ $ section ->addText ('This should be page 1 ' );
74+ $ section ->addPageBreak ();
75+ $ section ->addText ('This should be page 2 ' );
76+ $ section ->addPageBreak ();
77+ $ section ->addText ('This should be page 3 ' );
78+ $ section ->addPageBreak ();
79+ $ section ->addText ('This should be page 4 ' );
80+ $ section ->addPageBreak ();
81+ $ section ->addText ('This should be page 5 ' );
82+ $ writer = new RTF ($ phpWord );
83+ $ content = $ writer ->getContent ();
84+ $ expected = '{\footerf\pard\nowidctlpar {{\cf0\f0 First Footer}}\par ' ;
85+ self ::assertStringContainsString ($ expected , $ content );
86+ $ expected = '{\footerl\pard\nowidctlpar {{\cf0\f0 Even Footer}}\par ' ;
87+ self ::assertStringContainsString ($ expected , $ content );
88+ $ expected = '{\footerr\pard\nowidctlpar {{\cf0\f0 Odd Footer}}\par ' ;
89+ self ::assertStringContainsString ($ expected , $ content );
90+ }
91+
92+ public function testPageBreakBeforeTextRun (): void
93+ {
94+ $ phpWord = new PhpWord ();
95+ $ phpWord ->addParagraphStyle ('pbb ' , [
96+ 'pageBreakBefore ' => true ,
97+ ]);
98+ $ section1 = $ phpWord ->addSection ();
99+ $ textRun1 = $ section1 ->addTextRun ();
100+ $ textRun1 ->addText ('Section 1 Paragraph 1 ' );
101+ $ section2 = $ phpWord ->addSection ();
102+ $ textRun2 = $ section2 ->addTextRun ('pbb ' );
103+ $ textRun2 ->addText ('Section 2 Paragraph 1 ' );
104+ $ textRun3 = $ section2 ->addTextRun ('pbb ' );
105+ $ textRun3 ->addText ('Section 2 Paragraph 2 ' );
106+ $ writer = new RTF ($ phpWord );
107+ $ content = $ writer ->getContent ();
108+ $ expected = '\pard\nowidctlpar {{\cf0\f0 Section 2 Paragraph 1}}\par ' ;
109+ self ::assertStringContainsString ($ expected , $ content , 'no page break ' );
110+ $ expected = '\pard\nowidctlpar \page{{\cf0\f0 Section 2 Paragraph 2}}\par ' ;
111+ self ::assertStringContainsString ($ expected , $ content , 'page break ' );
112+ }
113+
114+ public function testPageBreakBeforeTitle (): void
115+ {
116+ $ phpWord = new PhpWord ();
117+ $ pbb = ['pageBreakBefore ' => true ];
118+ $ phpWord ->addTitleStyle (
119+ 1 ,
120+ ['bold ' => true ],
121+ $ pbb
122+ );
123+ $ section1 = $ phpWord ->addSection ();
124+ $ textRun1 = $ section1 ->addTextRun ();
125+ $ textRun1 ->addText ('Section 1 Paragraph 1 ' );
126+ $ section2 = $ phpWord ->addSection ();
127+ $ section2 ->addTitle ('Heading1 with pbb first element in section ' , 1 );
128+ $ section2 ->addTitle ('Heading1 with pbb not first element in section ' , 1 );
129+ $ writer = new RTF ($ phpWord );
130+ $ content = $ writer ->getContent ();
131+ $ expected = '\pard\nowidctlpar {\outlinelevel0{\cf0\f0\b Heading1 with pbb first element in section} ' ;
132+ self ::assertStringContainsString ($ expected , $ content , 'no page break ' );
133+ $ expected = '\pard\nowidctlpar \page{\outlinelevel0{\cf0\f0\b Heading1 with pbb not first element in section} ' ;
134+ self ::assertStringContainsString ($ expected , $ content , 'page break ' );
135+ }
42136}
0 commit comments