Commit bf2c404e authored by alexpott's avatar alexpott

Issue #2004224 by Berdir, andypost: Convert tests using TestEntity to...

Issue #2004224 by Berdir, andypost: Convert tests using TestEntity to EntityTest (except Field API tests).
parent 23357e25
......@@ -21,7 +21,7 @@ class DatetimeFieldTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('node', 'field_test', 'datetime', 'field_ui');
public static $modules = array('node', 'entity_test', 'datetime', 'field_ui');
/**
* A field to use in this test class.
......@@ -42,8 +42,8 @@ function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(array(
'access field_test content',
'administer field_test content',
'view test entity',
'administer entity_test content',
'administer content types',
));
$this->drupalLogin($web_user);
......@@ -56,8 +56,8 @@ function setUp() {
));
$this->instance = field_create_instance(array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
'settings' => array(
'default_value' => 'blank',
),
......@@ -85,7 +85,7 @@ function setUp() {
function testDateField() {
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
$this->drupalGet('entity_test/add');
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.');
$this->assertNoFieldByName("{$this->field['field_name']}[$langcode][0][value][time]", '', 'Time element not found.');
......@@ -98,12 +98,14 @@ function testDateField() {
$time_format = config('system.date')->get('formats.html_time.pattern.' . $format_type);
$edit = array(
'user_id' => 1,
'name' => $this->randomName(),
"{$this->field['field_name']}[$langcode][0][value][date]" => $date->format($date_format),
);
$this->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match);
preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match);
$id = $match[1];
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)));
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
$this->assertRaw($date->format($date_format));
$this->assertNoRaw($date->format($time_format));
......@@ -154,7 +156,7 @@ function testDatetimeField() {
field_update_field($this->field);
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
$this->drupalGet('entity_test/add');
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.');
$this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][time]", '', 'Time element found.');
......@@ -167,13 +169,15 @@ function testDatetimeField() {
$time_format = config('system.date')->get('formats.html_time.pattern.' . $format_type);
$edit = array(
'user_id' => 1,
'name' => $this->randomName(),
"{$this->field['field_name']}[$langcode][0][value][date]" => $date->format($date_format),
"{$this->field['field_name']}[$langcode][0][value][time]" => $date->format($time_format),
);
$this->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match);
preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match);
$id = $match[1];
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)));
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
$this->assertRaw($date->format($date_format));
$this->assertRaw($date->format($time_format));
......@@ -234,7 +238,7 @@ function testDatelistWidget() {
field_cache_clear();
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
$this->drupalGet('entity_test/add');
$field_name = $this->field['field_name'];
$langcode = Language::LANGCODE_NOT_SPECIFIED;
......@@ -256,7 +260,10 @@ function testDatelistWidget() {
$date_value = array('year' => 2012, 'month' => 12, 'day' => 31, 'hour' => 5, 'minute' => 15);
$date = new DrupalDateTime($date_value);
$edit = array();
$edit = array(
'user_id' => 1,
'name' => $this->randomName(),
);
// Add the ampm indicator since we are testing 12 hour time.
$date_value['ampm'] = 'am';
foreach ($date_value as $part => $value) {
......@@ -264,9 +271,9 @@ function testDatelistWidget() {
}
$this->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match);
preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match);
$id = $match[1];
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)));
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
$this->assertOptionSelected("edit-$field_name-$langcode-0-value-year", '2012', 'Correct year selected.');
$this->assertOptionSelected("edit-$field_name-$langcode-0-value-month", '12', 'Correct month selected.');
......@@ -293,7 +300,7 @@ function testDefaultValue() {
// Display creation form.
$date = new DrupalDateTime();
$date_format = 'Y-m-d';
$this->drupalGet('test-entity/add/test_bundle');
$this->drupalGet('entity_test/add');
$langcode = Language::LANGCODE_NOT_SPECIFIED;
// See if current date is set. We cannot test for the precise time because
......@@ -310,7 +317,7 @@ function testDefaultValue() {
// Display creation form.
$date = new DrupalDateTime();
$this->drupalGet('test-entity/add/test_bundle');
$this->drupalGet('entity_test/add');
// See that no date is set.
$this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.');
......@@ -327,7 +334,7 @@ function testInvalidField() {
field_update_field($this->field);
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
$this->drupalGet('entity_test/add');
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][date]", '', 'Date element found.');
$this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value][time]", '', 'Time element found.');
......@@ -403,23 +410,23 @@ function testInvalidField() {
}
/**
* Renders a test_entity and sets the output in the internal browser.
* Renders a entity_test and sets the output in the internal browser.
*
* @param int $id
* The test_entity ID to render.
* The entity_test ID to render.
* @param string $view_mode
* (optional) The view mode to use for rendering. Defaults to 'full'.
* @param bool $reset
* (optional) Whether to reset the test_entity controller cache. Defaults to
* (optional) Whether to reset the entity_test controller cache. Defaults to
* TRUE to simplify testing.
*/
protected function renderTestEntity($id, $view_mode = 'full', $reset = TRUE) {
if ($reset) {
entity_get_controller('test_entity')->resetCache(array($id));
entity_get_controller('entity_test')->resetCache(array($id));
}
$entity = field_test_entity_test_load($id);
$display = entity_get_display('test_entity', $entity->bundle(), 'full');
field_attach_prepare_view('test_entity', array($entity->id() => $entity), array($entity->bundle() => $display), $view_mode);
$entity = entity_load('entity_test', $id);
$display = entity_get_display('entity_test', $entity->bundle(), 'full');
field_attach_prepare_view('entity_test', array($entity->id() => $entity), array($entity->bundle() => $display), $view_mode);
$entity->content = field_attach_view($entity, $display, $view_mode);
$output = drupal_render($entity->content);
......
......@@ -20,7 +20,7 @@ class EmailFieldTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('node', 'field_test', 'email', 'field_ui');
public static $modules = array('node', 'entity_test', 'email', 'field_ui');
public static function getInfo() {
return array(
......@@ -34,8 +34,8 @@ function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array(
'access field_test content',
'administer field_test content',
'view test entity',
'administer entity_test content',
'administer content types',
));
$this->drupalLogin($this->web_user);
......@@ -53,13 +53,13 @@ function testEmailField() {
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
field_create_instance($this->instance);
// Create a form display for the default form mode.
entity_get_form_display('test_entity', 'test_bundle', 'default')
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($this->field['field_name'], array(
'type' => 'email_default',
'settings' => array(
......@@ -68,14 +68,14 @@ function testEmailField() {
))
->save();
// Create a display for the full view mode.
entity_get_display('test_entity', 'test_bundle', 'full')
entity_get_display('entity_test', 'entity_test', 'full')
->setComponent($this->field['field_name'], array(
'type' => 'email_mailto',
))
->save();
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
$this->drupalGet('entity_test/add');
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value]", '', 'Widget found.');
$this->assertRaw('placeholder="example@example.com"');
......@@ -83,16 +83,18 @@ function testEmailField() {
// Submit a valid e-mail address and ensure it is accepted.
$value = 'test@example.com';
$edit = array(
'user_id' => 1,
'name' => $this->randomName(),
"{$this->field['field_name']}[$langcode][0][value]" => $value,
);
$this->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match);
preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match);
$id = $match[1];
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)));
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)));
$this->assertRaw($value);
// Verify that a mailto link is displayed.
$entity = field_test_entity_test_load($id);
$entity = entity_load('entity_test', $id);
$display = entity_get_display($entity->entityType(), $entity->bundle(), 'full');
$entity->content = field_attach_view($entity, $display);
$this->drupalSetContent(drupal_render($entity->content));
......
......@@ -269,6 +269,9 @@ function field_entity_create(EntityInterface $entity) {
* Defaults to the entity language.
*/
function field_populate_default_values(EntityInterface $entity, $langcode = NULL) {
// Ensure we are working with a BC mode entity.
$entity = $entity->getBCEntity();
$entity_type = $entity->entityType();
$langcode = $langcode ?: $entity->language()->langcode;
foreach (field_info_instances($entity_type, $entity->bundle()) as $field_name => $instance) {
......
......@@ -49,9 +49,13 @@ function _generateTestFieldValues($cardinality) {
* (Optional) the name of the column to check.
*/
function assertFieldValues(EntityInterface $entity, $field_name, $langcode, $expected_values, $column = 'value') {
$e = clone $entity;
field_attach_load('test_entity', array($e->ftid => $e));
$values = isset($e->{$field_name}[$langcode]) ? $e->{$field_name}[$langcode] : array();
// Re-load the entity to make sure we have the latest changes.
entity_get_controller($entity->entityType())->resetCache(array($entity->id()));
$e = entity_load($entity->entityType(), $entity->id());
$field = $values = $e->getTranslation($langcode, FALSE)->$field_name;
// Filter out empty values so that they don't mess with the assertions.
$field->filterEmptyValues();
$values = $field->getValue();
$this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.');
foreach ($expected_values as $key => $value) {
$this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', array('@value' => $value)));
......
......@@ -7,6 +7,7 @@
namespace Drupal\field\Tests;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Language\Language;
class FormTest extends FieldTestBase {
......@@ -679,4 +680,21 @@ function testFieldFormHiddenWidget() {
$entity = field_test_entity_test_load($id);
$this->assertEqual($entity->{$this->field_name}[$langcode][0]['value'], $value, 'New revision has the expected value for the field with the Hidden widget');
}
/**
* {inheritdoc}
*/
function assertFieldValues(EntityInterface $entity, $field_name, $langcode, $expected_values, $column = 'value') {
// Override the base implementation with one that works with the old
// entity API.
// @todo: Remove this when replacing the remaining of test_entity with
// entity_test.
$e = clone $entity;
field_attach_load('test_entity', array($e->ftid => $e));
$values = isset($e->{$field_name}[$langcode]) ? $e->{$field_name}[$langcode] : array();
$this->assertEqual(count($values), count($expected_values), 'Expected number of values were saved.');
foreach ($expected_values as $key => $value) {
$this->assertEqual($values[$key][$column], $value, format_string('Value @value was saved correctly.', array('@value' => $value)));
}
}
}
......@@ -20,7 +20,7 @@ class NumberFieldTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('node', 'field_test', 'number', 'field_ui');
public static $modules = array('node', 'entity_test', 'number', 'field_ui');
protected $field;
protected $instance;
......@@ -37,7 +37,7 @@ public static function getInfo() {
function setUp() {
parent::setUp();
$this->web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content', 'administer content types', 'administer node fields','administer node display'));
$this->web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content', 'administer content types', 'administer node fields','administer node display'));
$this->drupalLogin($this->web_user);
}
......@@ -56,12 +56,12 @@ function testNumberDecimalField() {
field_create_field($this->field);
$this->instance = array(
'field_name' => $this->field['field_name'],
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test',
'bundle' => 'entity_test',
);
field_create_instance($this->instance);
entity_get_form_display('test_entity', 'test_bundle', 'default')
entity_get_form_display('entity_test', 'entity_test', 'default')
->setComponent($this->field['field_name'], array(
'type' => 'number',
'settings' => array(
......@@ -69,14 +69,14 @@ function testNumberDecimalField() {
),
))
->save();
entity_get_display('test_entity', 'test_bundle', 'default')
entity_get_display('entity_test', 'entity_test', 'default')
->setComponent($this->field['field_name'], array(
'type' => 'number_decimal',
))
->save();
// Display creation form.
$this->drupalGet('test-entity/add/test_bundle');
$this->drupalGet('entity_test/add');
$langcode = Language::LANGCODE_NOT_SPECIFIED;
$this->assertFieldByName("{$this->field['field_name']}[$langcode][0][value]", '', 'Widget is displayed');
$this->assertRaw('placeholder="0.00"');
......@@ -84,12 +84,14 @@ function testNumberDecimalField() {
// Submit a signed decimal value within the allowed precision and scale.
$value = '-1234.5678';
$edit = array(
'user_id' => 1,
'name' => $this->randomName(),
"{$this->field['field_name']}[$langcode][0][value]" => $value,
);
$this->drupalPost(NULL, $edit, t('Save'));
preg_match('|test-entity/manage/(\d+)/edit|', $this->url, $match);
preg_match('|entity_test/manage/(\d+)/edit|', $this->url, $match);
$id = $match[1];
$this->assertRaw(t('test_entity @id has been created.', array('@id' => $id)), 'Entity was created');
$this->assertText(t('entity_test @id has been created.', array('@id' => $id)), 'Entity was created');
$this->assertRaw(round($value, 2), 'Value is displayed.');
// Try to create entries with more than one decimal separator; assert fail.
......@@ -102,7 +104,7 @@ function testNumberDecimalField() {
);
foreach ($wrong_entries as $wrong_entry) {
$this->drupalGet('test-entity/add/test_bundle');
$this->drupalGet('entity_test/add');
$edit = array(
"{$this->field['field_name']}[$langcode][0][value]" => $wrong_entry,
);
......@@ -120,7 +122,7 @@ function testNumberDecimalField() {
);
foreach ($wrong_entries as $wrong_entry) {
$this->drupalGet('test-entity/add/test_bundle');
$this->drupalGet('entity_test/add');
$edit = array(
"{$this->field['field_name']}[$langcode][0][value]" => $wrong_entry,
);
......
......@@ -19,7 +19,14 @@ class OptionsDynamicValuesTest extends FieldTestBase {
*
* @var array
*/
public static $modules = array('options', 'field_test', 'options_test');
public static $modules = array('options', 'entity_test', 'options_test');
/**
* The created entity.
*
* @var \Drupal\Core\Entity\Entity
*/
protected $entity;
function setUp() {
parent::setUp();
......@@ -37,25 +44,31 @@ function setUp() {
$this->instance = array(
'field_name' => $this->field_name,
'entity_type' => 'test_entity',
'bundle' => 'test_bundle',
'entity_type' => 'entity_test_rev',
'bundle' => 'entity_test_rev',
'required' => TRUE,
);
$this->instance = field_create_instance($this->instance);
entity_get_form_display('test_entity', 'test_bundle', 'default')
entity_get_form_display('entity_test_rev', 'entity_test_rev', 'default')
->setComponent($this->field_name, array(
'type' => 'options_select',
))
->save();
// Create an entity and prepare test data that will be used by
// options_test_dynamic_values_callback().
$values = array(
'user_id' => mt_rand(1, 10),
'name' => $this->randomName(),
);
$this->entity = entity_create('entity_test_rev', $values);
$this->entity->save();
$uri = $this->entity->uri();
$this->test = array(
'id' => mt_rand(1, 10),
// Make sure this does not equal the ID so that
// options_test_dynamic_values_callback() always returns 4 values.
'vid' => mt_rand(20, 30),
'bundle' => 'test_bundle',
'label' => $this->randomName(),
'label' => $this->entity->label(),
'uuid' => $this->entity->uuid(),
'bundle' => $this->entity->bundle(),
'uri' => $uri['path'],
);
$this->entity = call_user_func_array('field_test_create_entity', $this->test);
}
}
......@@ -28,7 +28,7 @@ public static function getInfo() {
function testDynamicAllowedValues() {
// Verify that the test passes against every value we had.
foreach ($this->test as $key => $value) {
$this->entity->test_options[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = $value;
$this->entity->test_options->value = $value;
try {
field_attach_validate($this->entity);
$this->pass("$key should pass");
......@@ -40,7 +40,7 @@ function testDynamicAllowedValues() {
}
// Now verify that the test does not pass against anything else.
foreach ($this->test as $key => $value) {
$this->entity->test_options[Language::LANGCODE_NOT_SPECIFIED][0]['value'] = is_numeric($value) ? (100 - $value) : ('X' . $value);
$this->entity->test_options->value = is_numeric($value) ? (100 - $value) : ('X' . $value);
$pass = FALSE;
try {
field_attach_validate($this->entity);
......
......@@ -27,11 +27,11 @@ function testSelectListDynamic() {
$this->entity->save();
// Create a web user.
$web_user = $this->drupalCreateUser(array('access field_test content', 'administer field_test content'));
$web_user = $this->drupalCreateUser(array('view test entity', 'administer entity_test content'));
$this->drupalLogin($web_user);
// Display form.
$this->drupalGet('test-entity/manage/' . $this->entity->ftid . '/edit');
$this->drupalGet('entity_test_rev/manage/' . $this->entity->id() . '/edit');
$options = $this->xpath('//select[@id="edit-test-options-und"]/option');
$this->assertEqual(count($options), count($this->test) + 1);
foreach ($options as $option) {
......
......@@ -30,10 +30,11 @@ function options_test_allowed_values_callback($field, $instance, $entity) {
function options_test_dynamic_values_callback($field, $instance, EntityInterface $entity, &$cacheable) {
$cacheable = FALSE;
// We need the values of the entity as keys.
$uri = $entity->uri();
return drupal_map_assoc(array(
$entity->ftlabel,
$entity->id(),
$entity->getRevisionId(),
$entity->label(),
$uri['path'],
$entity->uuid(),
$entity->bundle(),
));
}
......@@ -34,7 +34,7 @@ public static function getInfo() {
*/
function testCRUD() {
// Verify loading of a default mapping.
$mapping = _rdf_mapping_load('test_entity', 'test_bundle');
$mapping = _rdf_mapping_load('entity_test', 'entity_test');
$this->assertTrue(count($mapping), 'Default mapping was found.');
// Verify saving a mapping.
......
......@@ -19,7 +19,7 @@ class MappingHookTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('rdf', 'rdf_test', 'field_test');
public static $modules = array('rdf', 'rdf_test', 'entity_test');
public static function getInfo() {
return array(
......@@ -34,7 +34,7 @@ public static function getInfo() {
*/
function testMapping() {
// Test that the mapping is returned correctly by the hook.
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$mapping = rdf_mapping_load('entity_test', 'entity_test');
$this->assertIdentical($mapping['rdftype'], array('sioc:Post'), 'Mapping for rdftype is sioc:Post.');
$this->assertIdentical($mapping['title'], array('predicates' => array('dc:title')), 'Mapping for title is dc:title.');
$this->assertIdentical($mapping['created'], array(
......@@ -44,7 +44,7 @@ function testMapping() {
), 'Mapping for created is dc:created with datatype xsd:dateTime and callback date_iso8601.');
$this->assertIdentical($mapping['uid'], array('predicates' => array('sioc:has_creator', 'dc:creator'), 'type' => 'rel'), 'Mapping for uid is sioc:has_creator and dc:creator, and type is rel.');
$mapping = rdf_mapping_load('test_entity', 'test_bundle_no_mapping');
$mapping = rdf_mapping_load('entity_test', 'test_bundle_no_mapping');
$this->assertEqual($mapping, array(), 'Empty array returned when an entity type, bundle pair has no mapping.');
}
}
......@@ -20,7 +20,7 @@ class RdfaMarkupTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('rdf', 'field_test', 'rdf_test');
public static $modules = array('rdf', 'entity_test', 'rdf_test');
protected $profile = 'standard';
......@@ -40,7 +40,7 @@ function testDrupalRdfaAttributes() {
$expected_attributes = array(
'property' => array('dc:title'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$mapping = rdf_mapping_load('entity_test', 'entity_test');
$attributes = rdf_rdfa_attributes($mapping['title']);
ksort($expected_attributes);
ksort($attributes);
......@@ -54,7 +54,7 @@ function testDrupalRdfaAttributes() {
'property' => array('dc:created'),
'content' => $isoDate,
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$mapping = rdf_mapping_load('entity_test', 'entity_test');
$attributes = rdf_rdfa_attributes($mapping['created'], $date);
ksort($expected_attributes);
ksort($attributes);
......@@ -65,7 +65,7 @@ function testDrupalRdfaAttributes() {
'datatype' => 'foo:bar1type',
'property' => array('foo:bar1'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$mapping = rdf_mapping_load('entity_test', 'entity_test');
$attributes = rdf_rdfa_attributes($mapping['foobar1']);
ksort($expected_attributes);
ksort($attributes);
......@@ -75,7 +75,7 @@ function testDrupalRdfaAttributes() {
$expected_attributes = array(
'rel' => array('sioc:has_creator', 'dc:creator'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$mapping = rdf_mapping_load('entity_test', 'entity_test');
$attributes = rdf_rdfa_attributes($mapping['foobar_objproperty1']);
ksort($expected_attributes);
ksort($attributes);
......@@ -85,7 +85,7 @@ function testDrupalRdfaAttributes() {
$expected_attributes = array(
'rev' => array('sioc:reply_of'),
);
$mapping = rdf_mapping_load('test_entity', 'test_bundle');
$mapping = rdf_mapping_load('entity_test', 'entity_test');
$attributes = rdf_rdfa_attributes($mapping['foobar_objproperty2']);
ksort($expected_attributes);
ksort($attributes);
......
......@@ -11,8 +11,8 @@
function rdf_test_rdf_mapping() {
return array(
array(
'type' => 'test_entity',
'bundle' => 'test_bundle',
'type' => 'entity_test',
'bundle' => 'entity_test',
'mapping' => array(
'rdftype' => array('sioc:Post'),
'title' => array(
......
......@@ -133,6 +133,27 @@ function entity_test_entity_bundle_info_alter(&$bundles) {
}
}
/**
* Implements hook_entity_view_mode_info_alter().
*/
function entity_test_entity_view_mode_info_alter(&$view_modes) {
$entity_info = entity_get_info();
foreach ($entity_info as $entity_type => $info) {
if ($entity_info[$entity_type]['module'] == 'entity_test') {
$view_modes[$entity_type] = array(
'full' => array(
'label' => t('Full object'),
'status' => TRUE,
),
'teaser' => array(
'label' => t('Teaser'),
'status' => TRUE,
),
);
}
}
}
/**
* Implements hook_field_extra_fields().
*/
......
......@@ -51,9 +51,34 @@ public function form(array $form, array &$form_state) {
'#languages' => Language::STATE_ALL,
);
// @todo: Is there a better way to check if an entity type is revisionable?
$entity_info = $entity->entityInfo();
if (!empty($entity_info['entity_keys']['revision']) && !$entity->isNew()) {
$form['revision'] = array(
'#type' => 'checkbox',
'#title' => t('Create new revision'),
'#default_value' => $entity->isNewRevision(),
);
}
return $form;
}
/**
* Overrides \Drupal\Core\Entity\EntityFormController::submit().
*/
public function submit(array $form, array &$form_state) {
// Build the entity object from the submitted values.
$entity = parent::submit($form, $form_state);
// Save as a new revision if requested to do so.
if (!empty($form_state['values']['revision'])) {
$entity->setNewRevision();
}
return $entity;
}
/**
* Overrides Drupal\Core\Entity\EntityFormController::save().
*/
......
......@@ -23,7 +23,7 @@
* field_cache = FALSE,
* base_table = "entity_test",
* entity_keys = {
* "id" = "ftid",
* "id" = "id",
* "bundle" = "type"
* }
* )
......
......@@ -19,7 +19,7 @@ class TermFieldMultipleVocabularyTest extends TaxonomyTestBase {
*
* @var array
*/