Skip to content

Commit

Permalink
Issue backdrop#905: Updating tests to handle Redirect in standard pro…
Browse files Browse the repository at this point in the history
…file.
  • Loading branch information
quicksketch committed Apr 25, 2016
1 parent 7ac090e commit ea6f26a
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 62 deletions.
6 changes: 6 additions & 0 deletions core/modules/node/tests/node.test
Original file line number Diff line number Diff line change
Expand Up @@ -2516,6 +2516,7 @@ class NodeEntityViewModeAlterTest extends NodeWebTestCase {
* Tests the cache invalidation of node operations.
*/
class NodePageCacheTest extends NodeWebTestCase {
protected $profile = 'minimal';

/**
* An admin user with administrative permissions for nodes.
Expand All @@ -2528,6 +2529,11 @@ class NodePageCacheTest extends NodeWebTestCase {
config_set('system.core', 'cache', 1);
config_set('system.core', 'page_cache_maximum_age', 300);

$this->backdropCreateContentType(array(
'type' => 'page',
'name' => 'Page',
));

$this->admin_user = $this->backdropCreateUser(array(
'bypass node access',
'access content overview',
Expand Down
5 changes: 5 additions & 0 deletions core/modules/path/path.module
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,11 @@ function path_form_element(Entity $entity) {
'#type' => 'value',
'#value' => $path['source'],
);
$fieldset['original'] = array(
'#type' => 'value',
'#value' => path_load($path['pid'])
);

$fieldset['langcode'] = array(
'#type' => 'value',
'#value' => $path['langcode'],
Expand Down
50 changes: 38 additions & 12 deletions core/modules/path/tests/path.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,19 @@
* Provides a base class for testing the Path module.
*/
class PathTestCase extends BackdropWebTestCase {
function setUp() {
parent::setUp('path');
protected $profile = 'minimal';

function setUp($modules = array()) {
$modules[] = 'path';
parent::setUp($modules);

$this->backdropCreateContentType(array(
'type' => 'page',
'name' => 'Page',
));

// Create test user and login.
$web_user = $this->backdropCreateUser(array('create page content', 'edit own page content', 'create post content', 'edit own post content', 'administer url aliases', 'create url aliases'));
$web_user = $this->backdropCreateUser(array('access content', 'create page content', 'edit own page content', 'administer url aliases', 'create url aliases'));
$this->backdropLogin($web_user);
}

Expand Down Expand Up @@ -107,9 +115,7 @@ class PathTestCase extends BackdropWebTestCase {
*/
function testNodeAlias() {
// Create test node.
$node1 = $this->backdropCreateNode(array(
'type' => 'post',
));
$node1 = $this->backdropCreateNode();

// Create alias.
$edit = array();
Expand Down Expand Up @@ -178,7 +184,6 @@ class PathTestCase extends BackdropWebTestCase {
$node_one = $this->backdropCreateNode();
$edit = array();
$edit['path[alias]'] = $this->randomName();
$edit['path[auto]'] = FALSE;
$this->backdropPost('node/' . $node_one->nid . '/edit', $edit, t('Save'));

// Now create another node and try to set the same alias.
Expand All @@ -196,6 +201,11 @@ class PathTaxonomyTermTestCase extends BackdropWebTestCase {
function setUp() {
parent::setUp('path', 'taxonomy');

// Redirect module is not tested with aliases in these tests. Redirect does
// its own testing in RedirectFunctionalTest.
module_disable(array('redirect'));
menu_rebuild();

// Create and login user.
$web_user = $this->backdropCreateUser(array('administer url aliases', 'administer taxonomy', 'access administration pages'));
$this->backdropLogin($web_user);
Expand Down Expand Up @@ -251,11 +261,29 @@ class PathTaxonomyTermTestCase extends BackdropWebTestCase {
* Tests URL aliases for translated nodes.
*/
class PathLanguageTestCase extends BackdropWebTestCase {
function setUp() {
parent::setUp('path', 'locale', 'translation');
protected $profile = 'testing';

/**
* The user account of the logged in user for these tests.
*
* @var User
*/
protected $web_user;

function setUp($modules = array()) {
$modules[] = 'node';
$modules[] = 'path';
$modules[] = 'locale';
$modules[] = 'translation';
parent::setUp($modules);

$this->backdropCreateContentType(array(
'type' => 'page',
'name' => 'Page',
));

// Create and login user.
$this->web_user = $this->backdropCreateUser(array('edit any page content', 'create page content', 'administer url aliases', 'create url aliases', 'administer languages', 'translate content', 'access administration pages'));
$this->web_user = $this->backdropCreateUser(array('access content', 'edit any page content', 'create page content', 'administer url aliases', 'create url aliases', 'administer languages', 'translate content', 'access administration pages'));
$this->backdropLogin($this->web_user);

// Enable French language.
Expand Down Expand Up @@ -284,7 +312,6 @@ class PathLanguageTestCase extends BackdropWebTestCase {
// Edit the node to set language and path.
$edit = array();
$edit['langcode'] = 'en';
$edit['path[auto]'] = FALSE;
$edit['path[alias]'] = $english_alias;
$this->backdropPost('node/' . $english_node->nid . '/edit', $edit, t('Save'));

Expand All @@ -300,7 +327,6 @@ class PathLanguageTestCase extends BackdropWebTestCase {
$edit["title"] = $this->randomName();
$edit["body[$langcode][0][value]"] = $this->randomName();
$french_alias = $this->randomName();
$edit['path[auto]'] = FALSE;
$edit['path[alias]'] = $french_alias;
$this->backdropPost(NULL, $edit, t('Save'));

Expand Down
34 changes: 17 additions & 17 deletions core/modules/path/tests/path_pattern.test
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,16 @@ class PathPatternFunctionalTestHelper extends PathPatternTestHelper {

function setUp(array $modules = array()) {
parent::setUp($modules);
$this->config = config('path.settings');
$config = config('path.settings');

// Set Path settings we assume to be as-is in this test.
$this->config->set('node_page_pattern', 'content/[node:title]');
$this->config->save();
$config->set('node_page_pattern', 'content/[node:title]');
$config->save();

// Redirect module is not tested with aliases in these tests. Redirect does
// its own testing in RedirectFunctionalTest.
module_disable(array('redirect'));
menu_rebuild();

// Allow other modules to add additional permissions for the admin user.
$permissions = array(
Expand All @@ -419,19 +424,14 @@ class PathPatternFunctionalTestHelper extends PathPatternTestHelper {
* Test basic Path automatic alias functionality.
*/
class PathPatternFunctionalTestCase extends PathPatternFunctionalTestHelper {

protected $config;

/**
* Basic functional testing of Path patterns.
*/
function testNodeEditing() {
module_load_include('inc', 'path');

$this->config = config('path.settings');
$config = config('path.settings');
// Delete the default node pattern. Only the page content type will have a pattern.
$this->config->set('node_pattern', '');
$this->config->save();
$config->set('node_pattern', '');
$config->save();

// Ensure the Path auto checkbox is checked by default on the node add form.
$this->backdropGet('node/add/page');
Expand All @@ -453,14 +453,14 @@ class PathPatternFunctionalTestCase extends PathPatternFunctionalTestHelper {
$this->assertText($title, 'Node accessible through automatic alias.');

// Disable the update action. The checkbox should not be visible.
$this->config->set('update_action', PATH_UPDATE_ACTION_NO_NEW);
$this->config->save();
$config->set('update_action', PATH_UPDATE_ACTION_NO_NEW);
$config->save();
$this->backdropGet("node/{$node->nid}/edit");
$this->assertNoFieldById('edit-path-auto');

// Reset the update action back to default. The checkbox should be visible.
$this->config->set('update_action', PATH_UPDATE_ACTION_LEAVE);
$this->config->save();
$config->set('update_action', PATH_UPDATE_ACTION_LEAVE);
$config->save();
$this->backdropGet("node/{$node->nid}/edit");
$this->assertFieldChecked('edit-path-auto');

Expand Down Expand Up @@ -508,8 +508,8 @@ class PathPatternFunctionalTestCase extends PathPatternFunctionalTestHelper {

// Set the page pattern to use only tokens so we can test the checkbox
// behavior if none of the tokens have a value currently.
$this->config->set('node_page_pattern', '[node:title]');
$this->config->save();
$config->set('node_page_pattern', '[node:title]');
$config->save();

// Create a node with an empty title. The auto checkbox should still be
// visible but unchecked.
Expand Down
33 changes: 0 additions & 33 deletions core/modules/redirect/redirect.module
Original file line number Diff line number Diff line change
Expand Up @@ -352,39 +352,6 @@ function redirect_views_api() {
);
}

/**
* Implements hook_form_FORM_ID_alter().
*
* Adds support for creating redirects if a node URL alias is changed.
*/
function redirect_form_node_form_alter(&$form, $form_state) {
if (!empty($form['path']['pid']['#value']) && !isset($form['path']['original'])) {
$form['path']['original'] = array('#type' => 'value', '#value' => path_load($form['path']['pid']['#value']));
}
}

/**
* Implements hook_form_FORM_ID_alter().
*
* Adds support for creating redirects if a taxonomy term URL alias is changed.
*/
function redirect_form_taxonomy_form_term_alter(&$form, $form_state) {
if (!empty($form['path']['pid']['#value']) && !isset($form['path']['original'])) {
$form['path']['original'] = array('#type' => 'value', '#value' => path_load($form['path']['pid']['#value']));
}
}

/**
* Implements hook_form_FORM_ID_alter().
*
* Adds support for creating redirects if an URL alias is changed.
*/
function redirect_form_path_admin_form_alter(&$form, $form_state) {
if (!empty($form['pid']['#value']) && !isset($form['original'])) {
$form['original'] = array('#type' => 'value', '#value' => path_load($form['pid']['#value']));
}
}

/**
* Load an URL redirect from the database.
*
Expand Down

0 comments on commit ea6f26a

Please sign in to comment.