Commit de63cbb8 authored by Dries's avatar Dries

Issue #61285 by typhonius, catch: remove poll module from core.

parent 4a75f92b
......@@ -260,9 +260,6 @@ PHP module
Picture module
- Peter Droogmans 'attiks' http://drupal.org/user/105002
Poll module
- Andrei Mateescu 'amateescu' http://drupal.org/user/729614
RDF module
- Stéphane Corlosquet 'scor' http://drupal.org/user/52142
- Lin Clark 'linclark' http://drupal.org/user/396253
......
......@@ -75,10 +75,9 @@ function testCommentEnable() {
$this->rebuildContainer();
$this->assertFalse(module_exists('comment'), 'Comment module disabled.');
// Enable core content type modules (book, and poll).
// Enable core content type module (book).
$edit = array();
$edit['modules[Core][book][enable]'] = 'book';
$edit['modules[Core][poll][enable]'] = 'poll';
$this->drupalPost('admin/modules', $edit, t('Save configuration'));
// Now enable the comment module.
......@@ -90,7 +89,6 @@ function testCommentEnable() {
// Create nodes of each type.
$book_node = $this->drupalCreateNode(array('type' => 'book'));
$poll_node = $this->drupalCreateNode(array('type' => 'poll', 'active' => 1, 'runtime' => 0, 'choice' => array(array('chtext' => ''))));
$this->drupalLogout();
......@@ -100,7 +98,6 @@ function testCommentEnable() {
$this->web_user = $this->drupalCreateUser(array('access content', 'access comments', 'post comments', 'skip comment approval'));
$this->drupalLogin($this->web_user);
$this->postComment($book_node, $this->randomName(), $this->randomName());
$this->postComment($poll_node, $this->randomName(), $this->randomName());
}
/**
......
......@@ -20,7 +20,7 @@ class DBLogTest extends WebTestBase {
*
* @var array
*/
public static $modules = array('dblog', 'node', 'poll', 'help');
public static $modules = array('dblog', 'node', 'forum', 'help');
/**
* A user with some relevent administrative permissions.
......@@ -202,7 +202,7 @@ private function verifyEvents() {
$this->drupalCreateContentType(array('type' => 'page', 'name' => t('Basic page')));
$this->doNode('article');
$this->doNode('page');
$this->doNode('poll');
$this->doNode('forum');
// When a user account is canceled, any content they created remains but the
// uid = 0. Records in the watchdog table related to that user have the uid
......@@ -297,7 +297,7 @@ private function doUser() {
* Generates and then verifies some node events.
*
* @param string $type
* A node type (e.g., 'article', 'page' or 'poll').
* A node type (e.g., 'article', 'page' or 'forum').
*/
private function doNode($type) {
// Create user.
......@@ -369,11 +369,11 @@ private function doNode($type) {
private function getContent($type) {
$langcode = LANGUAGE_NOT_SPECIFIED;
switch ($type) {
case 'poll':
case 'forum':
$content = array(
"title" => $this->randomName(8),
'choice[new:0][chtext]' => $this->randomName(32),
'choice[new:1][chtext]' => $this->randomName(32),
"taxonomy_forums[$langcode]" => array(1),
"body[$langcode][0][value]" => $this->randomName(32),
);
break;
......@@ -397,21 +397,10 @@ private function getContent($type) {
* Random content needed by various node types.
*/
private function getContentUpdate($type) {
switch ($type) {
case 'poll':
$content = array(
'choice[chid:1][chtext]' => $this->randomName(32),
'choice[chid:2][chtext]' => $this->randomName(32),
);
break;
default:
$langcode = LANGUAGE_NOT_SPECIFIED;
$content = array(
"body[$langcode][0][value]" => $this->randomName(32),
);
break;
}
$langcode = LANGUAGE_NOT_SPECIFIED;
$content = array(
"body[$langcode][0][value]" => $this->randomName(32),
);
return $content;
}
......
......@@ -12,9 +12,8 @@
* Exposes "pseudo-field" components on fieldable entities.
*
* Field UI's "Manage fields" and "Manage display" pages let users re-order
* fields, but also non-field components. For nodes, these include the title,
* poll choices, and other elements exposed by modules through hook_form() or
* hook_form_alter().
* fields, but also non-field components. For nodes, these include the title
* and other elements exposed by modules through hook_form() or hook_form_alter().
*
* Fieldable entities or modules that want to have their components supported
* should expose them using this hook. The user-defined settings (weight,
......@@ -38,32 +37,40 @@
* context.
*/
function hook_field_extra_fields() {
$extra['node']['poll'] = array(
'form' => array(
'choice_wrapper' => array(
'label' => t('Poll choices'),
'description' => t('Poll choices'),
'weight' => -4,
),
'settings' => array(
'label' => t('Poll settings'),
'description' => t('Poll module settings'),
'weight' => -3,
),
),
'display' => array(
'poll_view_voting' => array(
'label' => t('Poll vote'),
'description' => t('Poll vote'),
'weight' => 0,
),
'poll_view_results' => array(
'label' => t('Poll results'),
'description' => t('Poll results'),
'weight' => 0,
),
)
);
$extra = array();
$module_language_enabled = module_exists('language');
$description = t('Node module element');
foreach (node_type_get_types() as $bundle) {
if ($bundle->has_title) {
$extra['node'][$bundle->type]['form']['title'] = array(
'label' => $bundle->title_label,
'description' => $description,
'weight' => -5,
);
}
// Add also the 'language' select if Language module is enabled and the
// bundle has multilingual support.
// Visibility of the ordering of the language selector is the same as on the
// node/add form.
if ($module_language_enabled) {
$configuration = language_get_default_configuration('node', $bundle->type);
if ($configuration['language_show']) {
$extra['node'][$bundle->type]['form']['language'] = array(
'label' => t('Language'),
'description' => $description,
'weight' => 0,
);
}
}
$extra['node'][$bundle->type]['display']['language'] = array(
'label' => t('Language'),
'description' => $description,
'weight' => 0,
'visible' => FALSE,
);
}
return $extra;
}
......
......@@ -19,7 +19,7 @@ class HelpTest extends WebTestBase {
*
* @var array.
*/
public static $modules = array('poll');
public static $modules = array('shortcut');
// Tests help implementations of many arbitrary core modules.
protected $profile = 'standard';
......
......@@ -12,14 +12,13 @@
/**
* Tests basic options of multi-step node forms.
*/
class MultiStepNodeFormBasicOptionsTest extends WebTestBase {
class MultiStepNodeFormBasicOptionsTest extends NodeTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('poll');
public static function getInfo() {
return array(
......@@ -29,26 +28,52 @@ public static function getInfo() {
);
}
function setUp() {
parent::setUp();
$web_user = $this->drupalCreateUser(array('administer nodes', 'create poll content'));
$this->drupalLogin($web_user);
}
/**
* Tests changing the default values of basic options to ensure they persist.
*/
function testMultiStepNodeFormBasicOptions() {
// Prepare a user to create the node.
$web_user = $this->drupalCreateUser(array('administer nodes', 'create page content'));
$this->drupalLogin($web_user);
// Create an unlimited cardinality field.
$this->field_name = drupal_strtolower($this->randomName());
$this->field = array(
'field_name' => drupal_strtolower($this->field_name),
'type' => 'text',
'cardinality' => -1,
);
field_create_field($this->field);
// Attach an instance of the field to the page content type.
$this->instance = array(
'field_name' => $this->field_name,
'entity_type' => 'node',
'bundle' => 'page',
'label' => $this->randomName() . '_label',
'settings' => array(
'text_processing' => TRUE,
),
'widget' => array(
'type' => 'text_textfield',
),
'display' => array(
'full' => array(
'type' => 'text_default',
),
),
);
field_create_instance($this->instance);
$langcode = LANGUAGE_NOT_SPECIFIED;
$edit = array(
'title' => 'a',
'status' => FALSE,
'promote' => FALSE,
'sticky' => 1,
'choice[new:0][chtext]' => 'a',
'choice[new:1][chtext]' => 'a',
"$this->field_name[$langcode][0][value]" => $this->randomString(32),
);
$this->drupalPost('node/add/poll', $edit, t('Add another choice'));
$this->drupalPost('node/add/page', $edit, t('Add another item'));
$this->assertNoFieldChecked('edit-status', 'status stayed unchecked');
$this->assertNoFieldChecked('edit-promote', 'promote stayed unchecked');
$this->assertFieldChecked('edit-sticky', 'sticky stayed checked');
......
......@@ -11,6 +11,8 @@
* Test node type customizations persistence.
*/
class NodeTypePersistenceTest extends NodeTestBase {
// Enable the prerequisite modules for forum
public static $modules = array('history', 'taxonomy', 'options', 'comment');
public static function getInfo() {
return array(
'name' => 'Node type persist',
......@@ -25,59 +27,59 @@ public static function getInfo() {
function testNodeTypeCustomizationPersistence() {
$web_user = $this->drupalCreateUser(array('bypass node access', 'administer content types', 'administer modules'));
$this->drupalLogin($web_user);
$poll_key = 'modules[Core][poll][enable]';
$poll_enable = array($poll_key => "1");
$poll_disable = array($poll_key => FALSE);
$forum_key = 'modules[Core][forum][enable]';
$forum_enable = array($forum_key => "1");
$forum_disable = array($forum_key => FALSE);
// Enable poll and verify that the node type is in the DB and is not
// Enable forum and verify that the node type is in the DB and is not
// disabled.
$this->drupalPost('admin/modules', $poll_enable, t('Save configuration'));
$disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField();
$this->assertNotIdentical($disabled, FALSE, 'Poll node type found in the database');
$this->assertEqual($disabled, 0, 'Poll node type is not disabled');
$this->drupalPost('admin/modules', $forum_enable, t('Save configuration'));
$disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'forum'))->fetchField();
$this->assertNotIdentical($disabled, FALSE, 'Forum node type found in the database');
$this->assertEqual($disabled, 0, 'Forum node type is not disabled');
// Check that poll node type (uncustomized) shows up.
// Check that forum node type (uncustomized) shows up.
$this->drupalGet('node/add');
$this->assertText('poll', 'poll type is found on node/add');
$this->assertText('forum', 'forum type is found on node/add');
// Customize poll description.
// Customize forum description.
$description = $this->randomName();
$edit = array('description' => $description);
$this->drupalPost('admin/structure/types/manage/poll', $edit, t('Save content type'));
$this->drupalPost('admin/structure/types/manage/forum', $edit, t('Save content type'));
// Check that poll node type customization shows up.
// Check that forum node type customization shows up.
$this->drupalGet('node/add');
$this->assertText($description, 'Customized description found');
// Disable poll and check that the node type gets disabled.
$this->drupalPost('admin/modules', $poll_disable, t('Save configuration'));
$disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField();
$this->assertEqual($disabled, 1, 'Poll node type is disabled');
// Disable forum and check that the node type gets disabled.
$this->drupalPost('admin/modules', $forum_disable, t('Save configuration'));
$disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'forum'))->fetchField();
$this->assertEqual($disabled, 1, 'Forum node type is disabled');
$this->drupalGet('node/add');
$this->assertNoText('poll', 'poll type is not found on node/add');
$this->assertNoText('forum', 'forum type is not found on node/add');
// Reenable poll and check that the customization survived the module
// Reenable forum and check that the customization survived the module
// disable.
$this->drupalPost('admin/modules', $poll_enable, t('Save configuration'));
$disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField();
$this->assertNotIdentical($disabled, FALSE, 'Poll node type found in the database');
$this->assertEqual($disabled, 0, 'Poll node type is not disabled');
$this->drupalPost('admin/modules', $forum_enable, t('Save configuration'));
$disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'forum'))->fetchField();
$this->assertNotIdentical($disabled, FALSE, 'Forum node type found in the database');
$this->assertEqual($disabled, 0, 'Forum node type is not disabled');
$this->drupalGet('node/add');
$this->assertText($description, 'Customized description found');
// Disable and uninstall poll.
$this->drupalPost('admin/modules', $poll_disable, t('Save configuration'));
$edit = array('uninstall[poll]' => 'poll');
// Disable and uninstall forum.
$this->drupalPost('admin/modules', $forum_disable, t('Save configuration'));
$edit = array('uninstall[forum]' => 'forum');
$this->drupalPost('admin/modules/uninstall', $edit, t('Uninstall'));
$this->drupalPost(NULL, array(), t('Uninstall'));
$disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'poll'))->fetchField();
$this->assertTrue($disabled, 'Poll node type is in the database and is disabled');
$disabled = db_query('SELECT disabled FROM {node_type} WHERE type = :type', array(':type' => 'forum'))->fetchField();
$this->assertTrue($disabled, 'Forum node type is in the database and is disabled');
$this->drupalGet('node/add');
$this->assertNoText('poll', 'poll type is no longer found on node/add');
$this->assertNoText('forum', 'forum type is no longer found on node/add');
// Reenable poll and check that the customization survived the module
// Reenable forum and check that the customization survived the module
// uninstall.
$this->drupalPost('admin/modules', $poll_enable, t('Save configuration'));
$this->drupalPost('admin/modules', $forum_enable, t('Save configuration'));
$this->drupalGet('node/add');
$this->assertText($description, 'Customized description is found even after uninstall and reenable.');
}
......
......@@ -134,35 +134,28 @@ function testNodeTypeEditing() {
*/
function testNodeTypeStatus() {
// Enable all core node modules, and all types should be active.
module_enable(array('book', 'poll'), FALSE);
module_enable(array('book'), FALSE);
node_types_rebuild();
$types = node_type_get_types();
foreach (array('book', 'poll', 'article', 'page') as $type) {
foreach (array('book', 'article', 'page') as $type) {
$this->assertTrue(isset($types[$type]), format_string('%type is found in node types.', array('%type' => $type)));
$this->assertTrue(isset($types[$type]->disabled) && empty($types[$type]->disabled), format_string('%type type is enabled.', array('%type' => $type)));
}
// Disable poll module and the respective type should be marked as disabled.
module_disable(array('poll'), FALSE);
node_types_rebuild();
$types = node_type_get_types();
$this->assertTrue(!empty($types['poll']->disabled), "Poll module's node type disabled.");
// Disable book module and the respective type should still be active, since
// it is not provided by hook_node_info().
module_disable(array('book'), FALSE);
node_types_rebuild();
$types = node_type_get_types();
$this->assertTrue(isset($types['book']) && empty($types['book']->disabled), "Book module's node type still active.");
$this->assertTrue(!empty($types['poll']->disabled), "Poll module's node type still disabled.");
$this->assertTrue(isset($types['article']) && empty($types['article']->disabled), 'Article node type still active.');
$this->assertTrue(isset($types['page']) && empty($types['page']->disabled), 'Basic page node type still active.');
// Re-enable the modules and verify that the types are active again.
module_enable(array('book', 'poll'), FALSE);
module_enable(array('book'), FALSE);
node_types_rebuild();
$types = node_type_get_types();
foreach (array('book', 'poll', 'article', 'page') as $type) {
foreach (array('book', 'article', 'page') as $type) {
$this->assertTrue(isset($types[$type]), format_string('%type is found in node types.', array('%type' => $type)));
$this->assertTrue(isset($types[$type]->disabled) && empty($types[$type]->disabled), format_string('%type type is enabled.', array('%type' => $type)));
}
......
......@@ -21,12 +21,12 @@
* base node operation:
* - Node-type-specific hooks: These hooks are only invoked on the primary
* module, using the "base" return component of hook_node_info() as the
* function prefix. For example, poll.module defines the base for the Poll
* content type as "poll", so during creation of a poll node, hook_insert() is
* only invoked by calling poll_insert().
* function prefix. For example, forum.module defines the base for the Forum
* content type as "forum", so during creation of a forum node, hook_insert() is
* only invoked by calling forum_insert().
* - All-module hooks: This set of hooks is invoked on all implementing modules,
* to allow other modules to modify what the primary node module is doing. For
* example, hook_node_insert() is invoked on all modules when creating a poll
* example, hook_node_insert() is invoked on all modules when creating a forum
* node.
* - Field hooks: Hooks related to the fields attached to the node. These are
* invoked from the field operations functions described below, and can be
......
<?php
/**
* @file
* Contains \Drupal\poll\Plugin\block\block\PollRecentBlock.
*/
namespace Drupal\poll\Plugin\block\block;
use Drupal\block\BlockBase;
use Drupal\Core\Annotation\Plugin;
use Drupal\Core\Annotation\Translation;
/**
* Provides a 'Most recent poll' block.
*
* @Plugin(
* id = "poll_recent_block",
* subject = @Translation("Most recent poll"),
* module = "poll"
* )
*/
class PollRecentBlock extends BlockBase {
/**
* Stores the node ID of the latest poll.
*
* @var int
*/
protected $record;
/**
* Overrides \Drupal\block\BlockBase::settings().
*/
public function settings() {
return array(
'properties' => array(
'administrative' => TRUE,
),
);
}
/**
* Overrides \Drupal\block\BlockBase::access().
*/
public function blockAccess() {
if (user_access('access content')) {
// Retrieve the latest poll.
$select = db_select('node', 'n');
$select->join('poll', 'p', 'p.nid = n.nid');
$select->fields('n', array('nid'))
->condition('n.status', 1)
->condition('p.active', 1)
->orderBy('n.created', 'DESC')
->range(0, 1)
->addTag('node_access');
$record = $select->execute()->fetchObject();
if ($record) {
$this->record = $record->nid;
return TRUE;
}
}
return FALSE;
}
/**
* Implements \Drupal\block\BlockBase::build().
*/
public function build() {
$poll = node_load($this->record);
if ($poll->nid) {
$poll = poll_block_latest_poll_view($poll);
return array(
$poll->content
);
}
return array();
}
}
<?php
/**
* @file
* Definition of Drupal\poll\Tests\PollBlockTest.
*/
namespace Drupal\poll\Tests;
/**
* Tests the recent poll block.
*/
class PollBlockTest extends PollTestBase {
/**
* An administrative user for testing.
*
* @var Drupal\user\Plugin\Core\Entity\User
*/
protected $adminUser;
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('block');
public static function getInfo() {
return array(
'name' => 'Block availability',
'description' => 'Check if the most recent poll block is available.',
'group' => 'Poll',
);
}
function setUp() {
parent::setUp();
// Create and login user
$this->adminUser = $this->drupalCreateUser(array('administer blocks'));
$this->drupalLogin($this->adminUser);
}
/**
* Tests creating, viewing, voting on recent poll block.
*/
function testRecentBlock() {
// Enable the recent poll block.
$this->drupalPlaceBlock('poll_recent_block');
// Create a poll which should appear in recent polls block.
$title = $this->randomName();
$choices = $this->_generateChoices(7);
$poll_nid = $this->pollCreate($title, $choices, TRUE);
// Verify poll appears in a block.
// View user page so we're not matching the poll node on front page.
$this->drupalGet('user');
// If a 'block' view not generated, this title would not appear even though
// the choices might.
$this->assertText($title, 'Poll appears in block.');
// Logout and login back in as a user who can vote.
$this->drupalLogout();
$vote_user = $this->drupalCreateUser(array('cancel own vote', 'inspect all votes', 'vote on polls', 'access content'));
$this->drupalLogin($vote_user);
// Verify we can vote via the block.
$edit = array(
'choice' => '1',
);
$this->drupalPost('user/' . $vote_user->uid, $edit, t('Vote'));
$this->assertText('Your vote was recorded.', 'Your vote was recorded.');
$this->assertText('Total votes: 1', 'Vote count updated correctly.');
$this->assertText('Older polls', 'Link to older polls appears.');
$this->clickLink('Older polls');
$this->assertText('1 vote - open', 'Link to poll listing correct.');
// Close the poll and verify block doesn't appear.
$content_user = $this->drupalCreateUser(array('create poll content', 'edit any poll content', 'access content'));
$this->drupalLogout();
$this->drupalLogin($content_user);
$close_edit = array('active' => 0);
$this->pollUpdate($poll_nid, $title, $close_edit);
$this->drupalGet('user/' . $content_user->uid);
$this->assertNoText($title, 'Poll no longer appears in block.');
}