Skip to content
Snippets Groups Projects
Commit 44574dd5 authored by Dan Flanagan's avatar Dan Flanagan
Browse files

Merge branch '3460650-jsnippet-needs-some' into '8.x-1.x'

Resolve #3460650 "Jsnippet needs some"

See merge request !2
parents 7b53f5f9 af007190
No related branches found
No related tags found
No related merge requests found
Pipeline #221244 failed
langcode: en
status: true
dependencies:
config:
- field.field.node.page.field_jsnippet
- node.type.page
module:
- jsnippet
- user
id: node.page.default
targetEntityType: node
bundle: page
mode: default
content:
field_jsnippet:
type: entity_reference_snippet
label: above
settings: { }
third_party_settings: { }
weight: 101
region: content
links:
settings: { }
third_party_settings: { }
weight: 100
region: content
hidden: { }
langcode: en
status: true
dependencies:
config:
- field.storage.node.field_jsnippet
- node.type.page
id: node.page.field_jsnippet
field_name: field_jsnippet
entity_type: node
bundle: page
label: jsnippet
description: ''
required: false
translatable: false
default_value: { }
default_value_callback: ''
settings:
handler: 'default:jsnippet'
handler_settings:
target_bundles: null
auto_create: false
field_type: entity_reference
langcode: en
status: true
dependencies:
module:
- jsnippet
- node
id: node.field_jsnippet
field_name: field_jsnippet
entity_type: node
type: entity_reference
settings:
target_type: jsnippet
module: core
locked: false
cardinality: 1
translatable: true
indexes: { }
persist_with_no_fields: false
custom_storage: false
id: add_class
type: js
label: 'Add class'
snippet: "document.body.classList.add('jsnippet-class');"
scope: footer
behavior: '1'
langcode: en
status: true
dependencies: { }
langcode: en
status: true
dependencies: { }
name: Page
type: page
description: null
help: null
new_revision: false
preview_mode: 1
display_submitted: false
name: 'JSnippet test'
type: module
package: Testing
description: 'Testing assistance for jsnippet.'
dependencies:
- jsnippet:jsnippet
- drupal:user
- drupal:node
- drupal:file
<?php
namespace Drupal\Tests\jsnippet\Functional;
use Drupal\Tests\BrowserTestBase;
/**
* Tests functionality of jsnippet.
*
* @group jsnippet
*/
class JSnippetAdminTest extends BrowserTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'jsnippet_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Test that we can add (or not add) our snippet.
*/
public function testJSnippetAdmin() {
$this->drupalLogin($this->drupalCreateUser([
'administer snippets',
]));
// Confirm the snippet in config is visible.
$this->drupalGet('/admin/structure/snippet');
$this->assertSession()->pageTextContains('Add class');
$this->assertSession()->pageTextContains('add_class');
// Edit it.
$this->drupalGet('/admin/structure/snippet/add_class');
$this->submitForm(['label' => 'Different label'], 'Update Snippet');
$this->drupalGet('/admin/structure/snippet');
$this->assertSession()->pageTextNotContains('Add class');
$this->assertSession()->pageTextContains('Different label');
$this->assertSession()->pageTextContains('add_class');
// Make a new one.
$this->drupalGet('/admin/structure/snippet/add');
$this->submitForm([
'label' => 'Style snippet',
'id' => 'style_snippet',
'type' => 'css',
'snippet' => 'body { color: red }'
], 'Create Snippet');
$this->drupalGet('/admin/structure/snippet');
$this->assertSession()->pageTextContains('Style snippet');
$this->assertSession()->pageTextContains('style_snippet');
// Delete it.
$this->drupalGet('/admin/structure/snippet/style_snippet/delete');
$this->assertSession()->pageTextContains('Are you sure you want to delete snippet');
$this->submitForm([], 'Delete Snippet');
$this->assertSession()->statusMessageContains('Snippet Style snippet was deleted.');
$this->assertSession()->pageTextContains('Different label');
$this->assertSession()->pageTextContains('add_class');
$this->assertSession()->pageTextNotContains('style_snippet');
}
}
<?php
namespace Drupal\Tests\jsnippet\FunctionalJavascript;
use Drupal\FunctionalJavascriptTests\WebDriverTestBase;
use Drupal\node\Entity\Node;
/**
* Tests functionality of jsnippet.
*
* @group jsnippet
*/
class JSnippetTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = [
'jsnippet_test',
];
/**
* {@inheritdoc}
*/
protected $defaultTheme = 'stark';
/**
* Test that we can add (or not add) our snippet.
*/
public function testJSnippet() {
$page = Node::create([
'type' => 'page',
'title' => 'Page with snippet',
'field_jsnippet' => 'add_class',
]);
$page->save();
$this->drupalLogin($this->drupalCreateUser([
'access content',
]));
$this->drupalGet('node/' . $page->id());
$this->assertSession()->pageTextContains('Page with snippet');
$this->assertSession()->elementExists('css', 'body.jsnippet-class');
$page = Node::create([
'type' => 'page',
'title' => 'Page sans snippet',
]);
$page->save();
$this->drupalGet('node/' . $page->id());
$this->assertSession()->pageTextContains('Page sans snippet');
$this->assertSession()->elementNotExists('css', 'body.jsnippet-class');
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment