| 1 | <?php |
| 2 | return new class() extends \Civi\Test\EventCheck implements \Civi\Test\HookInterface { |
| 3 | |
| 4 | private $validSnippetTypes = [ |
| 5 | 'callback', |
| 6 | 'jquery', |
| 7 | 'markup', |
| 8 | 'script', |
| 9 | 'scriptFile', |
| 10 | 'scriptUrl', |
| 11 | 'settings', |
| 12 | 'style', |
| 13 | 'styleFile', |
| 14 | 'styleUrl', |
| 15 | 'template', |
| 16 | ]; |
| 17 | |
| 18 | private $validRegion = '/^[A-Za-z0-9\\-]+$/'; |
| 19 | |
| 20 | /** |
| 21 | * Ensure that the hook data is always well-formed. |
| 22 | */ |
| 23 | public function on_civi_region_render(\Civi\Core\Event\GenericHookEvent $e) { |
| 24 | $this->assertTrue($e->region instanceof \CRM_Core_Region); |
| 25 | /** @var \CRM_Core_Region $region */ |
| 26 | $region = $e->region; |
| 27 | $this->assertRegexp($this->validRegion, $region->_name); |
| 28 | foreach ($region->getAll() as $snippet) { |
| 29 | $this->assertContains($snippet['type'], $this->validSnippetTypes); |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | }; |