diff --git a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php index d4b1bda..202757f 100644 --- a/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php +++ b/core/modules/filter/lib/Drupal/filter/Tests/FilterAPITest.php @@ -7,16 +7,17 @@ namespace Drupal\filter\Tests; -use Drupal\simpletest\DrupalUnitTestBase; +use Drupal\Core\TypedData\AllowedValuesInterface; use Drupal\filter\Type\FilterFormat; +use Drupal\system\Tests\Entity\EntityUnitTestBase; use Symfony\Component\Validator\ConstraintViolationListInterface; /** * Tests the behavior of Filter's API. */ -class FilterAPITest extends DrupalUnitTestBase { +class FilterAPITest extends EntityUnitTestBase { - public static $modules = array('system', 'filter', 'filter_test'); + public static $modules = array('system', 'filter', 'filter_test', 'user'); public static function getInfo() { return array( @@ -29,7 +30,8 @@ public static function getInfo() { function setUp() { parent::setUp(); - $this->installConfig(array('system')); + $this->installConfig(array('system', 'filter')); + $this->installSchema('user', array('role_permission', 'users_roles')); // Create Filtered HTML format. $filtered_html_format = entity_create('filter_format', array( @@ -193,65 +195,61 @@ function testTypedDataAPI() { $definition = array('type' => 'filter_format'); $data = \Drupal::typedData()->create($definition); - if ($this->assertTrue($data instanceof \Drupal\Core\TypedData\AllowedValuesInterface, 'Typed data object implements \Drupal\Core\TypedData\AllowedValuesInterface')) { - $this->checkPermissions(array(), TRUE); - $filtered_html_user = $this->drupalCreateUser(array( - filter_permission_name(filter_format_load('filtered_html')), - )); - // Test with anonymous user. - $GLOBALS['user'] = drupal_anonymous_user(); + $this->assertTrue($data instanceof AllowedValuesInterface, 'Typed data object implements \Drupal\Core\TypedData\AllowedValuesInterface'); - $available_values = $data->getAvailableValues(); - $this->assertEqual( - $available_values, - array('filtered_html', 'full_html', 'plain_text'), - 'Expected available format values found' - ); - $available_options = $data->getAvailableOptions(); - $expected_available_options = array( - 'filtered_html' => 'Filtered HTML', - 'full_html' => 'Full HTML', - 'plain_text' => 'Plain text', - ); - $this->assertEqual($available_options, $expected_available_options); - $allowed_values = $data->getValues(); - $this->assertEqual($allowed_values, array('plain_text')); - $allowed_options = $data->getOptions(); - $this->assertEqual($allowed_options, array('plain_text' => 'Plain text')); + $filtered_html_user = $this->createUser(array('uid' => 2), array( + filter_permission_name(filter_format_load('filtered_html')), + )); - $data->setValue('foo'); - $violations = $data->validate(); - $this->assertFilterFormatViolation($violations, 'foo'); + // Test with anonymous user. + $GLOBALS['user'] = drupal_anonymous_user(); - // Make sure the information provided by a violation is correct. - $violation = $violations[0]; - $this->assertEqual($violation->getRoot(), $data, 'Violation root is filter format.'); - $this->assertEqual($violation->getPropertyPath(), '', 'Violation property path is correct.'); - $this->assertEqual($violation->getInvalidValue(), 'foo', 'Violation contains invalid value.'); + $available_values = $data->getAvailableValues(); + $this->assertEqual($available_values, array('filtered_html', 'full_html', 'plain_text')); + $available_options = $data->getAvailableOptions(); + $expected_available_options = array( + 'filtered_html' => 'Filtered HTML', + 'full_html' => 'Full HTML', + 'plain_text' => 'Plain text', + ); + $this->assertEqual($available_options, $expected_available_options); + $allowed_values = $data->getValues(); + $this->assertEqual($allowed_values, array('plain_text')); + $allowed_options = $data->getOptions(); + $this->assertEqual($allowed_options, array('plain_text' => 'Plain text')); - $data->setValue('plain_text'); - $violations = $data->validate(); - $this->assertEqual(count($violations), 0, "No validation violation for format 'plain_text' found"); + $data->setValue('foo'); + $violations = $data->validate(); + $this->assertFilterFormatViolation($violations, 'foo'); - // Anonymous doesn't have access to the 'filtered_html' format. - $data->setValue('filtered_html'); - $violations = $data->validate(); - $this->assertFilterFormatViolation($violations, 'filtered_html'); + // Make sure the information provided by a violation is correct. + $violation = $violations[0]; + $this->assertEqual($violation->getRoot(), $data, 'Violation root is filter format.'); + $this->assertEqual($violation->getPropertyPath(), '', 'Violation property path is correct.'); + $this->assertEqual($violation->getInvalidValue(), 'foo', 'Violation contains invalid value.'); - // Set user with access to 'filtered_html' format. - $GLOBALS['user'] = $filtered_html_user; - $violations = $data->validate(); - $this->assertEqual(count($violations), 0, "No validation violation for accessible format 'filtered_html' found."); + $data->setValue('plain_text'); + $violations = $data->validate(); + $this->assertEqual(count($violations), 0, "No validation violation for format 'plain_text' found"); - $allowed_values = $data->getValues(); - $this->assertEqual($allowed_values, array('filtered_html', 'plain_text')); - $allowed_options = $data->getOptions(); - $expected_allowed_options = array( - 'filtered_html' => 'Filtered HTML', - 'plain_text' => 'Plain text', - ); - $this->assertEqual($allowed_options, $expected_allowed_options); - } + // Anonymous doesn't have access to the 'filtered_html' format. + $data->setValue('filtered_html'); + $violations = $data->validate(); + $this->assertFilterFormatViolation($violations, 'filtered_html'); + + // Set user with access to 'filtered_html' format. + $GLOBALS['user'] = $filtered_html_user; + $violations = $data->validate(); + $this->assertEqual(count($violations), 0, "No validation violation for accessible format 'filtered_html' found."); + + $allowed_values = $data->getValues(); + $this->assertEqual($allowed_values, array('filtered_html', 'plain_text')); + $allowed_options = $data->getOptions(); + $expected_allowed_options = array( + 'filtered_html' => 'Filtered HTML', + 'plain_text' => 'Plain text', + ); + $this->assertEqual($allowed_options, $expected_allowed_options); } /**