updated ubercart, faq

This commit is contained in:
Bachir Soussi Chiadmi
2016-11-05 16:50:18 +01:00
parent 3413d81bb8
commit 0bb339fc99
110 changed files with 1382 additions and 641 deletions

View File

@@ -21,9 +21,10 @@ class UbercartRolesTestCase extends UbercartTestHelper {
/**
* Overrides DrupalWebTestCase::setUp().
*/
function setUp() {
protected function setUp($modules = array(), $permissions = array()) {
$modules = array('uc_payment', 'uc_payment_pack', 'uc_roles');
$permissions = array();
// Needed to see/modify roles on the /user/%/edit page
$permissions = array('administer permissions', 'administer users', 'view all role expirations');
parent::setUp($modules, $permissions);
}
@@ -59,4 +60,48 @@ class UbercartRolesTestCase extends UbercartTestHelper {
$this->drupalLogout();
$this->cronRun();
}
function testRoleAdminDelete() {
// Add role assignment to the test product.
$rid = $this->drupalCreateRole(array('access content'));
$this->drupalLogin($this->adminUser);
$this->drupalPost('node/' . $this->product->nid . '/edit/features', array('feature' => 'role'), t('Add'));
$edit = array(
'uc_roles_role' => $rid,
'end_override' => TRUE,
'uc_roles_expire_relative_duration' => 1,
'uc_roles_expire_relative_granularity' => 'day',
);
$this->drupalPost(NULL, $edit, t('Save feature'));
// Check out with the test product.
$this->drupalPost('node/' . $this->product->nid, array(), t('Add to cart'));
$order = $this->checkout();
uc_payment_enter($order->order_id, 'other', $order->order_total);
// Test that the role was granted.
$account = user_load($order->uid);
$this->assertTrue(isset($account->roles[$rid]), 'Existing user was granted role.');
// Test that the role appears on the user edit page.
$this->drupalGet('user/' . $order->uid . '/edit');
$this->assertText('Ubercart roles', 'Ubercart roles fieldset found.');
$this->assertNoText('There are no pending expirations for roles this user.', 'User has a role expiration.');
// Delete the role using the Drupal user edit page
// by unchecking the role and submitting the form.
$this->drupalPost(
'user/' . $order->uid . '/edit',
array('roles[' . $rid . ']' => FALSE),
t('Save')
);
// Test that the role was removed.
$account = user_load($order->uid, TRUE);
$this->assertFalse(isset($account->roles[$rid]), 'Role was removed from user.');
// Test that the role expiration data was removed.
$this->assertText('There are no pending expirations for roles this user.', 'User has no role expirations.');
}
}

View File

@@ -2,7 +2,6 @@ name = Roles
description = Assigns permanent or expirable roles based on product purchases.
dependencies[] = uc_product
dependencies[] = uc_order
dependencies[] = views
package = Ubercart - core (optional)
core = 7.x
@@ -10,11 +9,11 @@ core = 7.x
files[] = tests/uc_roles.test
; Views handlers
files[] = uc_roles.views.inc
files[] = views/uc_roles_handler_field_rid.inc
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
; Information added by Drupal.org packaging script on 2016-07-16
version = "7.x-3.10"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"
datestamp = "1468644909"

View File

@@ -1,16 +0,0 @@
name = Roles
description = Assigns permanent or expirable roles based on product purchases.
dependencies[] = uc_product
dependencies[] = uc_order
package = Ubercart - core (optional)
core = 7.x
; Test cases
files[] = tests/uc_roles.test
; Information added by Drupal.org packaging script on 2014-10-22
version = "7.x-3.8"
core = "7.x"
project = "ubercart"
datestamp = "1413965350"

View File

@@ -335,8 +335,9 @@ function uc_roles_user_presave(&$edit, $account, $category) {
// If a user's role is removed using Drupal, then so is any expiration data.
if (isset($edit['roles']) && is_array($edit['roles']) && isset($account->roles)) {
$allowed_uc_roles = _uc_roles_get_choices();
foreach ($account->roles as $rid => $role) {
if (!in_array($rid, array_keys($edit['roles'])) && $rid != DRUPAL_AUTHENTICATED_RID) {
if (isset($allowed_uc_roles[$rid]) && !$edit['roles'][$rid]) {
uc_roles_delete($account, $rid);
}
}
@@ -953,7 +954,7 @@ function _uc_roles_get_choices($exclude = array()) {
}
/**
* Deletes all data associated with a given product feature.
* Deletes all role data associated with a given product feature.
*
* @param $pfid
* An Ubercart product feature ID.
@@ -1278,9 +1279,13 @@ function _uc_roles_get_expiration($duration, $granularity, $start_time = NULL) {
return strtotime($operator . $duration . ' ' . $granularity, $start_time);
}
/**
* Implements hook_views_api().
*/
function uc_roles_views_api() {
return array('api' => '3.0');
return array(
'api' => '2.0',
'path' => drupal_get_path('module', 'uc_roles') . '/views',
);
}

View File

@@ -1,110 +0,0 @@
<?php
/**
* @file
* Views 2 hooks and callback registries.
*/
/**
* Implementation of hook_views_data().
*/
function uc_roles_views_data() {
$data['uc_roles_expirations']['table']['group'] = t('User');
$data['uc_roles_expirations']['table']['join'] = array(
'users' => array(
'left_field' => 'uid',
'field' => 'uid',
),
);
// Expose the role expiration date
$data['uc_roles_expirations']['expiration'] = array(
'title' => t('Ubercart Role expiration date/time'),
'help' => t('Date and time the role will expire. (See also Role expiration role.)'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// Expose the role id from uc_roles_expirations
$data['uc_roles_expirations']['rid'] = array(
'title' => t('Ubercart Role expiration role'),
'help' => t('The Role that corresponds with the Role expiration date/time'),
// Information for displaying the rid
'field' => array(
'handler' => 'uc_roles_handler_field_rid',
'click sortable' => TRUE,
),
// Information for accepting a rid as an argument
'argument' => array(
'handler' => 'views_handler_argument_users_roles_rid',
'name field' => 'title', // the field to display in the summary.
'numeric' => TRUE,
'validate type' => 'rid',
),
// Information for accepting a uid as a filter
'filter' => array(
'handler' => 'views_handler_filter_user_roles',
),
// Information for sorting on a uid.
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}
class uc_roles_handler_field_rid extends views_handler_field {
// Derived from views_handler_field_user_roles
// Purpose: get the *names* that correspond to the role_expire_rids.
function pre_render($values) {
$roles = array();
$this->items = array();
// Get all the unique role ids into the keys of $roles. Initializing into
// array_keys helps prevent us from having a list where the same rid appears
// over and over and over.
foreach ($values as $result) {
$roles[$this->get_value($result, NULL, TRUE)] = FALSE;
}
if ($roles) {
$result = db_query("SELECT r.rid, r.name FROM {role} r WHERE r.rid IN (:rids) ORDER BY r.name",
array(':rids' => array_keys($roles)));
foreach ($result as $role) {
$this->items[$role->rid]['role'] = check_plain($role->name);
$this->items[$role->rid]['rid'] = $role->rid;
}
}
}
// Render the rid as the role name.
function render($values) {
// Return the role name corresponding to the role ID.
// TODO: Should I be using this->get_value() here?
$rid = $values->uc_roles_expirations_rid;
if ($rid) {
$role = $this->items[$rid]['role'];
if (!empty($role)) {
return $role;
}
}
}
}

View File

@@ -0,0 +1,64 @@
<?php
/**
* @file
* Views hooks for Ubercart roles.
*/
/**
* Implements hook_views_data().
*/
function uc_roles_views_data() {
$data['uc_roles_expirations']['table']['group'] = t('User');
$data['uc_roles_expirations']['table']['join'] = array(
'users' => array(
'left_field' => 'uid',
'field' => 'uid',
),
);
// Expose the role expiration date.
$data['uc_roles_expirations']['expiration'] = array(
'title' => t('Ubercart Role expiration date/time'),
'help' => t('Date and time the role will expire. (See also Role expiration role.)'),
'field' => array(
'handler' => 'views_handler_field_date',
'click sortable' => TRUE,
),
'sort' => array(
'handler' => 'views_handler_sort_date',
),
'filter' => array(
'handler' => 'views_handler_filter_date',
),
);
// Expose the role id from uc_roles_expirations.
$data['uc_roles_expirations']['rid'] = array(
'title' => t('Ubercart Role expiration role'),
'help' => t('The Role that corresponds with the Role expiration date/time'),
// Information for displaying the rid
'field' => array(
'handler' => 'uc_roles_handler_field_rid',
'click sortable' => TRUE,
),
// Information for accepting a rid as an argument.
'argument' => array(
'handler' => 'views_handler_argument_users_roles_rid',
'name field' => 'title', // The field to display in the summary.
'numeric' => TRUE,
'validate type' => 'rid',
),
// Information for accepting a uid as a filter.
'filter' => array(
'handler' => 'views_handler_filter_user_roles',
),
// Information for sorting on a uid.
'sort' => array(
'handler' => 'views_handler_sort',
),
);
return $data;
}

View File

@@ -0,0 +1,52 @@
<?php
/**
* @file
* Views handler: Role ID field.
*/
/**
* Returns a role id rendered as a role name to display in the View.
*/
class uc_roles_handler_field_rid extends views_handler_field {
/**
* Overrides views_handler_field::pre_render().
*/
function pre_render(&$values) {
$roles = array();
$this->items = array();
// Get all the unique role ids into the keys of $roles. Initializing into
// array_keys helps prevent us from having a list where the same rid appears
// over and over and over.
foreach ($values as $result) {
$roles[$this->get_value($result, NULL, TRUE)] = FALSE;
}
if ($roles) {
$result = db_query("SELECT r.rid, r.name FROM {role} r WHERE r.rid IN (:rids) ORDER BY r.name",
array(':rids' => array_keys($roles)));
foreach ($result as $role) {
$this->items[$role->rid]['role'] = check_plain($role->name);
$this->items[$role->rid]['rid'] = $role->rid;
}
}
}
/**
* Overrides views_handler_field::render().
*/
function render($values) {
// Return the role name corresponding to the role ID.
// @todo: Should we be using this->get_value() here?
$rid = $values->uc_roles_expirations_rid;
if ($rid) {
$role = $this->items[$rid]['role'];
if (!empty($role)) {
return $role;
}
}
}
}