Skip to content

Commit 8febf0c

Browse files
committed
Add select2 tests
1 parent 824b2a5 commit 8febf0c

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/Html/Editor/Fields/Select2.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function processPaginatedResults(string $display = 'text', string $id = '
103103
{
104104
$script = 'function(data, params) { ';
105105
$script .= 'params.page = params.page || 1; ';
106-
$script .= "data.data.map(function(e) { e.text = e.{$display}; e.id = e.{$id}; return e; }); ";
106+
$script .= "data.data.map(function(e) { e.text = e.$display; e.id = e.$id; return e; }); ";
107107
$script .= 'return { results: data.data, pagination: { more: data.current_page < data.last_page } };';
108108
$script .= '}';
109109

tests/FieldTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,15 @@ public function it_can_create_select2_field()
187187
$this->assertEquals('select2', $field->getType());
188188
$this->assertEquals('/url', $field->opts['ajax']['url']);
189189
$this->assertEquals('Test', $field->opts['placeholder']['text']);
190-
$this->assertEquals('id', $field->opts['placeholder']['id']);
190+
$this->assertEquals('', $field->opts['placeholder']['id']);
191191
$this->assertCount(20, $field->options);
192+
193+
$field->processResults('fn');
194+
$this->assertEquals('fn', $field->opts['ajax']['processResults']);
195+
196+
$field->processPaginatedResults('username', 'user_id');
197+
$this->assertStringContainsString('e.text = e.username', $field->opts['ajax']['processResults']);
198+
$this->assertStringContainsString('e.id = e.user_id', $field->opts['ajax']['processResults']);
192199
}
193200

194201
/** @test */

0 commit comments

Comments
 (0)