Révision 280fe687
Ajouté par Assos Assos il y a plus de 8 ans
drupal7/sites/all/modules/commerce/tests/commerce_base.test | ||
---|---|---|
30 | 30 |
$dependencies = array( |
31 | 31 |
// API |
32 | 32 |
'entity', |
33 |
'entity_token',
|
|
33 |
'entity_token',
|
|
34 | 34 |
'rules', |
35 | 35 |
'addressfield', |
36 | 36 |
//'rules_admin', |
... | ... | |
283 | 283 |
$new_product->uid = $uid; |
284 | 284 |
|
285 | 285 |
$new_product->commerce_price[LANGUAGE_NONE][0]['amount'] = ($amount < 0) ? rand(2, 500) : $amount; |
286 |
$new_product->commerce_price[LANGUAGE_NONE][0]['currency_code'] = 'USD';
|
|
286 |
$new_product->commerce_price[LANGUAGE_NONE][0]['currency_code'] = $currency_code;
|
|
287 | 287 |
|
288 | 288 |
commerce_product_save($new_product); |
289 | 289 |
|
... | ... | |
582 | 582 |
* Type of the customer profile, default billing. |
583 | 583 |
* @param $uid |
584 | 584 |
* User id that will own the profile, by default anonymous. |
585 |
* @param $address_info |
|
586 |
* Address information, associative array keyed by the field name. |
|
587 |
* i.e. 'commerce_customer_address'. |
|
588 | 585 |
* |
589 | 586 |
* @return |
590 | 587 |
* The customer profile created or FALSE if the profile wasn't created. |
591 | 588 |
*/ |
592 |
public function createDummyCustomerProfile($type = 'billing', $uid = 0, $address_info = array()) { |
|
593 |
variable_set('site_default_country', 'US'); |
|
589 |
public function createDummyCustomerProfile($type = 'billing', $uid = 0) { |
|
594 | 590 |
// Initialize the profile. |
595 | 591 |
$profile = commerce_customer_profile_new($type, $uid); |
596 |
|
|
597 |
// Set the defaults.
|
|
592 |
// Initialize the address. |
|
593 |
$defaults = array();
|
|
598 | 594 |
$defaults['name_line'] = $this->randomName(); |
599 |
$defaults = array_merge($defaults, addressfield_default_values(), $this->generateAddressInformation()); |
|
600 |
|
|
601 |
// Get all the fields for the given type, by default billing. |
|
602 |
$instances = field_info_instances('commerce_customer_profile', $type); |
|
603 |
foreach ($instances as $name => $instance) { |
|
604 |
$info_field = field_info_field($name); |
|
605 |
if ($info_field['type'] == 'addressfield') { |
|
606 |
$values = !empty($address_info[$name]) ? array_merge($defaults, $address_info[$name]) : $defaults; |
|
607 |
$values['data'] = serialize($values['data']); |
|
608 |
$profile->{$name}[LANGUAGE_NONE][] = $values; |
|
609 |
} |
|
610 |
} |
|
595 |
$field = field_info_field('commerce_customer_address'); |
|
596 |
$instance = field_info_instance('commerce_customer_profile', 'commerce_customer_address', $type); |
|
597 |
$values = array_merge($defaults, addressfield_default_values($field, $instance), $this->generateAddressInformation()); |
|
598 |
$values['data'] = serialize($values['data']); |
|
599 |
$profile->commerce_customer_address[LANGUAGE_NONE][] = $values; |
|
600 |
// Save the dummy profile. |
|
611 | 601 |
commerce_customer_profile_save($profile); |
602 |
|
|
612 | 603 |
return $profile; |
613 | 604 |
} |
614 | 605 |
|
... | ... | |
695 | 686 |
// Loop through the line items looking for products. |
696 | 687 |
foreach (entity_metadata_wrapper('commerce_order', $order)->commerce_line_items as $delta => $line_item_wrapper) { |
697 | 688 |
// If this line item matches the product checked... |
698 |
if ($line_item_wrapper->type->value() == 'product' &&
|
|
689 |
if ($line_item_wrapper->getBundle() == 'product' &&
|
|
699 | 690 |
$line_item_wrapper->commerce_product->product_id->value() == $product->product_id) { |
700 | 691 |
$product_is_in_cart = TRUE; |
701 | 692 |
} |
... | ... | |
739 | 730 |
|
740 | 731 |
} |
741 | 732 |
|
742 |
|
|
743 |
/** |
|
744 |
* Sandbox for trying new things with tests. Eases development so only one test |
|
745 |
* has to run at a time. Move everything to CommerceBaseTesterTestCase after it |
|
746 |
* is functioning here. |
|
747 |
*/ |
|
748 |
class CommerceSandboxTestCase extends CommerceBaseTestCase { |
|
749 |
protected $site_admin; |
|
750 |
|
|
751 |
/** |
|
752 |
* getInfo() returns properties that are displayed in the test selection form. |
|
753 |
*/ |
|
754 |
public static function getInfo() { |
|
755 |
return array( |
|
756 |
'name' => t('Commerce sandbox'), |
|
757 |
'description' => t('Sandbox for trying new things with tests. Eases development so only one test has to run at a time.'), |
|
758 |
'group' => t('Drupal Commerce'), |
|
759 |
); |
|
760 |
} |
|
761 |
|
|
762 |
/** |
|
763 |
* setUp() performs any pre-requisite tasks that need to happen. |
|
764 |
*/ |
|
765 |
public function setUp() { |
|
766 |
$modules = parent::setUpHelper('all'); |
|
767 |
parent::setUp($modules); |
|
768 |
|
|
769 |
$this->site_admin = $this->createSiteAdmin(); |
|
770 |
cache_clear_all(); // Just in case |
|
771 |
} |
|
772 |
|
|
773 |
/** |
|
774 |
* Sandbox for test development |
|
775 |
*/ |
|
776 |
public function testTestTest() { |
|
777 |
|
|
778 |
} |
|
779 |
|
|
780 |
/** |
|
781 |
* Test the createDummyCustomerProfile function. |
|
782 |
*/ |
|
783 |
public function testTestCreateDummyCustomerProfile() { |
|
784 |
$store_admin = $this->createStoreAdmin(); |
|
785 |
// Create a new customer profile for the store admin. |
|
786 |
$profile = $this->createDummyCustomerProfile('billing', $store_admin->uid); |
|
787 |
|
|
788 |
// Load profile reseting cache. |
|
789 |
$profile = reset(commerce_customer_profile_load_multiple(array($profile->profile_id), array(), TRUE)); |
|
790 |
|
|
791 |
$this->assertFalse(empty($profile), t('Profile can be loaded from database')); |
|
792 |
|
|
793 |
// Login with store admin user and navigate to the profile listing page. |
|
794 |
$this->drupalLogin($store_admin); |
|
795 |
$this->drupalGet('admin/commerce/customer-profiles'); |
|
796 |
|
|
797 |
$this->assertText($profile->commerce_customer_address[LANGUAGE_NONE][0]['name_line'], t('\'Name line\' field for the profile created is present in the customer profile listing')); |
|
798 |
$type = commerce_customer_profile_type_load($profile->type); |
|
799 |
$this->assertText($type['name'], t('The type of the profile is informed in the profile listing page')); |
|
800 |
} |
|
801 |
|
|
802 |
} |
|
803 |
|
|
804 | 733 |
/** |
805 | 734 |
* Test class to test the CommerceBaseTestCase functions. All testTestFoo |
806 | 735 |
* functions have "testTest" in the name to indicate that they are verifying |
Formats disponibles : Unified diff
Weekly update of contrib modules