Exemplo n.º 1
0
 public function testDemoDataMaker()
 {
     $model = new Product();
     $name = 'Amazing Kid Sample';
     $productTemplateName = ProductsDemoDataMaker::getProductTemplateForProduct($name);
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName($productTemplateName);
     $model->name = $name;
     $model->quantity = mt_rand(1, 95);
     $model->productTemplate = $productTemplate;
     $model->stage->value = 'Open';
     $model->priceFrequency = $productTemplate->priceFrequency;
     $model->sellPrice->value = $productTemplate->sellPrice->value;
     $model->type = $productTemplate->type;
     $this->assertTrue($model->save());
     $id = $model->id;
     $product = Product::getById($id);
     $this->assertEquals($model->name, $product->name);
     $this->assertEquals($model->quantity, $product->quantity);
     $this->assertEquals($model->description, $product->description);
     $this->assertEquals($model->stage->value, $product->stage->value);
     $this->assertEquals($model->owner->id, $product->owner->id);
     $this->assertTrue($model->productTemplate->isSame($productTemplate));
     $this->assertEquals($model->priceFrequency, $product->priceFrequency);
     $this->assertEquals($model->sellPrice->value, $product->sellPrice->value);
     $this->assertEquals($model->type, $product->type);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //Setup test data owned by the super user.
     ProductTemplateTestHelper::createProductTemplateByName('My Product Template');
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     Currency::makeBaseCurrency();
     //Create a Product Template for testing.
     ProductTemplateTestHelper::createProductTemplateByName('superProductTemplate', $super);
 }
Exemplo n.º 4
0
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //Setup test data owned by the super user.
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
     $opportunity = OpportunityTestHelper::createOpportunityByNameForOwner('superOpportunity', $super);
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName('superProductTemplate');
     $contactWithNoAccount = ContactTestHelper::createContactByNameForOwner('noAccountContact', $super);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //Setup test data owned by the super user.
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
     $contact = ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account);
     ProductTestHelper::createProductByNameForOwner("My Product 1", $super);
     //Setup test data owned by the super user.
     ProductTemplateTestHelper::createProductTemplateByName('My Product Template');
 }
 public function testResolveProductTemplateHasManyProductCategoriesFromPost()
 {
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     $category1 = ProductCategoryTestHelper::createProductCategoryByName('Test Product Category');
     $category2 = ProductCategoryTestHelper::createProductCategoryByName('Test Product Category2');
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName('PT1');
     $postData = array('categoryIds' => $category1->id . ',' . $category2->id);
     // Not Coding Standard
     $id = $productTemplate->id;
     $productTemplate->forget();
     unset($productTemplate);
     $productTemplate = ProductTemplate::getById($id);
     $categories = ProductTemplateProductCategoriesUtil::resolveProductTemplateHasManyProductCategoriesFromPost($productTemplate, $postData);
     $this->assertEquals(count($categories), 2);
     $this->assertEquals($categories[$category1->id]->id, $category1->id);
 }
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     SecurityTestHelper::createSuperAdmin();
     $super = User::getByUsername('super');
     Yii::app()->user->userModel = $super;
     //Make sure everyone group is created
     $group = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $group->save();
     //Setup test data owned by the super user.
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
     ContactTestHelper::createContactWithAccountByNameForOwner('superContact', $super, $account);
     OpportunityTestHelper::createOpportunityWithAccountByNameForOwner('superOpportunity', $super, $account);
     ProductTestHelper::createProductStagesIfDoesNotExist();
     ProductTestHelper::createProductByNameForOwner("My Product 1", $super);
     //Setup test data owned by the super user.
     ProductTemplateTestHelper::createProductTemplateByName('My Product Template');
 }
 public static function createProductTemplateByVariables($product, $priceFrequency, $type, $status, $sellPriceFormulaType)
 {
     $currencyArray = ProductTemplateTestHelper::getCurrencyData();
     $productTemplate = new ProductTemplate();
     $productTemplate->name = 'Red Widget';
     $productTemplate->description = 'Description';
     $productTemplate->priceFrequency = $priceFrequency;
     $productTemplate->cost = $currencyArray[0];
     $productTemplate->listPrice = $currencyArray[1];
     $productTemplate->sellPrice = $currencyArray[2];
     $productTemplate->type = $type;
     $productTemplate->status = $status;
     $productTemplate->products->add($product);
     $sellPriceFormula = new SellPriceFormula();
     $sellPriceFormula->type = $sellPriceFormulaType;
     $productTemplate->sellPriceFormula = $sellPriceFormula;
     return $productTemplate;
 }
 public function testCategoryProductTemplates()
 {
     $user = UserTestHelper::createBasicUser('Steven 1');
     $productCategory = new ProductCategory();
     $productCategory->name = "My Test Category";
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName("Test Template");
     $productCategory->productTemplates->add($productTemplate);
     $this->assertTrue($productCategory->save());
     $id = $productCategory->id;
     unset($productCategory);
     $productCategory = ProductCategory::getById($id);
     $this->assertEquals(1, count($productCategory->productTemplates));
     $this->assertEquals($productTemplate, $productCategory->productTemplates[0]);
 }
 public function testSuperUserCreateAction()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     Yii::app()->user->userModel = $super;
     $this->resetGetArray();
     $currency = new Currency();
     $currency->code = 'USD';
     $currency->rateToBase = 1;
     $currency->save();
     $currencyRec = Currency::getByCode('USD');
     $currencyValue1Array = array('currency' => array('id' => $currencyRec->id), 'value' => 500.54);
     ProductTemplateTestHelper::createProductTemplateByName("My Catalog Item 1");
     $productTemplate = ProductTemplate::getByName('My Catalog Item 1');
     $product = array();
     $product['name'] = 'Red Widget';
     $product['quantity'] = 5;
     $product['priceFrequency'] = ProductTemplate::PRICE_FREQUENCY_ONE_TIME;
     $product['sellPrice'] = $currencyValue1Array;
     $product['type'] = ProductTemplate::TYPE_PRODUCT;
     $product['stage']['value'] = Product::OPEN_STAGE;
     $product['productTemplate'] = array('id' => $productTemplate[0]->id);
     $this->setPostArray(array('Product' => $product, 'Product_owner_name' => 'Super User'));
     $redirectUrl = $this->runControllerWithRedirectExceptionAndGetUrl('products/default/create');
     $products = Product::getByName('Red Widget');
     $this->assertEquals(1, count($products));
     $this->assertTrue($products[0]->id > 0);
     $this->assertEquals(500.54, $products[0]->sellPrice->value);
     $compareRedirectUrl = Yii::app()->createUrl('products/default/details', array('id' => $products[0]->id));
     $this->assertEquals($compareRedirectUrl, $redirectUrl);
 }
 /**
  * Walkthrough test for synchronous download
  */
 public function testAsynchronousDownloadDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $notificationsBeforeCount = count(Notification::getAll());
     $notificationMessagesBeforeCount = count(NotificationMessage::getAll());
     $productTemplates = ProductTemplate::getAll();
     if (count($productTemplates)) {
         foreach ($productTemplates as $productTemplate) {
             $productTemplate->delete();
         }
     }
     $productTemplates = array();
     for ($i = 0; $i <= ExportModule::$asynchronusThreshold + 1; $i++) {
         $productTemplates[] = ProductTemplateTestHelper::createProductTemplateByName('superProductTemplate' . $i);
     }
     $this->setGetArray(array('ProductTemplate_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '1', 'selectedIds' => ''));
     $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('productTemplates', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll()));
     $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll()));
     // Check export job, when many ids are selected.
     // This will probably never happen, but we need test for this case too.
     $notificationsBeforeCount = count(Notification::getAll());
     $notificationMessagesBeforeCount = count(NotificationMessage::getAll());
     // Now test case when multiple ids are selected
     $exportItems = ExportItem::getAll();
     if (count($exportItems)) {
         foreach ($exportItems as $exportItem) {
             $exportItem->delete();
         }
     }
     $selectedIds = "";
     foreach ($productTemplates as $productTemplate) {
         $selectedIds .= $productTemplate->id . ",";
         // Not Coding Standard
     }
     $this->setGetArray(array('ProductTemplatesSearchForm' => array('anyMixedAttributesScope' => array(0 => 'All'), 'anyMixedAttributes' => '', 'name' => ''), 'multiselect_ProductTemplatesSearchForm_anyMixedAttributesScope' => 'All', 'ProductTemplate_page' => '1', 'export' => '', 'ajax' => '', 'selectAll' => '', 'selectedIds' => "{$selectedIds}"));
     $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/default/export');
     // Start background job
     $job = new ExportJob();
     $this->assertTrue($job->run());
     $exportItems = ExportItem::getAll();
     $this->assertEquals(1, count($exportItems));
     $fileModel = $exportItems[0]->exportFileModel;
     $this->assertEquals(1, $exportItems[0]->isCompleted);
     $this->assertEquals('csv', $exportItems[0]->exportFileType);
     $this->assertEquals('productTemplates', $exportItems[0]->exportFileName);
     $this->assertTrue($fileModel instanceof ExportFileModel);
     $this->assertEquals($notificationsBeforeCount + 1, count(Notification::getAll()));
     $this->assertEquals($notificationMessagesBeforeCount + 1, count(NotificationMessage::getAll()));
 }
Exemplo n.º 12
0
 public function testUpdateRelatedCatalogItemOnAProductBySellPriceCriteria()
 {
     $super = User::getByUsername('super');
     $contactStates = ContactState::getAll();
     //Create workflow
     $workflow = new Workflow();
     $workflow->setDescription('aDescription');
     $workflow->setIsActive(true);
     $workflow->setOrder(1);
     $workflow->setModuleClassName('ProductsModule');
     $workflow->setName('myFirstProductWorkflow');
     $workflow->setTriggerOn(Workflow::TRIGGER_ON_NEW_AND_EXISTING);
     $workflow->setType(Workflow::TYPE_ON_SAVE);
     $workflow->setTriggersStructure('1');
     //Add Trigger
     $trigger = new TriggerForWorkflowForm('ProductsModule', 'Product', Workflow::TYPE_ON_SAVE);
     $trigger->attributeIndexOrDerivedType = 'sellPrice';
     $trigger->value = 600;
     $trigger->operator = 'greaterThanOrEqualTo';
     $workflow->addTrigger($trigger);
     //Add action
     $currencies = Currency::getAll();
     $action = new ActionForWorkflowForm('Product', Workflow::TYPE_ON_SAVE);
     $action->type = ActionForWorkflowForm::TYPE_UPDATE_RELATED;
     $action->relation = 'productTemplate';
     $attributes = array('description' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 'Set Price'), 'priceFrequency' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 2), 'listPrice' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 800, 'currencyId' => $currencies[0]->id), 'cost' => array('shouldSetValue' => '1', 'type' => WorkflowActionAttributeForm::TYPE_STATIC, 'value' => 700, 'currencyId' => $currencies[0]->id));
     $action->setAttributes(array(ActionForWorkflowForm::ACTION_ATTRIBUTES => $attributes));
     $workflow->addAction($action);
     //Create the saved Workflow
     $savedWorkflow = new SavedWorkflow();
     SavedWorkflowToWorkflowAdapter::resolveWorkflowToSavedWorkflow($workflow, $savedWorkflow);
     $saved = $savedWorkflow->save();
     $this->assertTrue($saved);
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName('superProductTemplate');
     $productTemplates = ProductTemplate::getByName('superProductTemplate');
     $product = ProductTestHelper::createProductByNameForOwner('Test Product', $super);
     $this->assertTrue($product->id > 0);
     $product->productTemplate = $productTemplates[0];
     //Change product sell price
     $product->sellPrice->value = 650;
     $this->assertTrue(WorkflowTriggersUtil::areTriggersTrueBeforeSave($workflow, $product));
     $saved = $product->save();
     $this->assertTrue($saved);
     $productId = $product->id;
     $product->forget();
     $product = Product::getById($productId);
     $this->assertEquals('Set Price', $product->productTemplate->description);
     $this->assertEquals(2, $product->productTemplate->priceFrequency);
     $this->assertEquals(700, $product->productTemplate->cost->value);
     $this->assertEquals(800, $product->productTemplate->listPrice->value);
 }
Exemplo n.º 13
0
 public function testPriceValidation()
 {
     $user = UserTestHelper::createBasicUser('Steven3');
     $product = ProductTestHelper::createProductByNameForOwner('Product 2', $user);
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByVariables($product, ProductTemplate::PRICE_FREQUENCY_ONE_TIME, ProductTemplate::TYPE_PRODUCT, ProductTemplate::STATUS_ACTIVE, SellPriceFormula::TYPE_EDITABLE);
     $productTemplate->cost->value = -200;
     $this->assertFalse($productTemplate->save());
     $productTemplate->sellPrice->value = -200;
     $this->assertFalse($productTemplate->save());
     $productTemplate->listPrice->value = -200;
     $this->assertFalse($productTemplate->save());
     $productTemplate->listPrice->value = 100;
     $productTemplate->sellPrice->value = 100;
     $productTemplate->cost->value = 100;
     $this->assertTrue($productTemplate->save());
 }
 public function testCloningWithAnotherProductTemplate()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     Yii::app()->user->userModel = $super;
     $productTemplate = ProductTemplateTestHelper::createProductTemplateByName("My Copy Catalog Item");
     $id = $productTemplate->id;
     $this->setGetArray(array('id' => $id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/copy');
     $this->assertTrue(strpos($content, 'My Copy Catalog Item') > 0);
     $productTemplates = ProductTemplate::getAll();
     $this->assertEquals(1, count($productTemplates));
 }