custom_formatters.general.test in Custom Formatters 7.2
Tests for the Custom Fomratters module.
File
tests/custom_formatters.general.testView source
<?php
/**
* @file
* Tests for the Custom Fomratters module.
*/
/**
* Class FileFieldPathsGeneralTestCase.
*/
class CustomFormattersGeneralTestCase extends CustomFormattersTestCase {
/**
* {@inheritdoc}
*/
public static function getInfo() {
return array(
'name' => 'General functionality',
'description' => 'Test general functionality.',
'group' => 'Custom Formatters',
);
}
/**
* Test General UI related functionality.
*/
public function testCustomFormattersUi() {
$this
->drupalGet('admin/structure/formatters');
// Ensure the Formatters overview page is present.
$expected_title = t('!title | !sitename', array(
'!title' => 'Formatters',
'!sitename' => variable_get('site_name', 'Drupal'),
));
$this
->assertTitle($expected_title);
// Ensure the Settings link is present and correct.
$this
->assertLink(t('Settings'));
$this
->assertLinkByHref('admin/structure/formatters/settings');
// Ensure our pre-prepared test formatter is present.
$this
->assertText('Test Formatter');
$this
->assertLinkByHref('admin/structure/formatters/list/test_formatter/edit');
$this
->assertCustomFormatterExists('test_formatter');
// Ensure our pre-prepared test formatter is present on the Manage display
// page.
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertRaw('custom_formatters_test_formatter');
$this
->assertRaw('Custom: Test Formatter');
// Change the Label prefix.
$edit = array(
'settings[label_prefix_value]' => $this
->randomName(),
);
$this
->drupalPost('admin/structure/formatters/settings', $edit, t('Save'));
$this
->assertText(t('Custom Formatters settings have been updated.'));
// Ensure our pre-prepared test formatter is present on the Manage display
// page with the altered label prefix.
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertRaw(t('@prefix: Test Formatter', array(
'@prefix' => $edit['settings[label_prefix_value]'],
)));
// Remove the Label prefix.
$edit = array(
'settings[label_prefix]' => FALSE,
);
$this
->drupalPost('admin/structure/formatters/settings', $edit, t('Save'));
$this
->assertText(t('Custom Formatters settings have been updated.'));
// Ensure our pre-prepared test formatter is present on the Manage display
// page without a label prefix.
$this
->drupalGet('admin/structure/types/manage/article/display');
$this
->assertRaw('Test Formatter');
}
/**
* Test the Formatter preset Engine.
*/
public function testCustomFormattersEngineFormatterPreset() {
// Create a Custom formatter.
$this->formatter = $this
->createCustomFormatter(array(
'mode' => 'formatter_preset',
'code' => serialize(array(
'formatter' => 'text_trimmed',
'settings' => array(
'trim_length' => 10,
),
)),
));
// Set the formatter active on the Body field.
$this
->setCustomFormatter($this->formatter->name, 'body', 'article');
// Ensure Formatter rendered correctly.
$this
->drupalGet("node/{$this->node->nid}");
// We substring to a length of 7 characters instead of 10 characters as the
// formatter will include the starting HTML paragraph tag in the character
// count.
$this
->assert(!strstr($this->content, $this->node->body[LANGUAGE_NONE][0]['value']) && strstr($this->content, substr($this->node->body[LANGUAGE_NONE][0]['value'], 0, 7)), t('Custom formatter output found.'));
}
/**
* Test the PHP Engine.
*/
public function testCustomFormattersEnginePhp() {
// Create a Custom formatter.
$text = $this
->randomName();
$this->formatter = $this
->createCustomFormatter(array(
'mode' => 'php',
'code' => "return '{$text}';",
));
// Set the formatter active on the Body field.
$this
->setCustomFormatter($this->formatter->name, 'body', 'article');
// Ensure Formatter rendered correctly.
$this
->drupalGet("node/{$this->node->nid}");
$this
->assertText($text, t('Custom formatter output found.'));
}
/**
* Test the HTML + Token engine.
*/
public function testCustomFormattersEngineHtmlToken() {
// Create a Custom formatter.
$text = $this
->randomName();
$this->formatter = $this
->createCustomFormatter(array(
'mode' => 'token',
'code' => $text,
));
// Set the formatter active on the Body field.
$this
->setCustomFormatter($this->formatter->name, 'body', 'article');
// Ensure Formatter rendered correctly.
$this
->drupalGet("node/{$this->node->nid}");
$this
->assertText($text, t('Custom formatter output found.'));
}
}
Classes
Name | Description |
---|---|
CustomFormattersGeneralTestCase | Class FileFieldPathsGeneralTestCase. |