You are here

commerce_pricelist_feeds.test in Commerce Pricelist 7

Functional tests for the commerce pricelist role module.

File

commerce_pricelist_feeds/tests/commerce_pricelist_feeds.test
View source
<?php

/**
 * @file
 * Functional tests for the commerce pricelist role module.
 */

/**
 * Test price list features for a product display that only has one product attached.
 */
class CommercePricelistFeedsTestCaseSimpleProduct extends CommercePricelistTestCase {
  protected $my_pricelist;
  protected $feeds_admin;

  /**
   * Implementation of getInfo().
   */
  public static function getInfo() {
    return array(
      'name' => 'Commerce Pricelist Feeds',
      'description' => 'Test importing pricelist items through feeds',
      'group' => 'Commerce Pricelist',
    );
  }

  /**
   * Implementation of setUp().
   */
  function setUp($other_modules = array()) {
    parent::setUp(array(
      'commerce_pricelist_feeds',
      'commerce_pricelist_feeds_example',
      'feeds',
      'feeds_ui',
    ));
    $this->feeds_admin = $this
      ->createAdminUser(array(
      'administer feeds',
    ));
    $this->my_pricelist = $this
      ->createDummyPricelist('My pricelist', 1);
  }

  /**
   * Test if importing pricelists through feeds works.
   */
  public function testCommercePricelistImport() {

    // Log in as a admin.
    $this
      ->drupalLogin($this->feeds_admin);
    $edit = array();

    // Upload csv file
    $rpath = drupal_get_path('module', 'commerce_pricelist_feeds_example');
    $rpath = realpath($rpath . '/sample_import_data.csv');
    $edit['files[feeds]'] = $rpath;
    $pricelist_path = 'admin/commerce/pricelist/commerce_pricelist_list/' . $this->pricelist_a->list_id;

    // Submit attached pricelist form
    $this
      ->drupalPost($pricelist_path . '/edit', $edit, t('Save'));
    $this
      ->assertText('Created 2 commerce pricelist_items.', t('Sucessfully imported pricelist items through csv file'));
    $this
      ->drupalGet($pricelist_path);
    $this
      ->assertNoText('No price list items currently exist.', t('Pricelist items were imported into the correct list.'));

    // Test import with pricelist name in import file
    $this
      ->drupalPost('/import/commerce_pricelist_csv_example', $edit, t('Import'));
    $this
      ->assertText('Created 2 commerce pricelist_items.', t('Sucessfully imported pricelist items through csv file into named pricelist'));

    // Post again to make sure we don't get duplicates
    $this
      ->drupalPost('/import/commerce_pricelist_csv_example', $edit, t('Import'));
    $this
      ->assertText('Found and replaced a duplicate pricelist item in this list.', t("Made sure we don't get duplicates"));
    $pricelist_path = 'admin/commerce/pricelist/commerce_pricelist_list/' . $this->my_pricelist->list_id;
    $this
      ->drupalGet($pricelist_path);
    $this
      ->assertNoText('No price list items currently exist.', t('Pricelist items were imported into the correct list.'));
  }

}

Classes

Namesort descending Description
CommercePricelistFeedsTestCaseSimpleProduct Test price list features for a product display that only has one product attached.