View source
<?php
namespace Drupal\Tests\acquia_lift_inspector\FunctionalJavascript;
use Drupal\acquia_lift\Tests\SettingsDataTrait;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
use Drupal\Tests\node\Traits\ContentTypeCreationTrait;
use Drupal\Tests\node\Traits\NodeCreationTrait;
class InspectorJsTest extends JavascriptTestBase {
use SettingsDataTrait;
use ContentTypeCreationTrait;
use NodeCreationTrait;
public static $modules = [
'acquia_lift',
'acquia_lift_inspector',
];
public function setUp() {
parent::setUp();
$this
->createContentType([
'type' => 'article',
]);
}
private function getActualJSCredentialSettings() {
return [
'account_id' => 'AccountId1',
'site_id' => 'SiteId1',
'assets_url' => 'https://lift3assets.dev.lift.acquia.com/latest',
'decision_api_url' => 'decision_api_url_1',
'oauth_url' => 'oauth_url_1//////authorize',
];
}
public function testShowDebug() {
$admin_user = $this
->drupalCreateUser([
'administer acquia lift',
]);
$this
->drupalLogin($admin_user);
$this
->setValidSettings();
$settings = $this
->config('acquia_lift.settings');
$settings
->set('credential', $this
->getActualJSCredentialSettings());
$settings
->save();
$node = $this
->createNode([
'type' => 'article',
]);
$this
->drupalGet($node
->toUrl()
->toString());
$javascript = <<<JS
(function(){
return Object.keys(window.AcquiaLift).length > 0;
}());
JS;
$this
->assertJsCondition($javascript);
$page = $this
->getSession()
->getPage();
$inspector = $page
->findById('lift-inspector');
$this
->assertEmpty($inspector);
$this
->getSession()
->wait(6000, "Drupal.acquiaLiftInspector.showModal();");
$page = $this
->getSession()
->getPage();
$inspector = $page
->findById('lift-inspector');
$this
->assertNotEmpty($inspector);
$accountId = $inspector
->find('css', '#account-id a')
->getText();
$this
->assertEquals($accountId, 'AccountId1');
$accountLink = $inspector
->find('css', '#account-id a')
->getAttribute('href');
$this
->assertEquals($accountLink, 'https://us-east-1.lift.acquia.com#person:accountId=AccountId1');
$siteId = $inspector
->find('css', '#site-id')
->getText();
$this
->assertEquals($siteId, 'SiteId1');
$identity = $inspector
->find('css', '#identity')
->getText();
$this
->assertEquals($identity, 'No tracking id available.');
$identity = $inspector
->find('css', '#user-segments p')
->getText();
$this
->assertEquals($identity, 'No segment(s) available.');
$identity = $inspector
->find('css', '#decisions p')
->getText();
$this
->assertEquals($identity, 'No decisions made.');
$identity = $inspector
->find('css', '#captures p')
->getText();
$this
->assertEquals($identity, 'No recent captures.');
}
}