Issue #2384487 by rpayanm, daffie, Sharique, areke: Make the class variables protected for FilterFormat

8.0.x
Alex Pott 2014-12-05 14:38:38 +00:00
parent f503eb9c21
commit 3ec63481f7
17 changed files with 50 additions and 50 deletions

View File

@ -95,7 +95,7 @@ class QuickEditIntegrationTest extends QuickEditTestBase {
// Associate text editor with text format.
$editor = entity_create('editor', array(
'format' => $full_html_format->format,
'format' => $full_html_format->id(),
'editor' => 'unicorn',
));
$editor->save();

View File

@ -156,7 +156,7 @@ function filter_formats(AccountInterface $account = NULL) {
$formats['user'][$account_id] = array();
foreach ($formats['all'] as $format) {
if ($format->access('use', $account)) {
$formats['user'][$account_id][$format->format] = $format;
$formats['user'][$account_id][$format->id()] = $format;
}
}
}
@ -246,7 +246,7 @@ function filter_default_format(AccountInterface $account = NULL) {
// available is the user's default format.
$formats = filter_formats($account);
$format = reset($formats);
return $format->format;
return $format->id();
}
/**
@ -408,7 +408,7 @@ function template_preprocess_filter_guidelines(&$variables) {
$format = $variables['format'];
$variables['tips'] = array(
'#theme' => 'filter_tips',
'#tips' => _filter_tips($format->format, FALSE),
'#tips' => _filter_tips($format->id(), FALSE),
);
}

View File

@ -26,7 +26,7 @@ class FilterController {
* @see template_preprocess_filter_tips()
*/
function filterTips(FilterFormatInterface $filter_format = NULL) {
$tips = $filter_format ? $filter_format->format : -1;
$tips = $filter_format ? $filter_format->id() : -1;
$build = array(
'#theme' => 'filter_tips',

View File

@ -133,7 +133,7 @@ class TextFormat extends RenderElement {
if (!isset($element['#format']) && !empty($formats)) {
// If no text format was selected, use the allowed format with the highest
// weight. This is equivalent to calling filter_default_format().
$element['#format'] = reset($formats)->format;
$element['#format'] = reset($formats)->id();
}
// If #allowed_formats is set, the list of formats must not be modified in

View File

@ -53,7 +53,7 @@ class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, En
*
* @var string
*/
public $format;
protected $format;
/**
* Unique label of the text format.
@ -66,7 +66,7 @@ class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, En
*
* @var string
*/
public $name;
protected $name;
/**
* Weight of this format in the text format selector.
@ -76,7 +76,7 @@ class FilterFormat extends ConfigEntityBase implements FilterFormatInterface, En
*
* @var int
*/
public $weight = 0;
protected $weight = 0;
/**
* List of user role IDs to grant access to use this format on initial creation.

View File

@ -244,13 +244,13 @@ class FilterAdminTest extends WebTestBase {
filter_formats_reset();
$format = entity_load('filter_format', $edit['format']);
$this->assertNotNull($format, 'Format found in database.');
$this->drupalGet('admin/config/content/formats/manage/' . $format->format);
$this->drupalGet('admin/config/content/formats/manage/' . $format->id());
$this->assertFieldByName('roles[' . DRUPAL_AUTHENTICATED_RID . ']', '', 'Role found.');
$this->assertFieldByName('filters[' . $second_filter . '][status]', '', 'Line break filter found.');
$this->assertFieldByName('filters[' . $first_filter . '][status]', '', 'Url filter found.');
// Disable new filter.
$this->drupalPostForm('admin/config/content/formats/manage/' . $format->format . '/disable', array(), t('Disable'));
$this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', array(), t('Disable'));
$this->assertUrl('admin/config/content/formats');
$this->assertRaw(t('Disabled text format %format.', array('%format' => $edit['name'])), 'Format successfully disabled.');
@ -261,7 +261,7 @@ class FilterAdminTest extends WebTestBase {
$edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = 1;
$this->drupalPostForm('admin/config/content/formats/manage/' . $full, $edit, t('Save configuration'));
$this->assertUrl('admin/config/content/formats');
$this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->name)), 'Full HTML format successfully updated.');
$this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->label())), 'Full HTML format successfully updated.');
// Switch user.
$this->drupalLogin($this->web_user);
@ -319,7 +319,7 @@ class FilterAdminTest extends WebTestBase {
$edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'] = FALSE;
$this->drupalPostForm('admin/config/content/formats/manage/' . $full, $edit, t('Save configuration'));
$this->assertUrl('admin/config/content/formats');
$this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->name)), 'Full HTML format successfully reverted.');
$this->assertRaw(t('The text format %format has been updated.', array('%format' => $format->label())), 'Full HTML format successfully reverted.');
$this->drupalGet('admin/config/content/formats/manage/' . $full);
$this->assertFieldByName('roles[' . DRUPAL_AUTHENTICATED_RID . ']', $edit['roles[' . DRUPAL_AUTHENTICATED_RID . ']'], 'Changes reverted.');

View File

@ -29,8 +29,8 @@ class FilterCrudTest extends KernelTestBase {
function testTextFormatCrud() {
// Add a text format with minimum data only.
$format = entity_create('filter_format');
$format->format = 'empty_format';
$format->name = 'Empty format';
$format->set('format', 'empty_format');
$format->set('name', 'Empty format');
$format->save();
$this->verifyTextFormat($format);
@ -49,7 +49,7 @@ class FilterCrudTest extends KernelTestBase {
$this->verifyTextFormat($format);
// Alter some text format properties and save again.
$format->name = 'Altered format';
$format->set('name', 'Altered format');
$format->setFilterConfig('filter_url', array(
'status' => 0,
));
@ -70,21 +70,21 @@ class FilterCrudTest extends KernelTestBase {
$format->disable()->save();
$formats = filter_formats();
$this->assertTrue(!isset($formats[$format->format]), 'filter_formats: Disabled text format no longer exists.');
$this->assertTrue(!isset($formats[$format->id()]), 'filter_formats: Disabled text format no longer exists.');
}
/**
* Verifies that a text format is properly stored.
*/
function verifyTextFormat($format) {
$t_args = array('%format' => $format->name);
$t_args = array('%format' => $format->label());
$default_langcode = \Drupal::languageManager()->getDefaultLanguage()->getId();
// Verify the loaded filter has all properties.
$filter_format = entity_load('filter_format', $format->format);
$this->assertEqual($filter_format->format, $format->format, format_string('filter_format_load: Proper format id for text format %format.', $t_args));
$this->assertEqual($filter_format->name, $format->name, format_string('filter_format_load: Proper title for text format %format.', $t_args));
$this->assertEqual($filter_format->weight, $format->weight, format_string('filter_format_load: Proper weight for text format %format.', $t_args));
$filter_format = entity_load('filter_format', $format->id());
$this->assertEqual($filter_format->id(), $format->id(), format_string('filter_format_load: Proper format id for text format %format.', $t_args));
$this->assertEqual($filter_format->label(), $format->label(), format_string('filter_format_load: Proper title for text format %format.', $t_args));
$this->assertEqual($filter_format->get('weight'), $format->get('weight'), format_string('filter_format_load: Proper weight for text format %format.', $t_args));
// Check that the filter was created in site default language.
$this->assertEqual($format->language()->getId(), $default_langcode, format_string('filter_format_load: Proper language code for text format %format.', $t_args));
}

View File

@ -50,24 +50,24 @@ class FilterDefaultFormatTest extends WebTestBase {
// Adjust the weights so that the first and second formats (in that order)
// are the two lowest weighted formats available to any user.
$edit = array();
$edit['formats[' . $first_format->format . '][weight]'] = -2;
$edit['formats[' . $second_format->format . '][weight]'] = -1;
$edit['formats[' . $first_format->id() . '][weight]'] = -2;
$edit['formats[' . $second_format->id() . '][weight]'] = -1;
$this->drupalPostForm('admin/config/content/formats', $edit, t('Save changes'));
$this->resetFilterCaches();
// Check that each user's default format is the lowest weighted format that
// the user has access to.
$actual = filter_default_format($first_user);
$expected = $first_format->format;
$expected = $first_format->id();
$this->assertEqual($actual, $expected, "First user's default format $actual is the expected lowest weighted format $expected that the user has access to.");
$actual = filter_default_format($second_user);
$expected = $second_format->format;
$expected = $second_format->id();
$this->assertEqual($actual, $expected, "Second user's default format $actual is the expected lowest weighted format $expected that the user has access to, and different to the first user's.");
// Reorder the two formats, and check that both users now have the same
// default.
$edit = array();
$edit['formats[' . $second_format->format . '][weight]'] = -3;
$edit['formats[' . $second_format->id() . '][weight]'] = -3;
$this->drupalPostForm('admin/config/content/formats', $edit, t('Save changes'));
$this->resetFilterCaches();
$this->assertEqual(filter_default_format($first_user), filter_default_format($second_user), 'After the formats are reordered, both users have the same default format.');

View File

@ -132,8 +132,8 @@ class FilterFormatAccessTest extends WebTestBase {
// Perform similar checks as above, but now against the entire list of
// available formats for this user.
$this->assertTrue(in_array($this->allowed_format->format, array_keys(filter_formats($this->web_user))), 'The allowed format appears in the list of available formats for a regular user.');
$this->assertFalse(in_array($this->disallowed_format->format, array_keys(filter_formats($this->web_user))), 'The disallowed format does not appear in the list of available formats for a regular user.');
$this->assertTrue(in_array($this->allowed_format->id(), array_keys(filter_formats($this->web_user))), 'The allowed format appears in the list of available formats for a regular user.');
$this->assertFalse(in_array($this->disallowed_format->id(), array_keys(filter_formats($this->web_user))), 'The disallowed format does not appear in the list of available formats for a regular user.');
$this->assertTrue(in_array(filter_fallback_format(), array_keys(filter_formats($this->web_user))), 'The fallback format appears in the list of available formats for a regular user.');
// Make sure that a regular user only has permission to use the format
@ -147,20 +147,20 @@ class FilterFormatAccessTest extends WebTestBase {
$this->drupalGet('node/add/page');
$elements = $this->xpath('//select[@name=:name]/option', array(
':name' => 'body[0][format]',
':option' => $this->allowed_format->format,
':option' => $this->allowed_format->id(),
));
$options = array();
foreach ($elements as $element) {
$options[(string) $element['value']] = $element;
}
$this->assertTrue(isset($options[$this->allowed_format->format]), 'The allowed text format appears as an option when adding a new node.');
$this->assertFalse(isset($options[$this->disallowed_format->format]), 'The disallowed text format does not appear as an option when adding a new node.');
$this->assertTrue(isset($options[$this->allowed_format->id()]), 'The allowed text format appears as an option when adding a new node.');
$this->assertFalse(isset($options[$this->disallowed_format->id()]), 'The disallowed text format does not appear as an option when adding a new node.');
$this->assertFalse(isset($options[filter_fallback_format()]), 'The fallback format does not appear as an option when adding a new node.');
// Check regular user access to the filter tips pages.
$this->drupalGet('filter/tips/' . $this->allowed_format->format);
$this->drupalGet('filter/tips/' . $this->allowed_format->id());
$this->assertResponse(200);
$this->drupalGet('filter/tips/' . $this->disallowed_format->format);
$this->drupalGet('filter/tips/' . $this->disallowed_format->id());
$this->assertResponse(403);
$this->drupalGet('filter/tips/' . filter_fallback_format());
$this->assertResponse(200);
@ -169,9 +169,9 @@ class FilterFormatAccessTest extends WebTestBase {
// Check admin user access to the filter tips pages.
$this->drupalLogin($this->admin_user);
$this->drupalGet('filter/tips/' . $this->allowed_format->format);
$this->drupalGet('filter/tips/' . $this->allowed_format->id());
$this->assertResponse(200);
$this->drupalGet('filter/tips/' . $this->disallowed_format->format);
$this->drupalGet('filter/tips/' . $this->disallowed_format->id());
$this->assertResponse(200);
$this->drupalGet('filter/tips/' . filter_fallback_format());
$this->assertResponse(200);
@ -195,8 +195,8 @@ class FilterFormatAccessTest extends WebTestBase {
// Check that the correct text format appears in the list of formats
// available to that role.
$this->assertTrue(in_array($this->allowed_format->format, array_keys(filter_get_formats_by_role($rid))), 'A text format which a role has access to appears in the list of formats available to that role.');
$this->assertFalse(in_array($this->disallowed_format->format, array_keys(filter_get_formats_by_role($rid))), 'A text format which a role does not have access to does not appear in the list of formats available to that role.');
$this->assertTrue(in_array($this->allowed_format->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role has access to appears in the list of formats available to that role.');
$this->assertFalse(in_array($this->disallowed_format->id(), array_keys(filter_get_formats_by_role($rid))), 'A text format which a role does not have access to does not appear in the list of formats available to that role.');
// Check that the fallback format is always allowed.
$this->assertEqual(filter_get_roles_by_format(entity_load('filter_format', filter_fallback_format())), user_role_names(), 'All roles have access to the fallback format.');
@ -221,7 +221,7 @@ class FilterFormatAccessTest extends WebTestBase {
$edit = array();
$edit['title[0][value]'] = $this->randomMachineName(8);
$edit[$body_value_key] = $this->randomMachineName(16);
$edit[$body_format_key] = $this->disallowed_format->format;
$edit[$body_format_key] = $this->disallowed_format->id();
$this->drupalPostForm('node/add/page', $edit, t('Save'));
$node = $this->drupalGetNodeByTitle($edit['title[0][value]']);
@ -294,7 +294,7 @@ class FilterFormatAccessTest extends WebTestBase {
// Switch the text format to a new one, then disable that format and all
// other formats on the site (leaving only the fallback format).
$this->drupalLogin($this->admin_user);
$edit = array($body_format_key => $this->allowed_format->format);
$edit = array($body_format_key => $this->allowed_format->id());
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, t('Save'));
$this->assertUrl('node/' . $node->id());
foreach (filter_formats() as $format) {

View File

@ -203,7 +203,7 @@ class QuickEditAutocompleteTermTest extends WebTestBase {
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
// Use the first available text format.
'format' => $format->format,
'format' => $format->id(),
'vid' => $this->vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));

View File

@ -115,7 +115,7 @@ class BreadcrumbTest extends MenuTestBase {
// Verify Filter text format administration breadcrumbs.
$filter_formats = filter_formats();
$format = reset($filter_formats);
$format_id = $format->format;
$format_id = $format->id();
$trail = $config + array(
'admin/config/content' => t('Content authoring'),
);

View File

@ -69,7 +69,7 @@ abstract class TaxonomyTestBase extends WebTestBase {
'description' => array(
'value' => $this->randomMachineName(),
// Use the first available text format.
'format' => $format->format,
'format' => $format->id(),
),
'vid' => $vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,

View File

@ -168,7 +168,7 @@ class TaxonomyFieldFilterTest extends ViewTestBase {
$term = entity_create('taxonomy_term', array(
'name' => $properties['name'],
'description' => $properties['description'],
'format' => $format->format,
'format' => $format->id(),
'vid' => $this->vocabulary->id(),
'langcode' => $properties['langcode'],
));

View File

@ -134,7 +134,7 @@ abstract class TaxonomyTestBase extends ViewTestBase {
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
// Use the first available text format.
'format' => $format->format,
'format' => $format->id(),
'vid' => $this->vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));

View File

@ -114,7 +114,7 @@ class TextFieldTest extends StringFieldTest {
$this->drupalLogin($this->adminUser);
foreach (filter_formats() as $format) {
if (!$format->isFallbackFormat()) {
$this->drupalPostForm('admin/config/content/formats/manage/' . $format->format . '/disable', array(), t('Disable'));
$this->drupalPostForm('admin/config/content/formats/manage/' . $format->id() . '/disable', array(), t('Disable'));
}
}
$this->drupalLogin($this->webUser);
@ -153,7 +153,7 @@ class TextFieldTest extends StringFieldTest {
$this->drupalPostForm('admin/config/content/formats/add', $edit, t('Save configuration'));
filter_formats_reset();
$format = entity_load('filter_format', $edit['format']);
$format_id = $format->format;
$format_id = $format->id();
$permission = $format->getPermissionName();
$roles = $this->webUser->getRoles();
$rid = $roles[0];

View File

@ -119,13 +119,13 @@ class UserSignatureTest extends WebTestBase {
// Log in as an administrator and edit the comment to use Full HTML, so
// that the comment text itself is not filtered at all.
$this->drupalLogin($this->admin_user);
$edit['comment_body[0][format]'] = $this->full_html_format->format;
$edit['comment_body[0][format]'] = $this->full_html_format->id();
$this->drupalPostForm('comment/' . $comment_id . '/edit', $edit, t('Save'));
// Assert that the signature did not make it through unfiltered.
$this->drupalGet('node/' . $node->id());
$this->assertNoRaw($signature_text, 'Unfiltered signature text not found.');
$this->assertRaw(check_markup($signature_text, $this->filtered_html_format->format), 'Filtered signature text found.');
$this->assertRaw(check_markup($signature_text, $this->filtered_html_format->id()), 'Filtered signature text found.');
// Verify that the user signature's text format's cache tag is present.
$this->drupalGet('node/' . $node->id());
$this->assertTrue(in_array('filter_format:filtered_html_format', explode(' ', $this->drupalGetHeader('X-Drupal-Cache-Tags'))));

View File

@ -158,7 +158,7 @@ class DefaultViewsTest extends ViewTestBase {
'name' => $this->randomMachineName(),
'description' => $this->randomMachineName(),
// Use the first available text format.
'format' => $format->format,
'format' => $format->id(),
'vid' => $vocabulary->id(),
'langcode' => LanguageInterface::LANGCODE_NOT_SPECIFIED,
));