This patch starts to move out some of our common string functions into a utility class.
My main motivation for this change is make our classes more unit testable. Currently, if a class calls format_string or check_plain, which is very common, it cannot be unit tested with PHPUnit because bootstrap.inc is not included and functions cannot be autoloaded.
I started with check_plain, format_string, and drupal_placeholder, because usage of check_plain and format_string are common in tests and many conversions to PHPUnit are blocked by them.
I moved the tests relating to these functions from XssUnitTest into a dedicted PHPUnit test, and I also added test coverage for String::placeholder (didn't see any before).
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | drupal-1938972-12.patch | 15.37 KB | ParisLiakos |
| #10 | drupal-1938972-10.patch | 15.39 KB | dawehner |
| #10 | interdiff.txt | 2.4 KB | dawehner |
| #5 | string-1938972-5.patch | 15.32 KB | tsphethean |
| #4 | 1938972.patch | 15.2 KB | robloach |
Comments
Comment #1
xanoThis may overlap/collide with #1938670: Convert unicode.inc to \Drupal\Component\Utility\Unicode.
Comment #2
robloachComment #3
robloachComment #4
robloachAdded some docblocks and made use of @dataProvider for checkPlain and format, since we're on PHPUnit now for String.
Comment #5
tsphethean commentedJust a couple of minor docblock changes that my IDE was flagging up - otherwise looking good to me.
Comment #6
robloachComment #7
dawehnerCould this additional method calls be a performance problem, hopefully not?
Comment #8
xanoWe should only use the procedural wrappers during a transitioning phase. We can convert all calls in follow-up issues and remove the functions when we're done with that. Alternatively we can do the conversion in this issue.
Comment #9
ParisLiakos commentedlets replace them in followups, will be much easier
Comment #10
dawehnerJust a silly doc-style update.
Comment #11
msonnabaum commentedThe method call is not a significant performance hit at all. Also, it's easily avoidable by calling the class directly for those paranoid about it.
I agree that any talk of removing the procedural wrappers should be done in another thread. I'm not sure I support it, but I dont want that discussion to block these issues.
Comment #12
ParisLiakos commentedchasing HEAD..
had to adjust the use statements after the Timer class went in
Comment #13
alexpottCommitted d9fd65f and pushed to 8.x. Thanks!
Minor fix done during commit... :)
Fixed spelling of Utility
Comment #15
dawehnerJust linking the conversion of filter_xss: #1998466: Convert filter_xss_admin and similar function to an Xss component