Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/changes/1.x/1.5.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Bug fixes

- Set writeAttribute return type by [@radarhere](https://github.com/radarhere) fixing [#2204](https://github.com/PHPOffice/PHPWord/issues/2204) in [#2776](https://github.com/PHPOffice/PHPWord/pull/2776)
- Writer RTF: Fix paragraph return when it should be line return in TextBreak by [@rasamassen](https://github.com/rasamassen) in [#2816](https://github.com/PHPOffice/PHPWord/pull/2816)

### Miscellaneous

Expand All @@ -16,4 +17,4 @@

### BC Breaks

### Notes
### Notes
4 changes: 4 additions & 0 deletions src/PhpWord/Writer/RTF/Element/TextBreak.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ public function write()
$parentWriter = $this->parentWriter;
$parentWriter->setLastParagraphStyle();

if ($this->withoutP) {
return '\line' . PHP_EOL;
}

return '\pard\par' . PHP_EOL;
}
}
65 changes: 65 additions & 0 deletions tests/PhpWordTests/Writer/RTF/Element/TextBreakTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php

/**
* This file is part of PHPWord - A pure PHP library for reading and writing
* word processing documents.
*
* PHPWord is free software distributed under the terms of the GNU Lesser
* General Public License version 3 as published by the Free Software Foundation.
*
* For the full copyright and license information, please read the LICENSE
* file that was distributed with this source code. For the full list of
* contributors, visit https://github.com/PHPOffice/PHPWord/contributors.
*
* @see https://github.com/PHPOffice/PHPWord
*
* @license http://www.gnu.org/licenses/lgpl.txt LGPL version 3
*/

namespace PhpOffice\PhpWordTests\Writer\RTF\Element;

use PhpOffice\PhpWord\Element\TextBreak as TextBreakElement;
use PhpOffice\PhpWord\Settings;
use PhpOffice\PhpWord\Writer\RTF;
use PhpOffice\PhpWord\Writer\RTF\Element\TextBreak as TextBreakWriter;
use PHPUnit\Framework\TestCase;

class TextBreakTest extends TestCase
{
protected function tearDown(): void
{
Settings::setDefaultRtl(null);
}

/**
* @param TextBreakWriter $field
*/
public function removeCr($field): string
{
return str_replace("\r\n", "\n", $field->write());
}

/**
* Test a normal textBreak.
*/
public function testTextBreakParagraph(): void
{
$parentWriter = new RTF();
$element = new TextBreakElement();
$writer = new TextBreakWriter($parentWriter, $element);
$expect = "\\pard\\par\n";
self::assertEquals($expect, $this->removeCr($writer));
}

/**
* Test a textBreak as a line break.
*/
public function testTextBreakLine(): void
{
$parentWriter = new RTF();
$element = new TextBreakElement();
$writer = new TextBreakWriter($parentWriter, $element, true);
$expect = "\\line\n";
self::assertEquals($expect, $this->removeCr($writer));
}
}
Loading