View source
<?php
namespace Drupal\Tests\thunder\FunctionalJavascript;
use Drupal\Core\Url;
use Drupal\Tests\node\Traits\NodeCreationTrait;
class ArticleCreationTest extends ThunderJavascriptTestBase {
use ThunderParagraphsTestTrait;
use ThunderArticleTestTrait;
use NodeCreationTrait;
protected static $paragraphsField = 'field_paragraphs';
public function testCreateArticle() {
$this
->articleFillNew([
'field_channel' => 1,
'title[0][value]' => 'Test article',
'field_seo_title[0][value]' => 'Massive gaining seo traffic text',
]);
$this
->selectMedia('field_teaser_media', 'image_browser', [
'media:1',
]);
$this
->addImageParagraph(static::$paragraphsField, [
'media:5',
]);
$this
->addTextParagraph(static::$paragraphsField, '<p>Awesome text</p><p>With a new line</p>');
$this
->addGalleryParagraph(static::$paragraphsField, 'Test gallery', [
'media:1',
'media:5',
], 1);
$this
->addTextParagraph(static::$paragraphsField, 'Awesome quote', 'quote');
$this
->addSocialParagraph(static::$paragraphsField, 'https://twitter.com/ThunderCoreTeam/status/776417570756976640', 'twitter', 3);
$this
->addSocialParagraph(static::$paragraphsField, 'https://www.instagram.com/p/BbywAZBBqlI/', 'instagram');
$this
->addLinkParagraph(static::$paragraphsField, 'Link to Thunder', 'http://www.thunder.org');
$this
->addVideoParagraph(static::$paragraphsField, [
'media:7',
], 0);
$this
->addSocialParagraph(static::$paragraphsField, 'https://www.pinterest.de/pin/478085316687452268/', 'pinterest');
$this
->createScreenshot($this
->getScreenshotFolder() . '/ArticleCreationTest_BeforeSave_' . date('Ymd_His') . '.png');
$this
->clickSave();
$this
->createScreenshot($this
->getScreenshotFolder() . '/ArticleCreationTest_AfterSave_' . date('Ymd_His') . '.png');
$this
->assertPageTitle('Massive gaining seo traffic text');
$this
->assertSession()
->pageTextContains('Test article');
$this
->assertSession()
->elementsCount('xpath', '//div[contains(@class, "field--name-field-paragraphs")]/div[contains(@class, "field__item")][2]//img', 1);
$this
->assertSession()
->pageTextContains('Awesome text');
$this
->assertSession()
->elementsCount('xpath', '//div[contains(@class, "field--name-field-paragraphs")]/div[contains(@class, "field__item")][3]//div[contains(@class, "slick-track")]/div[not(contains(@class, "slick-cloned"))]//img', 2);
$this
->assertSession()
->pageTextContains('Awesome quote');
$this
->getSession()
->wait(5000, "jQuery('iframe').filter(function(){return (this.src.indexOf('instagram.com/p/BbywAZBBqlI') !== -1);}).length === 1");
$numOfElements = $this
->getSession()
->evaluateScript("jQuery('iframe').filter(function(){return (this.src.indexOf('instagram.com/p/BbywAZBBqlI') !== -1);}).length");
$this
->assertEquals(1, $numOfElements, "Number of instagrams on page should be one.");
$this
->getSession()
->wait(5000, "jQuery('iframe').filter(function(){return (this.id.indexOf('twitter-widget-0') !== -1);}).length === 1");
$numOfElements = $this
->getSession()
->evaluateScript("jQuery('iframe').filter(function(){return (this.id.indexOf('twitter-widget-0') !== -1);}).length");
$this
->assertEquals(1, $numOfElements, "Number of twitter on page should be one.");
$this
->assertSession()
->linkExists('Link to Thunder');
$this
->assertSession()
->linkByHrefExists('http://www.thunder.org');
$this
->assertSession()
->elementExists('css', '.shariff-button.twitter');
$this
->assertSession()
->elementExists('css', '.shariff-button.facebook');
$this
->getSession()
->wait(5000, "jQuery('iframe').filter(function(){return (this.src.indexOf('media/oembed?url=https%3A//www.youtube.com/watch%3Fv%3DKsp5JVFryEg') !== -1);}).length === 1");
$numOfElements = $this
->getSession()
->evaluateScript("jQuery('iframe').filter(function(){return (this.src.indexOf('/media/oembed?url=https%3A//www.youtube.com/watch%3Fv%3DKsp5JVFryEg') !== -1);}).length");
$this
->assertEquals(1, $numOfElements, "Number of youtube on page should be one.");
$this
->assertSession()
->elementsCount('xpath', '//div[contains(@class, "field--name-field-paragraphs")]/div[contains(@class, "field__item")][9]//span[contains(@data-pin-id, "478085316687452268")]', 2);
}
public function testCreateArticleWithNoModeration() {
foreach (\Drupal::entityTypeManager()
->getStorage('node')
->loadByProperties([
'type' => 'article',
]) as $node) {
$node
->delete();
}
\Drupal::service('module_installer')
->uninstall([
'thunder_workflow',
]);
$this
->articleFillNew([
'field_channel' => 1,
'title[0][value]' => 'Test article',
'field_seo_title[0][value]' => 'Massive gaining seo traffic text',
]);
$this
->clickSave();
$this
->assertPageTitle('Massive gaining seo traffic text');
$this
->assertSession()
->pageTextContains('Test article');
}
public function testModerationWorkflow() {
$this
->articleFillNew([
'field_channel' => 1,
'title[0][value]' => 'Test workflow article',
'field_seo_title[0][value]' => 'Massive gaining seo traffic text',
]);
$this
->setModerationState('published');
$this
->clickSave();
$this
->assertPageTitle('Massive gaining seo traffic text');
$node = $this
->getNodeByTitle('Test workflow article');
$this
->drupalGet($node
->toUrl('edit-form'));
$this
->setModerationState('unpublished');
$this
->getSession()
->getPage()
->find('xpath', '//*[@id="edit-preview"]')
->click();
$this
->clickLink('Back to content editing');
$this
->assertSession()
->pageTextNotContains('An illegal choice has been detected. Please contact the site administrator.');
$this
->setFieldValues($this
->getSession()
->getPage(), [
'title[0][value]' => 'Test workflow article in draft',
'field_seo_title[0][value]' => 'Massive gaining even more seo traffic text',
]);
$this
->setModerationState('draft');
$this
->clickSave();
$this
->drupalGet($node
->toUrl('edit-form'));
$this
->setFieldValues($this
->getSession()
->getPage(), [
'title[0][value]' => 'Test workflow article in draft 2',
'field_seo_title[0][value]' => 'Massive gaining even more and more seo traffic text',
]);
$this
->setModerationState('draft');
$this
->clickSave();
$this
->assertPageTitle('Massive gaining even more and more seo traffic text');
$node_storage = \Drupal::entityTypeManager()
->getStorage('node');
$revert_url = Url::fromRoute('node.revision_revert_default_confirm', [
'node' => $node
->id(),
'node_revision' => $node_storage
->getLatestRevisionId($node
->id()),
]);
$this
->drupalPostForm($revert_url, [], $this
->t('Revert'));
$this
->drupalGet($node
->toUrl());
$this
->assertPageTitle('Massive gaining seo traffic text');
$this
->drupalGet($node
->toUrl('edit-form'));
$this
->assertSession()
->fieldValueEquals('field_seo_title[0][value]', 'Massive gaining seo traffic text');
}
}