Skip to content

Commit

Permalink
add test for newline preservation
Browse files Browse the repository at this point in the history
  • Loading branch information
modelm committed Jun 12, 2018
1 parent 9361df2 commit 690336b
Showing 1 changed file with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions tests/phpunit/test-functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,60 @@ function test__hcmp_create_xprofile_fields() {
}
}

/**
* Ensure newlines are preserved in xprofile field data when editing.
*
* @dataProvider newlines_preserved_provider
*
* @param string Field value.
*/
function test_newlines_preserved( $value ) {
$u = self::factory()->user->create();
add_filter(
'bp_displayed_user_id', function() use ( $u ) {
return $u;
}
);

$g = self::factory()->xprofile_group->create();
$f = self::factory()->xprofile_field->create( [
'field_group_id' => $g,
'type' => 'textarea',
] );

$field = xprofile_get_field( $f );

xprofile_set_field_data( $f, $u, $value );

$args = [
'field' => $f,
'user_id' => $u,
];

$expected = $value;
$actual = _hcmp_get_field_data( $field->name );

$this->assertSame( $expected, $actual );
}

/**
* Provider for test_newlines_preserved.
*/
function newlines_preserved_provider() {
return [
[ 'This value does not contain a newline.' ],
[ 'This value has multiple newlines in a row!
Oh my.' ],
[ '<strong>Nowhere In Particular</strong>
Ph.D., Zebra Affairs
<strong>The Graduate Center, University of Mars</strong>
M.Phil., Special Topics
<strong>Elsewhere College</strong>
B.A., English, summa cum laude' ],
];
}
}

0 comments on commit 690336b

Please sign in to comment.