function get_element_output($name, $value) { $result = string_hanging_indent($value, 15, 75, $name . ': ', $this->newline); // remove the last newline, this will be added during the final record join $result = rtrim($result, $this->newline); return $result; }
function test_string_hanging_indent() { // long test string $string = 'abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl mnopqrst uvwxyz'; $result = string_hanging_indent($string, 20, 70); $expected = " abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl\n"; $expected .= " mnopqrst uvwxyz abcdefghi jkl mnopqrst uvwxyz\n"; $expected .= " abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl\n"; $expected .= " mnopqrst uvwxyz\n"; $this->assertEqual($result, $expected); $result = string_hanging_indent($string, 12, 51); $expected = " abcdefghi jkl mnopqrst uvwxyz abcdefghi\n"; $expected .= " jkl mnopqrst uvwxyz abcdefghi jkl\n"; $expected .= " mnopqrst uvwxyz abcdefghi jkl mnopqrst\n"; $expected .= " uvwxyz abcdefghi jkl mnopqrst uvwxyz\n"; $this->assertEqual($result, $expected); // add title $result = string_hanging_indent($string, 20, 70, "My String:"); $expected = "My String: abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl\n"; $expected .= " mnopqrst uvwxyz abcdefghi jkl mnopqrst uvwxyz\n"; $expected .= " abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl\n"; $expected .= " mnopqrst uvwxyz\n"; $this->assertEqual($result, $expected); $result = string_hanging_indent($string, 12, 51, "My String:"); $expected = "My String: abcdefghi jkl mnopqrst uvwxyz abcdefghi\n"; $expected .= " jkl mnopqrst uvwxyz abcdefghi jkl\n"; $expected .= " mnopqrst uvwxyz abcdefghi jkl mnopqrst\n"; $expected .= " uvwxyz abcdefghi jkl mnopqrst uvwxyz\n"; $this->assertEqual($result, $expected); // Does not break long words by default $string = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'; $result = string_hanging_indent($string, 20, 70); $expected = " {$string}\n"; $this->assertEqual($result, $expected); // Cut option breaks long words $string = 'abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz'; $result = string_hanging_indent($string, 20, 70, '', "\n", TRUE); $expected = " abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwx\n"; $expected .= " yzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuv\n"; $expected .= " wxyzabcdefghijklmnopqrstuvwxyz\n"; $this->assertEqual($result, $expected); // test with custom line break $string = 'abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl mnopqrst uvwxyz'; $result = string_hanging_indent($string, 20, 70, '', "\r\n"); $expected = " abcdefghi jkl mnopqrst uvwxyz abcdefghi jkl\r\n"; $expected .= " mnopqrst uvwxyz abcdefghi jkl mnopqrst uvwxyz\r\n"; $this->assertEqual($result, $expected); }