Move into nested docroot
This commit is contained in:
parent
83a0d3a149
commit
c8b70abde9
13405 changed files with 0 additions and 0 deletions
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Kernel\Migrate;
|
||||
|
||||
use Drupal\config\Tests\SchemaCheckTestTrait;
|
||||
use Drupal\Tests\migrate_drupal\Kernel\d6\MigrateDrupal6TestBase;
|
||||
|
||||
/**
|
||||
* Upgrade variables to text.settings.yml.
|
||||
*
|
||||
* @group migrate_drupal_6
|
||||
*/
|
||||
class MigrateTextConfigsTest extends MigrateDrupal6TestBase {
|
||||
|
||||
use SchemaCheckTestTrait;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
$this->executeMigration('text_settings');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests migration of text variables to text.settings.yml.
|
||||
*/
|
||||
public function testTextSettings() {
|
||||
$config = $this->config('text.settings');
|
||||
$this->assertIdentical(456, $config->get('default_summary_length'));
|
||||
$this->assertConfigSchema(\Drupal::service('config.typed'), 'text.settings', $config->get());
|
||||
}
|
||||
|
||||
}
|
98
web/core/modules/text/tests/src/Kernel/TextFormatterTest.php
Normal file
98
web/core/modules/text/tests/src/Kernel/TextFormatterTest.php
Normal file
|
@ -0,0 +1,98 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Kernel;
|
||||
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
|
||||
/**
|
||||
* Tests the text formatters functionality.
|
||||
*
|
||||
* @group text
|
||||
*/
|
||||
class TextFormatterTest extends EntityKernelTestBase {
|
||||
|
||||
/**
|
||||
* The entity type used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $entityType = 'entity_test';
|
||||
|
||||
/**
|
||||
* The bundle used in this test.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $bundle = 'entity_test';
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('text');
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
FilterFormat::create(array(
|
||||
'format' => 'my_text_format',
|
||||
'name' => 'My text format',
|
||||
'filters' => array(
|
||||
'filter_autop' => array(
|
||||
'module' => 'filter',
|
||||
'status' => TRUE,
|
||||
),
|
||||
),
|
||||
))->save();
|
||||
|
||||
FieldStorageConfig::create(array(
|
||||
'field_name' => 'formatted_text',
|
||||
'entity_type' => $this->entityType,
|
||||
'type' => 'text',
|
||||
'settings' => array(),
|
||||
))->save();
|
||||
FieldConfig::create([
|
||||
'entity_type' => $this->entityType,
|
||||
'bundle' => $this->bundle,
|
||||
'field_name' => 'formatted_text',
|
||||
'label' => 'Filtered text',
|
||||
])->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests all text field formatters.
|
||||
*/
|
||||
public function testFormatters() {
|
||||
$formatters = array(
|
||||
'text_default',
|
||||
'text_trimmed',
|
||||
'text_summary_or_trimmed',
|
||||
);
|
||||
|
||||
// Create the entity to be referenced.
|
||||
$entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($this->entityType)
|
||||
->create(array('name' => $this->randomMachineName()));
|
||||
$entity->formatted_text = array(
|
||||
'value' => 'Hello, world!',
|
||||
'format' => 'my_text_format',
|
||||
);
|
||||
$entity->save();
|
||||
|
||||
foreach ($formatters as $formatter) {
|
||||
// Verify the text field formatter's render array.
|
||||
$build = $entity->get('formatted_text')->view(array('type' => $formatter));
|
||||
\Drupal::service('renderer')->renderRoot($build[0]);
|
||||
$this->assertEqual($build[0]['#markup'], "<p>Hello, world!</p>\n");
|
||||
$this->assertEqual($build[0]['#cache']['tags'], FilterFormat::load('my_text_format')->getCacheTags(), format_string('The @formatter formatter has the expected cache tags when formatting a formatted text field.', array('@formatter' => $formatter)));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
216
web/core/modules/text/tests/src/Kernel/TextSummaryTest.php
Normal file
216
web/core/modules/text/tests/src/Kernel/TextSummaryTest.php
Normal file
|
@ -0,0 +1,216 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Kernel;
|
||||
|
||||
use Drupal\KernelTests\KernelTestBase;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
* Tests text_summary() with different strings and lengths.
|
||||
*
|
||||
* @group text
|
||||
*/
|
||||
class TextSummaryTest extends KernelTestBase {
|
||||
|
||||
public static $modules = array('system', 'user', 'filter', 'text');
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installConfig(array('text'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests an edge case where the first sentence is a question and
|
||||
* subsequent sentences are not. This edge case is documented at
|
||||
* https://www.drupal.org/node/180425.
|
||||
*/
|
||||
function testFirstSentenceQuestion() {
|
||||
$text = 'A question? A sentence. Another sentence.';
|
||||
$expected = 'A question? A sentence.';
|
||||
$this->assertTextSummary($text, $expected, NULL, 30);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test summary with long example.
|
||||
*/
|
||||
function testLongSentence() {
|
||||
$text = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' . // 125
|
||||
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' . // 108
|
||||
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. ' . // 103
|
||||
'Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; // 110
|
||||
$expected = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. ' .
|
||||
'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. ' .
|
||||
'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur.';
|
||||
// First three sentences add up to: 336, so add one for space and then 3 to get half-way into next word.
|
||||
$this->assertTextSummary($text, $expected, NULL, 340);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test various summary length edge cases.
|
||||
*/
|
||||
function testLength() {
|
||||
FilterFormat::create(array(
|
||||
'format' => 'autop',
|
||||
'filters' => array(
|
||||
'filter_autop' => array(
|
||||
'status' => 1,
|
||||
),
|
||||
),
|
||||
))->save();
|
||||
FilterFormat::create(array(
|
||||
'format' => 'autop_correct',
|
||||
'filters' => array(
|
||||
'filter_autop' => array(
|
||||
'status' => 1,
|
||||
),
|
||||
'filter_htmlcorrector' => array(
|
||||
'status' => 1,
|
||||
),
|
||||
),
|
||||
))->save();
|
||||
|
||||
// This string tests a number of edge cases.
|
||||
$text = "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>";
|
||||
|
||||
// The summaries we expect text_summary() to return when $size is the index
|
||||
// of each array item.
|
||||
// Using no text format:
|
||||
$format = NULL;
|
||||
$i = 0;
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\n", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nH", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n<", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
|
||||
// Using a text format with filter_autop enabled.
|
||||
$format = 'autop';
|
||||
$i = 0;
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
|
||||
// Using a text format with filter_autop and filter_htmlcorrector enabled.
|
||||
$format = 'autop_correct';
|
||||
$i = 0;
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p></p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p></p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p></p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p></p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p></p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
$this->assertTextSummary($text, "<p>\nHi\n</p>\n<p>\nfolks\n<br />\n!\n</p>", $format, $i++);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls text_summary() and asserts that the expected teaser is returned.
|
||||
*/
|
||||
function assertTextSummary($text, $expected, $format = NULL, $size = NULL) {
|
||||
$summary = text_summary($text, $format, $size);
|
||||
$this->assertIdentical($summary, $expected, format_string('<pre style="white-space: pre-wrap">@actual</pre> is identical to <pre style="white-space: pre-wrap">@expected</pre>', array(
|
||||
'@actual' => $summary,
|
||||
'@expected' => $expected,
|
||||
)));
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,119 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Kernel;
|
||||
|
||||
use Drupal\Core\Field\FieldItemListInterface;
|
||||
use Drupal\Core\Field\FieldItemInterface;
|
||||
use Drupal\field\Entity\FieldConfig;
|
||||
use Drupal\Tests\field\Kernel\FieldKernelTestBase;
|
||||
use Drupal\field\Entity\FieldStorageConfig;
|
||||
use Drupal\filter\Entity\FilterFormat;
|
||||
|
||||
/**
|
||||
* Tests using entity fields of the text summary field type.
|
||||
*
|
||||
* @group text
|
||||
*/
|
||||
class TextWithSummaryItemTest extends FieldKernelTestBase {
|
||||
|
||||
/**
|
||||
* Modules to enable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $modules = array('filter');
|
||||
|
||||
/**
|
||||
* Field storage entity.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldStorageConfig.
|
||||
*/
|
||||
protected $fieldStorage;
|
||||
|
||||
/**
|
||||
* Field entity.
|
||||
*
|
||||
* @var \Drupal\field\Entity\FieldConfig
|
||||
*/
|
||||
protected $field;
|
||||
|
||||
|
||||
protected function setUp() {
|
||||
parent::setUp();
|
||||
|
||||
$this->installEntitySchema('entity_test_rev');
|
||||
|
||||
// Create the necessary formats.
|
||||
$this->installConfig(array('filter'));
|
||||
FilterFormat::create(array(
|
||||
'format' => 'no_filters',
|
||||
'filters' => array(),
|
||||
))->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests processed properties.
|
||||
*/
|
||||
public function testCrudAndUpdate() {
|
||||
$entity_type = 'entity_test';
|
||||
$this->createField($entity_type);
|
||||
|
||||
// Create an entity with a summary and no text format.
|
||||
$storage = $this->container->get('entity_type.manager')
|
||||
->getStorage($entity_type);
|
||||
$entity = $storage->create();
|
||||
$entity->summary_field->value = $value = $this->randomMachineName();
|
||||
$entity->summary_field->summary = $summary = $this->randomMachineName();
|
||||
$entity->summary_field->format = NULL;
|
||||
$entity->name->value = $this->randomMachineName();
|
||||
$entity->save();
|
||||
|
||||
$entity = $storage->load($entity->id());
|
||||
$this->assertTrue($entity->summary_field instanceof FieldItemListInterface, 'Field implements interface.');
|
||||
$this->assertTrue($entity->summary_field[0] instanceof FieldItemInterface, 'Field item implements interface.');
|
||||
$this->assertEqual($entity->summary_field->value, $value);
|
||||
$this->assertEqual($entity->summary_field->summary, $summary);
|
||||
$this->assertNull($entity->summary_field->format);
|
||||
// Even if no format is given, if text processing is enabled, the default
|
||||
// format is used.
|
||||
$this->assertEqual($entity->summary_field->processed, "<p>$value</p>\n");
|
||||
$this->assertEqual($entity->summary_field->summary_processed, "<p>$summary</p>\n");
|
||||
|
||||
// Change the format, this should update the processed properties.
|
||||
$entity->summary_field->format = 'no_filters';
|
||||
$this->assertEqual($entity->summary_field->processed, $value);
|
||||
$this->assertEqual($entity->summary_field->summary_processed, $summary);
|
||||
|
||||
// Test the generateSampleValue() method.
|
||||
$entity = $this->container->get('entity_type.manager')
|
||||
->getStorage($entity_type)
|
||||
->create();
|
||||
$entity->summary_field->generateSampleItems();
|
||||
$this->entityValidateAndSave($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a text_with_summary field storage and field.
|
||||
*
|
||||
* @param string $entity_type
|
||||
* Entity type for which the field should be created.
|
||||
*/
|
||||
protected function createField($entity_type) {
|
||||
// Create a field .
|
||||
$this->fieldStorage = FieldStorageConfig::create(array(
|
||||
'field_name' => 'summary_field',
|
||||
'entity_type' => $entity_type,
|
||||
'type' => 'text_with_summary',
|
||||
'settings' => array(
|
||||
'max_length' => 10,
|
||||
)
|
||||
));
|
||||
$this->fieldStorage->save();
|
||||
$this->field = FieldConfig::create([
|
||||
'field_storage' => $this->fieldStorage,
|
||||
'bundle' => $entity_type,
|
||||
]);
|
||||
$this->field->save();
|
||||
}
|
||||
|
||||
}
|
165
web/core/modules/text/tests/src/Unit/Migrate/TextFieldTest.php
Normal file
165
web/core/modules/text/tests/src/Unit/Migrate/TextFieldTest.php
Normal file
|
@ -0,0 +1,165 @@
|
|||
<?php
|
||||
|
||||
namespace Drupal\Tests\text\Unit\Migrate;
|
||||
|
||||
use Drupal\migrate\Plugin\MigrationInterface;
|
||||
use Drupal\migrate\Row;
|
||||
use Drupal\Tests\UnitTestCase;
|
||||
use Drupal\text\Plugin\migrate\cckfield\TextField;
|
||||
use Prophecy\Argument;
|
||||
|
||||
/**
|
||||
* @coversDefaultClass \Drupal\text\Plugin\migrate\cckfield\TextField
|
||||
* @group text
|
||||
*/
|
||||
class TextFieldTest extends UnitTestCase {
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate_drupal\Plugin\MigrateCckFieldInterface
|
||||
*/
|
||||
protected $plugin;
|
||||
|
||||
/**
|
||||
* @var \Drupal\migrate\Plugin\MigrationInterface
|
||||
*/
|
||||
protected $migration;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function setUp() {
|
||||
$this->plugin = new TextField([], 'text', []);
|
||||
|
||||
$migration = $this->prophesize(MigrationInterface::class);
|
||||
|
||||
// The plugin's processCckFieldValues() method will call
|
||||
// setProcessOfProperty() and return nothing. So, in order to examine the
|
||||
// process pipeline created by the plugin, we need to ensure that
|
||||
// getProcess() always returns the last input to setProcessOfProperty().
|
||||
$migration->setProcessOfProperty(Argument::type('string'), Argument::type('array'))
|
||||
->will(function($arguments) use ($migration) {
|
||||
$migration->getProcess()->willReturn($arguments[1]);
|
||||
});
|
||||
|
||||
$this->migration = $migration->reveal();
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessFilteredTextFieldValues() {
|
||||
$field_info = [
|
||||
'widget_type' => 'text_textfield',
|
||||
];
|
||||
$this->plugin->processCckFieldValues($this->migration, 'body', $field_info);
|
||||
|
||||
$process = $this->migration->getProcess();
|
||||
$this->assertSame('iterator', $process['plugin']);
|
||||
$this->assertSame('body', $process['source']);
|
||||
$this->assertSame('value', $process['process']['value']);
|
||||
|
||||
// Ensure that filter format IDs will be looked up in the filter format
|
||||
// migrations.
|
||||
$lookup = $process['process']['format'][2];
|
||||
$this->assertSame('migration', $lookup['plugin']);
|
||||
$this->assertContains('d6_filter_format', $lookup['migration']);
|
||||
$this->assertContains('d7_filter_format', $lookup['migration']);
|
||||
$this->assertSame('format', $lookup['source']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessBooleanTextImplicitValues() {
|
||||
$info = array(
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => array(
|
||||
'allowed_values' => "foo\nbar",
|
||||
)
|
||||
);
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'bar' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::processCckFieldValues
|
||||
*/
|
||||
public function testProcessBooleanTextExplicitValues() {
|
||||
$info = array(
|
||||
'widget_type' => 'optionwidgets_onoff',
|
||||
'global_settings' => array(
|
||||
'allowed_values' => "foo|Foo\nbaz|Baz",
|
||||
)
|
||||
);
|
||||
$this->plugin->processCckFieldValues($this->migration, 'field', $info);
|
||||
|
||||
$expected = [
|
||||
'value' => [
|
||||
'plugin' => 'static_map',
|
||||
'source' => 'value',
|
||||
'default_value' => 0,
|
||||
'map' => [
|
||||
'baz' => 1,
|
||||
],
|
||||
],
|
||||
];
|
||||
$this->assertSame($expected, $this->migration->getProcess()['process']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Data provider for testGetFieldType().
|
||||
*/
|
||||
public function getFieldTypeProvider() {
|
||||
return array(
|
||||
array('string_long', 'text_textfield', array(
|
||||
'text_processing' => FALSE,
|
||||
)),
|
||||
array('string', 'text_textfield', array(
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 128,
|
||||
)),
|
||||
array('string_long', 'text_textfield', array(
|
||||
'text_processing' => FALSE,
|
||||
'max_length' => 4096,
|
||||
)),
|
||||
array('text_long', 'text_textfield', array(
|
||||
'text_processing' => TRUE,
|
||||
)),
|
||||
array('text', 'text_textfield', array(
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 128,
|
||||
)),
|
||||
array('text_long', 'text_textfield', array(
|
||||
'text_processing' => TRUE,
|
||||
'max_length' => 4096,
|
||||
)),
|
||||
array('list_string', 'optionwidgets_buttons'),
|
||||
array('list_string', 'optionwidgets_select'),
|
||||
array('boolean', 'optionwidgets_onoff'),
|
||||
array('text_long', 'text_textarea'),
|
||||
array(NULL, 'undefined'),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ::getFieldType
|
||||
* @dataProvider getFieldTypeProvider
|
||||
*/
|
||||
public function testGetFieldType($expected_type, $widget_type, array $settings = array()) {
|
||||
$row = new Row(array('widget_type' => $widget_type), array('widget_type' => array()));
|
||||
$row->setSourceProperty('global_settings', $settings);
|
||||
$this->assertSame($expected_type, $this->plugin->getFieldType($row));
|
||||
}
|
||||
|
||||
}
|
Reference in a new issue