View source
<?php
namespace Drupal\Tests\thunder\FunctionalJavascript\Integration;
use Drupal\Tests\thunder\FunctionalJavascript\ThunderArticleTestTrait;
use Drupal\Tests\thunder\FunctionalJavascript\ThunderJavascriptTestBase;
use Drupal\Tests\thunder\FunctionalJavascript\ThunderParagraphsTestTrait;
use Drupal\thunder_test_mock_request\MockHttpClientMiddleware;
class RiddleTest extends ThunderJavascriptTestBase {
use ThunderArticleTestTrait;
use ThunderParagraphsTestTrait;
public function testRiddle() {
$riddleToken = getenv('RIDDLE_TOKEN');
MockHttpClientMiddleware::addUrlResponse('https://www.riddle.com/imageservice/q_80,f_auto,c_fill,w_256,h_144/rpnykwxetggrh99lkten', file_get_contents(DRUPAL_ROOT . '/core/misc/druplicon.png'));
MockHttpClientMiddleware::addUrlResponse('https://cdn.riddle.com/website/riddle/2019/placeholders/placeholder-poll.png', file_get_contents(DRUPAL_ROOT . '/core/misc/druplicon.png'));
if (empty($riddleToken)) {
if ($this
->isForkPullRequest()) {
$this
->markTestSkipped("Skip Riddle test (missing secure environment variables)");
return;
}
$this
->fail("Riddle token is not available.");
return;
}
if (!\Drupal::service('module_installer')
->install([
'thunder_riddle',
])) {
$this
->fail("Unable to install Thunder Riddle integration module.");
return;
}
$this
->rebuildAll();
$this
->logWithRole('administrator');
$this
->drupalGet('admin/config/content/riddle_marketplace');
$page = $this
->getSession()
->getPage();
$this
->setFieldValues($page, [
'token' => $riddleToken,
]);
$this
->clickButtonDrupalSelector($page, 'edit-submit');
$this
->logWithRole(static::$defaultUserRole);
$this
->articleFillNew([
'field_channel' => 1,
'title[0][value]' => 'Article 1',
'field_seo_title[0][value]' => 'Article 1',
]);
$paragraphIndex = $this
->addParagraph('field_paragraphs', 'riddle');
$buttonName = "field_paragraphs_{$paragraphIndex}_subform_field_riddle_entity_browser_entity_browser";
$this
->scrollElementInView("[name=\"{$buttonName}\"]");
$page
->pressButton($buttonName);
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->getSession()
->switchToIFrame('entity_browser_iframe_riddle_browser');
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->clickButtonDrupalSelector($page, 'edit-import-riddle');
$this
->assertNotEmpty($this
->assertSession()
->waitForElementVisible('css', '.view-media-entity-browser .views-field-thumbnail__target-id img:last-child'));
$this
->getSession()
->switchToIFrame();
$page
->find('xpath', '//*[contains(@class, "ui-dialog-titlebar-close")]')
->click();
$this
->assertSession()
->assertWaitOnAjaxRequest();
$this
->selectMedia("field_paragraphs_{$paragraphIndex}_subform_field_riddle", 'riddle_browser', [
'media:23',
]);
$paragraphIndex = $this
->addParagraph('field_paragraphs', 'riddle');
$this
->selectMedia("field_paragraphs_{$paragraphIndex}_subform_field_riddle", 'riddle_browser', [
'media:24',
]);
$this
->clickSave();
$this
->drupalGet('node/10');
$this
->assertSession()
->elementExists('xpath', '//div[contains(@class, "field--name-field-paragraphs")]/div[contains(@class, "field__item")][1]//iframe[contains(@src, "https://www.riddle.com/a/114979")]');
$this
->assertSession()
->elementExists('xpath', '//div[contains(@class, "field--name-field-paragraphs")]/div[contains(@class, "field__item")][2]//iframe[contains(@src, "https://www.riddle.com/a/114982")]');
}
}