t('Anonymous purchasing'), 'description' => t('Test the purchasing of products that are marked as anonymous or for registed users.'), 'group' => t('e-Commerce'), ); } function setUp() { parent::setUp('ec_product', 'ec_anon', 'ec_buynow', 'ec_cart', 'ctools', 'ec_checkout', 'ec_store', 'ec_common', 'rules'); } function testAnonUserPurchase() { $product = array( 'type' => 'product', 'ptype' => 'generic', 'price' => '20.00', 'anon_policy' => 1, ); $node = $this->drupalCreateNode($product); $this->drupalGet('node/' . $node->nid); $this->assertNoLink(t('Buy now'), t('Buy now link doesn\'t exist')); $this->assertNoLink(t('Add to cart'), t('Add to cart link doesn\'t exist')); $this->drupalGet('node/' . $node->nid . '/checkout'); $this->assertText(t('Only registered users can purchase this product'), t('Product can\'t be purchased by anonymous customers')); $product['anon_policy'] = 3; $node = $this->drupalCreateNode($product); $this->drupalGet('node/' . $node->nid); $this->assertLink(t('Buy now')); $this->assertLink(t('Add to cart')); $this->clickLink(t('Buy now')); $this->assertNoText(t('Only registered users can purchase this product'), t('Product can be purchased by anonymous customers')); } function testAnonUserPurchaseWithLogin() { $product = array( 'type' => 'product', 'ptype' => 'generic', 'price' => '20.00', 'anon_policy' => 4, ); $node = $this->drupalCreateNode($product); $this->drupalGet('node/'. $node->nid); $this->assertLink(t('Buy now'), 0, t('Buy now link exist')); $this->assertLink(t('Add to cart'), 0, t('Add to cart link exist')); $this->assertNoText(t('Only registered users can purchase this product'), t('Product can\'t be purchased by anonymous customers')); $this->clickLink('Buy now'); $this->assertText('Login or register to continue the checkout process', t('Redirection to login process to purchase product restricted to registered users.')); $this->assertField('edit-name', t('Username field exists')); $this->assertField('edit-pass', t('Password field exists')); } function testRegisteredUserPurchase() { $account = $this->drupalCreateUser(); $this->drupalLogin($account); $product = array( 'ptype' => 'generic', 'price' => '20.00', 'anon_policy' => 3, ); $node = $this->drupalCreateNode($product); $this->drupalGet('node/' . $node->nid); $this->assertNoLink(t('Buy now'), t('Buy now link doesn\'t exist')); $this->assertNoLink(t('Add to cart'), t('Add to cart link doesn\'t exist')); $this->drupalGet('node/' . $node->nid . '/checkout'); $this->assertText(t('Only non-registered users can purchase this product'), t('Product can\'t be purchased by registered customers')); $product['anon_policy'] = 1; $node = $this->drupalCreateNode($product); $this->drupalGet('node/' . $node->nid); $this->assertLink(t('Buy now')); $this->assertLink(t('Add to cart')); $this->clickLink(t('Buy now')); $this->assertNoText(t('Only non-registered users can purchase this product'), t('Product can be purchased by registered customers')); } function testAnonUserPurchaseWithAnonymousInCart() { $product = array( 'type' => 'product', 'ptype' => 'generic', 'price' => '20.00', 'anon_policy' => 4, ); $registered_product = $this->drupalCreateNode($product); $product['anon_policy'] = 3; $anonymous_product = $this->drupalCreateNode($product); $this->drupalGet('node/'. $anonymous_product->nid); $this->assertLink(t('Buy now'), 0, t('Buy now link exist')); $this->assertLink(t('Add to cart'), 0, t('Add to cart link exist')); $this->assertNoText(t('Only registered users can purchase this product'), t('Product can\'t be purchased by anonymous customers')); $this->clickLink('Add to cart'); $this->drupalGet('node/' . $registered_product->nid); $this->assertLink(t('Buy now'), 0, t('Buy now link exist')); $this->assertNoLink(t('Add to cart'), 0, t('Add to cart link doesn\'t exist')); } function testAnonUserPurchaseWithRegisteredInCart() { $product = array( 'type' => 'product', 'ptype' => 'generic', 'price' => '20.00', 'anon_policy' => 4, ); $registered_product = $this->drupalCreateNode($product); $product['anon_policy'] = 3; $anonymous_product = $this->drupalCreateNode($product); $this->drupalGet('node/'. $registered_product->nid); $this->assertLink(t('Buy now'), 0, t('Buy now link exist')); $this->assertLink(t('Add to cart'), 0, t('Add to cart link exist')); $this->assertNoText(t('Only registered users can purchase this product'), t('Product can\'t be purchased by anonymous customers')); $this->clickLink('Add to cart'); $this->drupalGet('node/' . $anonymous_product->nid); $this->assertLink(t('Buy now'), 0, t('Buy now link exist')); $this->assertNoLink(t('Add to cart'), 0, t('Add to cart link doesn\'t exist')); } } class ecProductCreateWithAnon extends DrupalWebTestCase { function getInfo() { return array( 'name' => t('Product Creation with Anonmous'), 'description' => t('Test product creation with Anonymous module enabled.\.'), 'group' => t('e-Commerce'), ); } function setUp() { parent::setUp('ec_common', 'ec_product', 'ec_anon', 'ctools'); variable_set('ec_default_currency', 'USD'); } function testCreateProduct() { $account = $this->drupalCreateUser(array('create product content', 'administer products')); $this->drupalLogin($account); $edit = array( 'title' => $this->randomString(20), 'body[und][0][value]' => $this->randomString(50), 'price' => format_currency(rand(1, 100000) / 100), 'anon_policy' => 3, ); $this->drupalPost('node/add/product/generic', $edit, t('Save')); } }