View source
<?php
namespace Drupal\rdf_builder\Tests;
use Drupal\simpletest\WebTestBase;
class ContentTypeBuilderTest extends WebTestBase {
public static $modules = array(
'rdf_builder',
'rdfui',
'rdf',
'field',
'node',
'field_ui',
);
public static function getInfo() {
return array(
'name' => 'Schema.Org driven Content Type Builder',
'description' => 'Tests the functionality of the ContentBuilder Form.',
'group' => 'RDF UI Builder',
);
}
public function setUp() {
parent::setUp();
$this->admin_user = $this
->drupalCreateUser(array(
'administer content types',
));
$this
->drupalLogin($this->admin_user);
}
protected function testContentTypeCreate() {
$this
->editFormOne();
foreach (array(
'email',
'name',
) as $element) {
$this
->assertText($element, format_string('property "@element" of "@type" was found.', array(
'@element' => $element,
'@type' => $this->rdf_type,
)));
}
$this
->assertFieldByName('fields[schema:email][enable]', NULL, 'Checkbox for property found');
$this
->assertFieldByName('fields[schema:email][type]', NULL, 'Dropdown list for data type found.');
$edit = array(
'fields[schema:email][enable]' => '1',
'fields[schema:email][type]' => 'email',
'fields[schema:name][enable]' => '1',
'fields[schema:name][type]' => '',
);
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertText("Create field: you need to provide a data type for name", 'Form validated and errors displayed.');
$this
->assertUrl($this->uri, array(), 'Stayed on same page after incorrect submission.');
$edit['fields[schema:name][type]'] = 'text';
$this
->drupalPostForm(NULL, $edit, t('Save'));
$this
->assertText('Content Type Person created', 'Successful content type creation message displayed');
}
protected function editFormOne() {
$this->uri = 'admin/structure/types/rdf';
$this
->drupalGet($this->uri);
$this
->assertRaw('Create a content type by importing Schema.Org entity type.', "Form one displayed correctly.");
$this->rdf_type = "schema:Person";
$edit = array(
'rdf-type' => $this->rdf_type,
);
$this
->drupalPostForm(NULL, $edit, t('Next >>'));
$this
->assertRaw('Choose fields to start with.', 'Navigated to page two of the form.');
}
protected function testNavigateBack() {
$this
->editFormOne();
$this
->drupalPostForm(NULL, array(), t('< Back'));
$this
->assertRaw("Create a content type by importing Schema.Org entity type.", "Navigated back to form one.");
}
}