public function testWordWrapNoCutBreakAfter() { $line = Text\MultiByte::wordWrap('foobar-foobar', 5, '-', false); $this->assertEquals('foobar-foobar', $line); }
public function testWordWrapTriggersDeprecatedError() { $this->setExpectedException('PHPUnit_Framework_Error_Deprecated'); $line = Text\MultiByte::wordWrap('äbüöcß', 2, ' ', true); }
/** * Render the column width the given column width * * @param integer $columnWidth The width of the column * @param integer $padding The padding for the column * @throws \Zend\Text\Table\Exception When $columnWidth is lower than 1 * @throws \Zend\Text\Table\Exception When padding is greater than columnWidth * @return string */ public function render($columnWidth, $padding = 0) { if (is_int($columnWidth) === false or $columnWidth < 1) { throw new Exception('$columnWidth must be an integer and greater than 0'); } $columnWidth -= $padding * 2; if ($columnWidth < 1) { throw new Exception('Padding (' . $padding . ') is greater than column width'); } switch ($this->_align) { case self::ALIGN_LEFT: $padMode = STR_PAD_RIGHT; break; case self::ALIGN_CENTER: $padMode = STR_PAD_BOTH; break; case self::ALIGN_RIGHT: $padMode = STR_PAD_LEFT; break; default: // This can never happen, but the CS tells I have to have it ... break; } $outputCharset = Table::getOutputCharset(); $lines = explode("\n", Text\MultiByte::wordWrap($this->_content, $columnWidth, "\n", true, $outputCharset)); $paddedLines = array(); foreach ($lines as $line) { $paddedLines[] = str_repeat(' ', $padding) . Text\MultiByte::strPad($line, $columnWidth, ' ', $padMode, $outputCharset) . str_repeat(' ', $padding); } $result = implode("\n", $paddedLines); return $result; }
public function testWordWrapInvalidArgument() { $this->setExpectedException('Zend\Text\Exception\InvalidArgumentException', "Cannot force cut when width is zero"); Text\MultiByte::wordWrap('a', 0, "\n", true); }