protected function ScannerBaseTestCase::generateSampleContent in Search and Replace Scanner 7
Generate some sample content.
This mirrors some of the logic from devel_generate_content() with the exception that it specifically tries to ensure the custom word $this->searchWord is present in the title and/or body field of some content.
Parameters
int $count: The number of nodes to generate with a minimum of five; defaults to 20.
string $content_type: The content type to generate; defaults to 'article'.
3 calls to ScannerBaseTestCase::generateSampleContent()
- ScannerBasicsTestCase::setUp in tests/
ScannerBasicsTestCase.test - Sets up a Drupal site for running functional and integration tests.
- ScannerWithFieldCollectionTestCase::setUp in tests/
ScannerWithFieldCollectionTestCase.test - Sets up a Drupal site for running functional and integration tests.
- ScannerWithLinkTestCase::setUp in tests/
ScannerWithLinkTestCase.test - Sets up a Drupal site for running functional and integration tests.
File
- tests/
ScannerBaseTestCase.test, line 92 - Base test class to make other tests simpler.
Class
- ScannerBaseTestCase
- Base test class to make other tests simpler.
Code
protected function generateSampleContent($count = 20, $content_type = 'article') {
// A minimum of five.
if ($count < 5) {
$count = 5;
}
// Replace devel_generate_content() so that the content can be customized.
module_load_include('inc', 'devel_generate');
module_load_include('inc', 'devel_generate', 'devel_generate.fields');
for ($x = 0; $x < $count; $x++) {
$node = new StdClass();
$node->type = $content_type;
$node->revision = 0;
$node->promote = 0;
$node->status = 1;
$node->uid = 1;
$node->language = LANGUAGE_NONE;
$node->devel_generate = array(
'word' => $this->searchWord,
);
// A portion of nodes will have the custom word inserted.
if (mt_rand(0, 5) == 5) {
$node->title = devel_create_greeking(2, TRUE) . ' ' . $this->searchWord . ' ' . devel_create_greeking(2, TRUE);
}
else {
$node->title = devel_create_greeking(5, TRUE);
}
// Add any more base fields that might be appropriate.
devel_generate_fields($node, 'node', $node->type);
// Add the custom word to the body field on some records and specifically
// remove it from the others.
if (mt_rand(0, 5) == 5) {
$node->body[LANGUAGE_NONE][0]['value'] = devel_create_para(3, 1) . '<p>' . $this->searchWord . '</p>' . devel_create_para(3, 1);
}
else {
$node->body[LANGUAGE_NONE][0]['value'] = str_replace($this->searchWord, '', $node->body[LANGUAGE_NONE][0]['value']);
}
// Save the node.
node_save($node);
}
}