-
Notifications
You must be signed in to change notification settings - Fork 41
Optimize entry meta logic #3267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+61
−17
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -81,6 +81,37 @@ private function create_text_and_number_fields() { | |
| return array( $form, $text_field_id, $number_field_id ); | ||
| } | ||
|
|
||
| /** | ||
| * Callers may hand set_value_before_save() a field they have already loaded, so that | ||
| * update_entry_metas() does not look the same field up a second time for every value. | ||
| * The packing has to follow the field that was passed, otherwise the argument is being | ||
| * ignored and the second lookup is back. | ||
| * | ||
| * @covers FrmEntryMeta::set_value_before_save | ||
| */ | ||
| public function test_set_value_before_save_packs_with_the_field_that_was_passed() { | ||
| list( , $text_field_id ) = $this->create_text_and_number_fields(); | ||
|
|
||
| $as_number = clone FrmField::getOne( $text_field_id ); | ||
| $as_number->type = 'number'; | ||
|
|
||
| $values = array( | ||
| 'item_id' => 1, | ||
| 'field_id' => $text_field_id, | ||
| 'meta_value' => 'abc', | ||
| ); | ||
| $this->run_private_method( array( 'FrmEntryMeta', 'set_value_before_save' ), array( &$values, $as_number ) ); | ||
| $this->assertEqualsWithDelta( 0.0, $values['meta_value'], PHP_FLOAT_EPSILON, 'The passed number field should coerce a non-numeric value to a float.' ); | ||
|
|
||
| $values = array( | ||
| 'item_id' => 1, | ||
| 'field_id' => $text_field_id, | ||
| 'meta_value' => 'abc', | ||
| ); | ||
| $this->run_private_method( array( 'FrmEntryMeta', 'set_value_before_save' ), array( &$values, null ) ); | ||
| $this->assertSame( 'abc', $values['meta_value'], 'With no field passed the stored text field should be looked up and leave the value alone.' ); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
|
|
||
| /** | ||
| * The field argument has to stay optional. add_entry_meta() and update_entry_meta() are | ||
| * called with four arguments from dozens of places across the add-ons, and those callers | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method you are trying to call is not defined, which can result in a fatal error.