api-8.x-1.x-dev/tests/src/Functional/AttributesTest.php
tests/src/Functional/AttributesTest.php
<?php
namespace Drupal\Tests\api\Functional;
/**
* Tests that attributes parsing for classes is working.
*
* @group api
*/
class AttributesTest extends WebPagesBase {
/**
* {@inheritdoc}
*/
protected function setUp() : void {
$this->baseSetUp();
$this->branchInfo = $this->setUpBranchApiCall('', TRUE, [
'directory' => $this->apiModulePath . '/tests/files/sample_attributes',
]);
$this->removePhpBranch();
$this->clearCache();
$this->cronRun();
$this->processApiParseQueue();
}
/**
* Test hooks.
*/
public function testHook() {
$this->drupalGet('api/' . $this->branchInfo['project'] . '/sample.api.php/function/hook_sample');
$this->assertSession()->pageTextContains('2 functions implement hook_sample()');
$this->assertSession()->linkExists('sample_sample');
$this->clickLink('SampleElementWithAttribute::hookInClass');
$this->assertSession()->pageTextContains(<<<'EOT'
#[Hook('sample', order: new OrderAfter("<script/>"))]
EOT);
// Back to the original page.
$this->clickLink('sample');
$this->assertSession()->pageTextContains('function hook_sample(');
}
/**
* Test dynamic hooks.
*/
public function testDynamicHook() {
$this->drupalGet('api/' . $this->branchInfo['project'] . '/class.php/function/SampleElementWithAttribute::dynamicHookInClass');
$this->clickLink('foo_baz_sample');
$this->assertSession()->pageTextContains('function hook_foo_BAR_sample(');
}
/**
* Tets the elements page.
*/
public function testElement() {
$this->drupalGet('api/' . $this->branchInfo['project'] . '/elements');
$this->assertSession()->pageTextContains('sample_annotation');
$this->assertSession()->pageTextContains('sample_attribute');
}
}
