FieldCollectionAjaxTest.php in Field collection 8
File
tests/src/FunctionalJavascript/FieldCollectionAjaxTest.php
View source
<?php
namespace Drupal\Tests\field_collection\FunctionalJavascriptTests;
use Drupal\FunctionalJavascriptTests\JavascriptTestBase;
use Drupal\Tests\field_collection\Functional\FieldCollectionTestTrait;
use Drupal\field\Entity\FieldStorageConfig;
use Drupal\Core\Field\FieldStorageDefinitionInterface;
class FieldCollectionAJAXTest extends JavascriptTestBase {
use FieldCollectionTestTrait;
protected static $modules = [
'field_collection',
'node',
'field',
'field_ui',
];
public function setUp() {
parent::setUp();
$this
->setUpFieldCollectionTest();
}
public function testEmptyFields() {
$user_privileged = $this
->drupalCreateUser([
'access content',
'edit any article content',
'create article content',
]);
$this
->drupalLogin($user_privileged);
$field_config = FieldStorageConfig::loadByName('node', $this->field_collection_name);
$field_config
->setCardinality(FieldStorageDefinitionInterface::CARDINALITY_UNLIMITED);
$field_config
->save();
$this
->drupalGet('node/add/article');
$this
->assertFieldById('edit-field-test-collection-0-field-inner-0-value');
$this
->click('.field-add-more-submit');
$this
->assertJsCondition('jQuery("[name=\'field_test_collection[0][field_inner][0][value]\']").length', 10000);
$this
->assertJsCondition('jQuery("[name=\'field_test_collection[1][field_inner][0][value]\']").length', 10000);
$node = $this
->drupalCreateNode([
'type' => 'article',
]);
$this
->drupalGet('node/' . $node
->id() . '/edit');
$this
->assertFieldById('edit-field-test-collection-0-field-inner-0-value');
}
}