updated ubercart, faq
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* File download product feature tests.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Tests the file download purchase functionality.
|
||||
*/
|
||||
class UbercartFileTestCase extends UbercartTestHelper {
|
||||
|
||||
public static function getInfo() {
|
||||
return array(
|
||||
'name' => 'File downloads',
|
||||
'description' => 'Ensures that the purchase of file downloads functions correctly.',
|
||||
'group' => 'Ubercart',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Overrides DrupalWebTestCase::setUp().
|
||||
*/
|
||||
public function setUp($modules = array(), $permissions = array()) {
|
||||
$modules = array('uc_payment', 'uc_payment_pack', 'uc_file');
|
||||
$permissions = array();
|
||||
parent::setUp($modules, $permissions);
|
||||
|
||||
// Need admin permissions in order to change file download settings.
|
||||
$this->drupalLogin($this->adminUser);
|
||||
|
||||
// Set up directory for files to live in.
|
||||
$this->configureDownloadDirectory();
|
||||
}
|
||||
|
||||
function testFilePurchaseCheckout() {
|
||||
// Add file download feature to the test product.
|
||||
$filename = $this->uploadTestFile();
|
||||
$this->drupalLogin($this->adminUser);
|
||||
$this->drupalPost('node/' . $this->product->nid . '/edit/features', array('feature' => 'file'), t('Add'));
|
||||
$edit = array(
|
||||
'uc_file_model' => '',
|
||||
'uc_file_filename' => $filename,
|
||||
);
|
||||
$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 file was granted.
|
||||
$this->drupalGet('user/' . $order->uid . '/purchased-files');
|
||||
$this->assertText($filename, 'File found in list of purchased files.');
|
||||
|
||||
// Test that the email is correct.
|
||||
$mail = $this->findMail('/File Downloads for Order# ' . preg_quote($order->order_id) . '/');
|
||||
|
||||
// Delete the user.
|
||||
user_delete($order->uid);
|
||||
|
||||
// Run cron to ensure deleted users are handled correctly.
|
||||
$this->drupalLogout();
|
||||
$this->cronRun();
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to configure Credit Card payment method settings.
|
||||
*/
|
||||
protected function configureDownloadDirectory() {
|
||||
// Create directory for downloads, make it readable and writeable.
|
||||
// Putting this under sites/default/files because SimpleTest needs to be
|
||||
// able to create the directory - this is NOT where you'd put the downloads
|
||||
// directory on a live site. On a live site, it should be outside the web root.
|
||||
drupal_mkdir('sites/default/files/file-downloads', 0755);
|
||||
|
||||
$this->drupalPost(
|
||||
'admin/store/settings/products',
|
||||
array(
|
||||
'uc_file_base_dir' => 'sites/default/files/file-downloads',
|
||||
),
|
||||
t('Save configuration')
|
||||
);
|
||||
|
||||
$this->assertFieldByName(
|
||||
'uc_file_base_dir',
|
||||
'sites/default/files/file-downloads',
|
||||
'Download file path has been set.'
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Helper function to upload test file for downloading.
|
||||
*/
|
||||
protected function uploadTestFile() {
|
||||
$filename = 'README.txt';
|
||||
// Use the Ubercart README.txt because we know it will always be there
|
||||
// and we know in advance how big it is.
|
||||
copy(drupal_get_path('module', 'uc_file') . '/../' . $filename,
|
||||
'sites/default/files/file-downloads/README.txt'
|
||||
);
|
||||
return $filename;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function tearDown() {
|
||||
// Cleanup file download directory after test.
|
||||
drupal_unlink('sites/default/files/file-downloads/README.txt');
|
||||
drupal_rmdir('sites/default/files/file-downloads');
|
||||
parent::tearDown();
|
||||
}
|
||||
|
||||
}
|
@@ -409,7 +409,7 @@ function uc_file_admin_files_form_action_submit($form, &$form_state) {
|
||||
drupal_set_message(t('The selected file(s) have been deleted.'));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('One or more files could not be deleted.'));
|
||||
drupal_set_message(t('One or more files could not be deleted.'), 'warning');
|
||||
}
|
||||
|
||||
break;
|
||||
@@ -440,11 +440,11 @@ function uc_file_admin_files_form_action_submit($form, &$form_state) {
|
||||
drupal_set_message(t('The file %file has been uploaded to %dir', array('%file' => $file_object->filename, '%dir' => $dir)));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('An error occurred while copying the file to %dir', array('%dir' => $dir)));
|
||||
drupal_set_message(t('An error occurred while copying the file to %dir', array('%dir' => $dir)), 'error');
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('Can not move file to %dir', array('%dir' => $dir)));
|
||||
drupal_set_message(t('Can not move file to %dir', array('%dir' => $dir)), 'error');
|
||||
}
|
||||
|
||||
break;
|
||||
|
@@ -2,6 +2,7 @@
|
||||
* @file
|
||||
* Styles for uc_file module.
|
||||
*/
|
||||
|
||||
.download-table-row {
|
||||
vertical-align: top;
|
||||
}
|
||||
|
@@ -5,12 +5,15 @@ dependencies[] = uc_order
|
||||
package = Ubercart - core (optional)
|
||||
core = 7.x
|
||||
|
||||
; Test cases
|
||||
files[] = tests/uc_file.test
|
||||
|
||||
stylesheets[all][] = uc_file.css
|
||||
scripts[] = uc_file.js
|
||||
|
||||
; 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"
|
||||
|
||||
|
@@ -453,7 +453,7 @@ function uc_file_uc_add_to_cart($nid, $qty, $data) {
|
||||
'%download_limit' => $file_user['download_limit'] ? $file_user['download_limit'] : t('unlimited'),
|
||||
'%address_limit' => $file_user['address_limit' ] ? $file_user['address_limit' ] : t('unlimited'),
|
||||
'%expiration' => $file_user['expiration' ] ? format_date($file_user['expiration'], 'small') : t('never'),
|
||||
)));
|
||||
)), 'warning');
|
||||
}
|
||||
else {
|
||||
return array(array(
|
||||
@@ -528,11 +528,14 @@ function uc_file_uc_store_status() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Product feature delete function.
|
||||
* Deletes all file data associated with a given product feature.
|
||||
*
|
||||
* @param $pfid
|
||||
* An Ubercart product feature ID.
|
||||
*/
|
||||
function uc_file_feature_delete($feature) {
|
||||
function uc_file_feature_delete($pfid) {
|
||||
db_delete('uc_file_products')
|
||||
->condition('pfid', $feature['pfid'])
|
||||
->condition('pfid', $pfid)
|
||||
->execute();
|
||||
}
|
||||
|
||||
@@ -545,12 +548,18 @@ function uc_file_feature_delete($feature) {
|
||||
*/
|
||||
function uc_file_feature_form($form, &$form_state, $node, $feature) {
|
||||
if (!is_dir(variable_get('uc_file_base_dir', NULL))) {
|
||||
drupal_set_message(t('A file directory needs to be configured in <a href="@url">product settings</a> under the file download settings tab before a file can be selected.', array('@url' => url('admin/store/settings/products'))), 'error');
|
||||
drupal_set_message(t('A file directory needs to be configured in <a href="@url">product settings</a> under the file download settings tab before a file can be selected.', array('@url' => url('admin/store/settings/products'))), 'warning');
|
||||
|
||||
unset($form['buttons']);
|
||||
return $form;
|
||||
}
|
||||
|
||||
// Rescan the file directory to populate {uc_files} with the current list
|
||||
// because files uploaded via any method other than the Upload button
|
||||
// (e.g. by FTP) won'b be in {uc_files} yet.
|
||||
|
||||
uc_file_refresh();
|
||||
|
||||
if (!db_query_range('SELECT 1 FROM {uc_files}', 0, 1)->fetchField()) {
|
||||
$form['file']['file_message'] = array(
|
||||
'#markup' => t(
|
||||
@@ -563,9 +572,6 @@ function uc_file_feature_form($form, &$form_state, $node, $feature) {
|
||||
return $form;
|
||||
}
|
||||
|
||||
// Make sure we have an up-to-date list for the autocompletion.
|
||||
uc_file_refresh();
|
||||
|
||||
// Grab all the models on this product.
|
||||
$models = uc_product_get_models($node->nid);
|
||||
|
||||
@@ -790,7 +796,7 @@ function uc_file_feature_form_submit($form, &$form_state) {
|
||||
$description .= t('<strong>Directory:</strong> !dir<br />', array('!dir' => $file_product['filename']));
|
||||
}
|
||||
else {
|
||||
$description .= t('<strong>File:</strong> !file<br />', array('!file' => basename($file_product['filename'])));;
|
||||
$description .= t('<strong>File:</strong> !file<br />', array('!file' => basename($file_product['filename'])));
|
||||
}
|
||||
$description .= $file_product['shippable'] ? t('<strong>Shippable:</strong> Yes') : t('<strong>Shippable:</strong> No');
|
||||
|
||||
@@ -1238,12 +1244,12 @@ function uc_file_remove_by_id($fid, $recur) {
|
||||
$remove_fields = TRUE;
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('The directory %dir could not be deleted.', array('%dir' => $filename)));
|
||||
drupal_set_message(t('The directory %dir could not be deleted.', array('%dir' => $filename)), 'warning');
|
||||
$result = FALSE;
|
||||
}
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('The directory %dir could not be deleted because it is not empty.', array('%dir' => $filename)));
|
||||
drupal_set_message(t('The directory %dir could not be deleted because it is not empty.', array('%dir' => $filename)), 'warning');
|
||||
$result = FALSE;
|
||||
}
|
||||
}
|
||||
@@ -1254,7 +1260,7 @@ function uc_file_remove_by_id($fid, $recur) {
|
||||
drupal_set_message(t('The file %dir was deleted.', array('%dir' => $filename)));
|
||||
}
|
||||
else {
|
||||
drupal_set_message(t('The file %dir could not be deleted.', array('%dir' => $filename)));
|
||||
drupal_set_message(t('The file %dir could not be deleted.', array('%dir' => $filename)), 'error');
|
||||
$result = FALSE;
|
||||
}
|
||||
}
|
||||
|
@@ -12,6 +12,9 @@
|
||||
* An associative array containing:
|
||||
* - form: A render element representing the form.
|
||||
*
|
||||
* @return string
|
||||
* The HTML output.
|
||||
*
|
||||
* @ingroup themeable
|
||||
*/
|
||||
function theme_uc_file_hook_user_file_downloads($variables) {
|
||||
|
Reference in New Issue
Block a user