From 61d3d04ed60fc9b728de9d3091fdb534b0862f50 Mon Sep 17 00:00:00 2001 From: Guy Marriott Date: Wed, 24 Jul 2019 15:55:08 +1200 Subject: [PATCH] FIX Removing potentially breaking lower-case change (and fix tests) --- src/TagField.php | 4 ++-- tests/TagFieldTest.php | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/TagField.php b/src/TagField.php index 17c0bf7..efe6192 100644 --- a/src/TagField.php +++ b/src/TagField.php @@ -283,7 +283,7 @@ class TagField extends MultiSelectField $option = $item->$titleField; $options->push(ArrayData::create([ 'Title' => $option, - 'Value' => strtolower($option), + 'Value' => $option, 'Selected' => (bool) $values->find('ID', $item->ID) ])); }; @@ -448,7 +448,7 @@ class TagField extends MultiSelectField foreach ($query->map('ID', $titleField) as $id => $title) { $items[$title] = [ 'Title' => $title, - 'Value' => strtolower($title), + 'Value' => $title, ]; } diff --git a/tests/TagFieldTest.php b/tests/TagFieldTest.php index dab4748..8429e4a 100755 --- a/tests/TagFieldTest.php +++ b/tests/TagFieldTest.php @@ -181,7 +181,7 @@ class TagFieldTest extends SapphireTest $request = $this->getNewRequest(['term' => 'Tag']); $this->assertEquals( - '{"items":[{"id":"Tag1","text":"Tag1"}]}', + '{"items":[{"Title":"Tag1","Value":"Tag1"}]}', $field->suggest($request)->getBody() ); @@ -191,7 +191,7 @@ class TagFieldTest extends SapphireTest $request = $this->getNewRequest(['term' => '222']); $this->assertEquals( - '{"items":[{"id":"222","text":"222"}]}', + '{"items":[{"Title":"222","Value":"222"}]}', $field->suggest($request)->getBody() ); @@ -201,7 +201,7 @@ class TagFieldTest extends SapphireTest $request = $this->getNewRequest(['term' => 'TAG1']); $this->assertEquals( - '{"items":[{"id":"Tag1","text":"Tag1"}]}', + '{"items":[{"Title":"Tag1","Value":"Tag1"}]}', $field->suggest($request)->getBody() ); @@ -230,7 +230,7 @@ class TagFieldTest extends SapphireTest $request = $this->getNewRequest(['term' => 'Tag']); $this->assertEquals( - '{"items":[{"id":"Tag1","text":"Tag1"}]}', + '{"items":[{"Title":"Tag1","Value":"Tag1"}]}', $field->suggest($request)->getBody() ); @@ -240,7 +240,7 @@ class TagFieldTest extends SapphireTest $request = $this->getNewRequest(['term' => 'Tag1']); $this->assertEquals( - '{"items":[{"id":"Tag1","text":"Tag1"}]}', + '{"items":[{"Title":"Tag1","Value":"Tag1"}]}', $field->suggest($request)->getBody() ); @@ -369,8 +369,16 @@ class TagFieldTest extends SapphireTest $this->assertFalse($schema['lazyLoad']); $this->assertFalse($schema['creatable']); $this->assertEquals([ - ['Title' => 'Tag1', 'Value' => 'Tag1'], - ['Title' => '222', 'Value' => '222'], + ['Title' => 'Tag1', 'Value' => 'Tag1', 'Selected' => false], + ['Title' => '222', 'Value' => '222', 'Selected' => false], + ], $schema['options']); + + $field->setValue(['222']); + $schema = $field->getSchemaDataDefaults(); + + $this->assertEquals([ + ['Title' => 'Tag1', 'Value' => 'Tag1', 'Selected' => false], + ['Title' => '222', 'Value' => '222', 'Selected' => true], ], $schema['options']); $field