View source
<?php
class ParagraphsWebTestCase extends DrupalWebTestCase {
protected $privilegedUser;
public static function getInfo() {
return array(
'name' => 'Paragraphs test',
'description' => 'Ensure that the simpletest_example content type provided functions properly.',
'group' => 'Paragraphs',
);
}
public function setUp() {
$modules = array(
'paragraphs_test',
);
parent::setUp($modules);
features_revert_module('paragraphs_test');
$this->privilegedUser = $this
->drupalCreateUserWithRole('ptest creator');
}
public function testPanelizer() {
$this
->drupalLogin($this->privilegedUser);
$this
->drupalGet('node/add/paragraph-test');
$this
->drupalPost(NULL, array(), t('Add new Paragraph'));
$title = $this
->randomString(20);
$value1 = $this
->randomString(20);
$create_edit = array(
'title' => $title,
'field_paragraphs[und][0][field_ptest_text][und][0][value]' => $value1,
);
$this
->drupalPost(NULL, $create_edit, t('Save'));
$this
->assertRaw(t('!post %title has been created.', array(
'!post' => 'Paragraph Test',
'%title' => $title,
)), 'Paragraph test node created.');
$this
->assertText(check_plain($value1), 'First value of paragraph was rendered.');
$node_url = $this
->getUrl();
$this
->drupalGet($node_url . '/edit');
$this
->drupalPost(NULL, array(), t('Add another Paragraph'));
$value2 = $this
->randomString(20);
$update_edit = array(
'field_paragraphs[und][1][field_ptest_text][und][0][value]' => $value2,
);
$this
->drupalPost(NULL, $update_edit, t('Save'));
$this
->assertRaw(t('!post %title has been updated.', array(
'!post' => 'Paragraph Test',
'%title' => $title,
)), 'Paragraph test node updated.');
$this
->assertText(check_plain($value1), 'First value of paragraph was rendered.');
$this
->assertText(check_plain($value2), 'Second value of paragraph was rendered.');
}
public function testRequiredFieldInBundle() {
$this
->drupalLogin($this->privilegedUser);
$this
->drupalGet('node/add/paragraph-test');
$this
->drupalPost(NULL, array(), t('Add new Paragraph'));
$title = $this
->randomString(20);
$create_edit = array(
'title' => $title,
);
$this
->drupalPost(NULL, $create_edit, t('Save'));
$this
->assertRaw(t('!field field is required.', array(
'!field' => 'PTest Text',
)), 'Field failed whole-form validation');
$this
->drupalPost(NULL, $create_edit, t('Collapse'));
$this
->assertRaw(t('!field field is required.', array(
'!field' => 'PTest Text',
)), 'Field failed per-paragraph validation');
$value1 = $this
->randomString(20);
$create_edit = array(
'field_paragraphs[und][0][field_ptest_text][und][0][value]' => $value1,
);
$this
->drupalPost(NULL, $create_edit, t('Collapse'));
$this
->assertRaw(t('Warning: this content must be saved to reflect changes on this paragraphs item.'), 'Field passed per-paragraph validation');
$create_edit = array(
'title' => $title,
);
$this
->drupalPost(NULL, $create_edit, t('Save'));
$this
->assertRaw(t('!post %title has been created.', array(
'!post' => 'Paragraph Test',
'%title' => $title,
)), 'Paragraph test node created.');
$this
->assertText(check_plain($value1), 'Value of paragraph was rendered.');
}
protected function drupalCreateUserWithRole($role_name) {
$role = user_role_load_by_name($role_name);
if (!$role) {
return FALSE;
}
$edit = array();
$edit['name'] = $this
->randomName();
$edit['mail'] = $edit['name'] . '@example.com';
$edit['pass'] = user_password();
$edit['status'] = 1;
$edit['roles'] = array(
$role->rid => $role->rid,
);
$account = user_save(drupal_anonymous_user(), $edit);
$this
->assertTrue(!empty($account->uid), t('User created with name %name and pass %pass', array(
'%name' => $edit['name'],
'%pass' => $edit['pass'],
)), t('User login'));
if (empty($account->uid)) {
return FALSE;
}
$account->pass_raw = $edit['pass'];
return $account;
}
}