-
Notifications
You must be signed in to change notification settings - Fork 396
Get unique html element id from record view helper #2999
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
Changes from 4 commits
c69cbc0
4859ace
3d33b82
3dd8446
22e7630
cbdedf7
3e308f2
e294a75
c05492d
0c34fbc
07af7fa
60de01a
d8dfc5e
d4a6492
6c57f53
3a9c45f
1848009
bd13052
6ee8f92
010756c
634dacb
898df17
48e5a10
939411f
87480db
d31c992
d614377
3a9b9d5
8cba230
46b2f01
83f543d
0ee81bc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -419,10 +419,10 @@ public function getSearchResult($view) | |
| */ | ||
| public function getCheckbox($idPrefix = '', $formAttr = false, $number = null) | ||
| { | ||
| $id = $this->driver->getSourceIdentifier() . '|' | ||
| . $this->driver->getUniqueId(); | ||
| $context | ||
| = ['id' => $id, 'number' => $number, 'prefix' => $idPrefix]; | ||
| $context = compact('number') + [ | ||
| 'id' => $this->getUniqueIdWithSourcePrefix(), | ||
| 'checkboxElementId' => $this->getUniqueHtmlElementId($idPrefix) | ||
| ]; | ||
|
Member
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. Minor style point: I'd de-indent the closing |
||
| if ($formAttr) { | ||
| $context['formAttr'] = $formAttr; | ||
| } | ||
|
|
@@ -711,4 +711,35 @@ protected function deduplicateLinks($links) | |
| { | ||
| return array_values(array_unique($links, SORT_REGULAR)); | ||
| } | ||
|
|
||
| /** | ||
| * Get the source identifier + unique id of the record without spaces | ||
| * | ||
| * @param string $idPrefix Prefix for HTML ids | ||
| * @throws \Exception If no record driver can be found | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getUniqueHtmlElementId($idPrefix = "") | ||
| { | ||
| return preg_replace( | ||
| "/\s+/", | ||
| "_", | ||
| ($idPrefix ? $idPrefix . '-' : '') . $this->getUniqueIdWithSourcePrefix() | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * Get the source identifier + unique id of the record | ||
| * | ||
| * @return string | ||
| */ | ||
| public function getUniqueIdWithSourcePrefix() | ||
| { | ||
| if ($this->driver) { | ||
|
demiankatz marked this conversation as resolved.
|
||
| return "{$this->driver->tryMethod('getSourceIdentifier')}" | ||
| . "|{$this->driver->tryMethod('getUniqueId')}"; | ||
|
Member
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. Both |
||
| } | ||
| throw new \Exception("No record driver found."); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -365,6 +365,21 @@ public function testGetLink( | |
| $this->assertEquals($expected, $record->getLink('bar', 'foo')); | ||
| } | ||
|
|
||
| /** | ||
| * Helper function for testGetCheckbox to simulate withConsecutive deprecated in PhpUnit 9.6 | ||
| * stolen from https://stackoverflow.com/a/75536028 | ||
| * | ||
| * @param ...$args | ||
| * @return callable | ||
| */ | ||
| public function consecutiveCalls(...$args): callable | ||
|
Member
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. You might find it helpful to use WithConsecutiveTrait.php here -- that's the general-purpose solution I used to replace the deprecated withConsecutive method in other tests.
Contributor
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. Thats an interesting headsup, i will look into it tomorrow. I am indeed not done, i quickly threw some code together as the necessary changes seemed rather simple and i had no running test-environment on my local machine. As i cannot continue to spam not working tests i should probably get that going again. |
||
| { | ||
| $count = 0; | ||
| return function ($arg) use (&$count, $args) { | ||
| return $arg == $args[$count++]; | ||
| }; | ||
| } | ||
|
|
||
| /** | ||
| * Test getCheckbox. | ||
| * | ||
|
|
@@ -373,21 +388,18 @@ public function testGetLink( | |
| public function testGetCheckbox() | ||
| { | ||
| $context = $this->getMockContext(); | ||
| $this->expectConsecutiveCalls( | ||
| $context, | ||
| 'renderInContext', | ||
| [ | ||
| [ | ||
| $context->expects($this->exactly(2))->method('renderInContext') | ||
| ->with( | ||
| self::callback(self::consecutiveCalls( | ||
| 'record/checkbox.phtml', | ||
| ['id' => 'Solr|000105196', 'number' => 1, 'prefix' => 'bar', 'formAttr' => 'foo'], | ||
| ], | ||
| [ | ||
| ['id' => 'bar-Solr|000105196', 'number' => 1, 'prefix' => 'bar', 'formAttr' => 'foo'] | ||
| )), | ||
| self::callback(self::consecutiveCalls( | ||
| 'record/checkbox.phtml', | ||
| ['id' => 'Solr|000105196', 'number' => 2, 'prefix' => 'bar', 'formAttr' => 'foo'], | ||
| ], | ||
| ], | ||
| 'success' | ||
| ); | ||
| ['id' => 'bar-Solr|000105196', 'number' => 2, 'prefix' => 'bar', 'formAttr' => 'foo'] | ||
| )) | ||
| ) | ||
| ->willReturnOnConsecutiveCalls('success', 'success'); | ||
| $record = $this->getRecord( | ||
| $this->loadRecordFixture('testbug1.json'), | ||
| [], | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.