<commit_before><?php
    /*********************************************************************************
     * Zurmo is a customer relationship management program developed by
     * Zurmo, Inc. Copyright (C) 2013 Zurmo Inc.
     *
     * Zurmo is free software; you can redistribute it and/or modify it under
     * the terms of the GNU General Public License version 3 as published by the
     * Free Software Foundation with the addition of the following permission added
     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
     *
     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
     * details.
     *
     * You should have received a copy of the GNU General Public License along with
     * this program; if not, see http://www.gnu.org/licenses or write to the Free
     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
     * 02110-1301 USA.
     *
     * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
     * Suite 370 Chicago, IL 60606. or at email address <EMAIL>.
     *
     * The interactive user interfaces in original and modified versions
     * of this program must display Appropriate Legal Notices, as required under
     * Section 5 of the GNU General Public License version 3.
     *
     * In accordance with Section 7(b) of the GNU General Public License version 3,
     * these Appropriate Legal Notices must retain the display of the Zurmo
     * logo and Zurmo copyright notice. If the display of the logo is not reasonably
     * feasible for technical reasons, the Appropriate Legal Notices must display the words
     * "Copyright Zurmo Inc. 2013. All rights reserved".
     ********************************************************************************/

    /**
    * Designer Module Walkthrough of productTemplates.
    * Walkthrough for the super user of all possible controller actions.
    * Since this is a super user, he should have access to all controller actions
    * without any exceptions being thrown.
    * This also test the creation of the customfileds, addition of custom fields to all the layouts including the search
    * views.
    * This also test creation search, edit and delete of the ProductTemplate based on the custom fields.
    */
    class ProductTemplatesDesignerSuperUserWalkthroughTest extends ZurmoWalkthroughBaseTest
    {
        public static $activateDefaultLanguages = true;

        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);
        }

         public function testSuperUserProductTemplateDefaultControllerActions()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');

            //Default Controller actions requiring some sort of parameter via POST or GET
            //Load Product Modules Menu.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/modulesMenu');

            //Load AttributesList for ProductTemplate module.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/attributesList');

            //Load ModuleLayoutsList for ProductTemplate module.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/moduleLayoutsList');

            //Now confirm everything did in fact save correctly.
            $this->assertEquals('Catalog Item',  ProductTemplatesModule::getModuleLabelByTypeAndLanguage('Singular'));
            $this->assertEquals('Catalog Items', ProductTemplatesModule::getModuleLabelByTypeAndLanguage('Plural'));
            $this->assertEquals('catalog item',  ProductTemplatesModule::getModuleLabelByTypeAndLanguage('SingularLowerCase'));
            $this->assertEquals('catalog items', ProductTemplatesModule::getModuleLabelByTypeAndLanguage('PluralLowerCase'));

            //Load LayoutEdit for each applicable module and applicable layout
            $this->resetPostArray();
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplatesListView'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplatesModalListView'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplatesModalSearchView'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplateEditAndDetailsView'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
        }

        /**
         * @depends testSuperUserProductTemplateDefaultControllerActions
         */
        public function testSuperUserCustomFieldsWalkthroughForProductTemplatesModule()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');

            //Test create field list.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule'));

            //View creation screen, then create custom field for each custom field type.
            $this->createCheckBoxCustomFieldByModule            ('ProductTemplatesModule', 'checkbox');
            $this->createCurrencyValueCustomFieldByModule       ('ProductTemplatesModule', 'currency');
            $this->createDateCustomFieldByModule                ('ProductTemplatesModule', 'date');
            $this->createDateTimeCustomFieldByModule            ('ProductTemplatesModule', 'datetime');
            $this->createDecimalCustomFieldByModule             ('ProductTemplatesModule', 'decimal');
            $this->createDropDownCustomFieldByModule            ('ProductTemplatesModule', 'picklist');
            $this->createDependentDropDownCustomFieldByModule   ('ProductTemplatesModule', 'countrylist');
            $this->createDependentDropDownCustomFieldByModule   ('ProductTemplatesModule', 'statelist');
            $this->createDependentDropDownCustomFieldByModule   ('ProductTemplatesModule', 'citylist');
            $this->createIntegerCustomFieldByModule             ('ProductTemplatesModule', 'integer');
            $this->createMultiSelectDropDownCustomFieldByModule ('ProductTemplatesModule', 'multiselect');
            $this->createTagCloudCustomFieldByModule            ('ProductTemplatesModule', 'tagcloud');
            $this->createCalculatedNumberCustomFieldByModule    ('ProductTemplatesModule', 'calcnumber');
            $this->createDropDownDependencyCustomFieldByModule  ('ProductTemplatesModule', 'dropdowndep');
            $this->createPhoneCustomFieldByModule               ('ProductTemplatesModule', 'phone');
            $this->createRadioDropDownCustomFieldByModule       ('ProductTemplatesModule', 'radio');
            $this->createTextCustomFieldByModule                ('ProductTemplatesModule', 'text');
            $this->createTextAreaCustomFieldByModule            ('ProductTemplatesModule', 'textarea');
            $this->createUrlCustomFieldByModule                 ('ProductTemplatesModule', 'url');
        }

        /**
         * @depends testSuperUserCustomFieldsWalkthroughForProductTemplatesModule
         */
        public function testSuperUserAddCustomFieldsToLayoutsForProductTemplatesModule()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');

            //Add custom fields to ProductEditAndDetailsView.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplateEditAndDetailsView'));
            $layout = ProductTemplatesDesignerWalkthroughHelperUtil::getProductTemplateEditAndDetailsViewLayoutWithAllCustomFieldsPlaced();
            $this->setPostArray(array('save'  => 'Save', 'layout' => $layout,
                                      'LayoutPanelsTypeForm' => array('type' => FormLayout::PANELS_DISPLAY_TYPE_ALL)));
            $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/LayoutEdit');
            $this->assertFalse(strpos($content, 'Layout saved successfully') === false);

            //Add all fields to ProductTemplatesSearchView.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplatesSearchView'));
            $layout = ProductTemplatesDesignerWalkthroughHelperUtil::getProductTemplatesSearchViewLayoutWithAllCustomFieldsPlaced();
            $this->setPostArray(array('save'  => 'Save', 'layout' => $layout));
            $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/LayoutEdit');
            $this->assertFalse(strpos($content, 'Layout saved successfully') === false);

            //Add all fields to ProductTemplatesListView.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplatesListView'));
            $layout = ProductTemplatesDesignerWalkthroughHelperUtil::getProductTemplatesListViewLayoutWithAllStandardAndCustomFieldsPlaced();
            $this->setPostArray(array('save'  => 'Save', 'layout' => $layout));
            $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/LayoutEdit');
            $this->assertFalse(strpos($content, 'Layout saved successfully') === false);

        }

        /**
         * @depends testSuperUserAddCustomFieldsToLayoutsForProductTemplatesModule
         */
        public function testLayoutsLoadOkAfterCustomFieldsPlacedForProductTemplatesModule()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
            $superProductTemplateId = self::getModelIdByModelNameAndName ('ProductTemplate', 'superProductTemplate');
            //Load create, edit, and details views.
            $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/create');
            $this->setGetArray(array('id' => $superProductTemplateId));
            $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/edit');
            $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/details');
            $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/list');
        }

        /**
         * @depends testLayoutsLoadOkAfterCustomFieldsPlacedForProductTemplatesModule
         */
        public function testCreateAProductTemplateAfterTheCustomFieldsArePlacedForProductTemplatesModule()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');

            //Set the date and datetime variable values here.
            $date           = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateFormat(), time());
            $dateAssert     = date('Y-m-d');
            $datetime       = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateTimeFormat(), time());
            $datetimeAssert = date('Y-m-d H:i:')."00";
            $baseCurrency   = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());

            //Create a new product based on the custom fields.
            $this->resetGetArray();
            $this->setPostArray(array('ProductTemplate' => array(
                            'name'                              => 'myNewProductTemplate',
                            'type'                              => ProductTemplate::TYPE_PRODUCT,
                            'description'                       => 'Test Description',
                            'sellPrice'                         => array ('currency' => array ('id' => $baseCurrency->id), 'value' => 200),
                            'cost'                              => array ('currency' => array ('id' => $baseCurrency->id), 'value' => 200),
                            'listPrice'                         => array ('currency' => array ('id' => $baseCurrency->id), 'value' => 200),
                            'priceFrequency'                    => 2,
                            'status'                            => ProductTemplate::STATUS_ACTIVE,
                            'sellPriceFormula'                  => array ( 'type' => SellPriceFormula::TYPE_EDITABLE ),
                            'checkboxCstm'                      => '1',
                            'currencyCstm'                      => array('value'    => 45,
                                                                         'currency' => array('id' => $baseCurrency->id)),
                            'dateCstm'                          => $date,
                            'datetimeCstm'                      => $datetime,
                            'decimalCstm'                       => '123',
                            'picklistCstm'                      => array('value' => 'a'),
                            'multiselectCstm'                   => array('values' => array('ff', 'rr')),
                            'tagcloudCstm'                      => array('values' => array('writing', 'gardening')),
                            'countrylistCstm'                   => array('value'  => 'bbbb'),
                            'statelistCstm'                     => array('value'  => 'bbb1'),
                            'citylistCstm'                      => array('value'  => 'bb1'),
                            'integerCstm'                       => '12',
                            'phoneCstm'                         => '259-784-2169',
                            'radioCstm'                         => array('value' => 'd'),
                            'textCstm'                          => 'This is a test Text',
                            'textareaCstm'                      => 'This is a test TextArea',
                            'urlCstm'                           => 'http://wwww.abc.com'
                            )));
            $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/default/create');

            //Check the details if they are saved properly for the custom fields.
            $productTemplateId = self::getModelIdByModelNameAndName('ProductTemplate', 'myNewProductTemplate');
            $productTemplate   = ProductTemplate::getById($productTemplateId);

            $this->assertEquals($productTemplate->name                       , 'myNewProductTemplate');
            $this->assertEquals($productTemplate->sellPrice->value           , 200.00);
            $this->assertEquals($productTemplate->cost->value                , 200.00);
            $this->assertEquals($productTemplate->listPrice->value           , 200.00);
            $this->assertEquals($productTemplate->description                , 'Test Description');
            $this->assertEquals($productTemplate->type                       , ProductTemplate::TYPE_PRODUCT);
            $this->assertEquals($productTemplate->status                     , ProductTemplate::STATUS_ACTIVE);
            $this->assertEquals($productTemplate->priceFrequency             , 2);
            $this->assertEquals($productTemplate->sellPriceFormula->type     , SellPriceFormula::TYPE_EDITABLE);
            $this->assertEquals($productTemplate->checkboxCstm               , '1');
            $this->assertEquals($productTemplate->currencyCstm->value        , 45);
            $this->assertEquals($productTemplate->currencyCstm->currency->id , $baseCurrency->id);
            $this->assertEquals($productTemplate->dateCstm                   , $dateAssert);
            $this->assertEquals($productTemplate->datetimeCstm               , $datetimeAssert);
            $this->assertEquals($productTemplate->decimalCstm                , '123');
            $this->assertEquals($productTemplate->picklistCstm->value        , 'a');
            $this->assertEquals($productTemplate->integerCstm                , 12);
            $this->assertEquals($productTemplate->phoneCstm                  , '259-784-2169');
            $this->assertEquals($productTemplate->radioCstm->value           , 'd');
            $this->assertEquals($productTemplate->textCstm                   , 'This is a test Text');
            $this->assertEquals($productTemplate->textareaCstm               , 'This is a test TextArea');
            $this->assertEquals($productTemplate->urlCstm                    , 'http://wwww.abc.com');
            $this->assertEquals($productTemplate->countrylistCstm->value     , 'bbbb');
            $this->assertEquals($productTemplate->statelistCstm->value       , 'bbb1');
            $this->assertEquals($productTemplate->citylistCstm->value        , 'bb1');
            $this->assertContains('ff'                                       , $productTemplate->multiselectCstm->values);
            $this->assertContains('rr'                                       , $productTemplate->multiselectCstm->values);
            $this->assertContains('writing'                                  , $productTemplate->tagcloudCstm->values);
            $this->assertContains('gardening'                                , $productTemplate->tagcloudCstm->values);
            $metadata            = CalculatedDerivedAttributeMetadata::
                                   getByNameAndModelClassName('calcnumber', 'ProductTemplate');
            $testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $productTemplate);
            $this->assertEquals(1476                                     , intval(str_replace(',',"", $testCalculatedValue)));
        }

        /**
         * @depends testCreateAProductTemplateAfterTheCustomFieldsArePlacedForProductTemplatesModule
         */
        public function testWhetherSearchWorksForTheCustomFieldsPlacedForProductTemplatesModuleAfterCreatingTheProductTemplate()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');

            //Search a created opportunity using the customfield.
            $this->resetPostArray();
            $this->setGetArray(array('ProductTemplatesSearchForm' => array(
                                                'name'                      => 'myNewProductTemplate',<commit_msg>Fix bug<commit_after><?php
    /*********************************************************************************
     * Zurmo is a customer relationship management program developed by
     * Zurmo, Inc. Copyright (C) 2013 Zurmo Inc.
     *
     * Zurmo is free software; you can redistribute it and/or modify it under
     * the terms of the GNU General Public License version 3 as published by the
     * Free Software Foundation with the addition of the following permission added
     * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
     * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
     * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
     *
     * Zurmo is distributed in the hope that it will be useful, but WITHOUT
     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
     * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
     * details.
     *
     * You should have received a copy of the GNU General Public License along with
     * this program; if not, see http://www.gnu.org/licenses or write to the Free
     * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
     * 02110-1301 USA.
     *
     * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
     * Suite 370 Chicago, IL 60606. or at email address <EMAIL>.
     *
     * The interactive user interfaces in original and modified versions
     * of this program must display Appropriate Legal Notices, as required under
     * Section 5 of the GNU General Public License version 3.
     *
     * In accordance with Section 7(b) of the GNU General Public License version 3,
     * these Appropriate Legal Notices must retain the display of the Zurmo
     * logo and Zurmo copyright notice. If the display of the logo is not reasonably
     * feasible for technical reasons, the Appropriate Legal Notices must display the words
     * "Copyright Zurmo Inc. 2013. All rights reserved".
     ********************************************************************************/

    /**
    * Designer Module Walkthrough of productTemplates.
    * Walkthrough for the super user of all possible controller actions.
    * Since this is a super user, he should have access to all controller actions
    * without any exceptions being thrown.
    * This also test the creation of the customfileds, addition of custom fields to all the layouts including the search
    * views.
    * This also test creation search, edit and delete of the ProductTemplate based on the custom fields.
    */
    class ProductTemplatesDesignerSuperUserWalkthroughTest extends ZurmoWalkthroughBaseTest
    {
        public static $activateDefaultLanguages = true;

        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);
        }

         public function testSuperUserProductTemplateDefaultControllerActions()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');

            //Default Controller actions requiring some sort of parameter via POST or GET
            //Load Product Modules Menu.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/modulesMenu');

            //Load AttributesList for ProductTemplate module.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/attributesList');

            //Load ModuleLayoutsList for ProductTemplate module.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/moduleLayoutsList');

            //Now confirm everything did in fact save correctly.
            $this->assertEquals('Catalog Item',  ProductTemplatesModule::getModuleLabelByTypeAndLanguage('Singular'));
            $this->assertEquals('Catalog Items', ProductTemplatesModule::getModuleLabelByTypeAndLanguage('Plural'));
            $this->assertEquals('catalog item',  ProductTemplatesModule::getModuleLabelByTypeAndLanguage('SingularLowerCase'));
            $this->assertEquals('catalog items', ProductTemplatesModule::getModuleLabelByTypeAndLanguage('PluralLowerCase'));

            //Load LayoutEdit for each applicable module and applicable layout
            $this->resetPostArray();
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplatesListView'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplatesModalListView'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplatesModalSearchView'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplateEditAndDetailsView'));
            $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
        }

        /**
         * @depends testSuperUserProductTemplateDefaultControllerActions
         */
        public function testSuperUserCustomFieldsWalkthroughForProductTemplatesModule()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');

            //Test create field list.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule'));

            //View creation screen, then create custom field for each custom field type.
            $this->createCheckBoxCustomFieldByModule            ('ProductTemplatesModule', 'checkbox');
            $this->createCurrencyValueCustomFieldByModule       ('ProductTemplatesModule', 'currency');
            $this->createDateCustomFieldByModule                ('ProductTemplatesModule', 'date');
            $this->createDateTimeCustomFieldByModule            ('ProductTemplatesModule', 'datetime');
            $this->createDecimalCustomFieldByModule             ('ProductTemplatesModule', 'decimal');
            $this->createDropDownCustomFieldByModule            ('ProductTemplatesModule', 'picklist');
            $this->createDependentDropDownCustomFieldByModule   ('ProductTemplatesModule', 'countrylist');
            $this->createDependentDropDownCustomFieldByModule   ('ProductTemplatesModule', 'statelist');
            $this->createDependentDropDownCustomFieldByModule   ('ProductTemplatesModule', 'citylist');
            $this->createIntegerCustomFieldByModule             ('ProductTemplatesModule', 'integer');
            $this->createMultiSelectDropDownCustomFieldByModule ('ProductTemplatesModule', 'multiselect');
            $this->createTagCloudCustomFieldByModule            ('ProductTemplatesModule', 'tagcloud');
            $this->createCalculatedNumberCustomFieldByModule    ('ProductTemplatesModule', 'calcnumber');
            $this->createDropDownDependencyCustomFieldByModule  ('ProductTemplatesModule', 'dropdowndep');
            $this->createPhoneCustomFieldByModule               ('ProductTemplatesModule', 'phone');
            $this->createRadioDropDownCustomFieldByModule       ('ProductTemplatesModule', 'radio');
            $this->createTextCustomFieldByModule                ('ProductTemplatesModule', 'text');
            $this->createTextAreaCustomFieldByModule            ('ProductTemplatesModule', 'textarea');
            $this->createUrlCustomFieldByModule                 ('ProductTemplatesModule', 'url');
        }

        /**
         * @depends testSuperUserCustomFieldsWalkthroughForProductTemplatesModule
         */
        public function testSuperUserAddCustomFieldsToLayoutsForProductTemplatesModule()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');

            //Add custom fields to ProductEditAndDetailsView.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplateEditAndDetailsView'));
            $layout = ProductTemplatesDesignerWalkthroughHelperUtil::getProductTemplateEditAndDetailsViewLayoutWithAllCustomFieldsPlaced();
            $this->setPostArray(array('save'  => 'Save', 'layout' => $layout,
                                      'LayoutPanelsTypeForm' => array('type' => FormLayout::PANELS_DISPLAY_TYPE_ALL)));
            $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/LayoutEdit');
            $this->assertFalse(strpos($content, 'Layout saved successfully') === false);

            //Add all fields to ProductTemplatesSearchView.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplatesSearchView'));
            $layout = ProductTemplatesDesignerWalkthroughHelperUtil::getProductTemplatesSearchViewLayoutWithAllCustomFieldsPlaced();
            $this->setPostArray(array('save'  => 'Save', 'layout' => $layout));
            $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/LayoutEdit');
            $this->assertFalse(strpos($content, 'Layout saved successfully') === false);

            //Add all fields to ProductTemplatesListView.
            $this->setGetArray(array('moduleClassName' => 'ProductTemplatesModule',
                                     'viewClassName'   => 'ProductTemplatesListView'));
            $layout = ProductTemplatesDesignerWalkthroughHelperUtil::getProductTemplatesListViewLayoutWithAllStandardAndCustomFieldsPlaced();
            $this->setPostArray(array('save'  => 'Save', 'layout' => $layout));
            $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/LayoutEdit');
            $this->assertFalse(strpos($content, 'Layout saved successfully') === false);

        }

        /**
         * @depends testSuperUserAddCustomFieldsToLayoutsForProductTemplatesModule
         */
        public function testLayoutsLoadOkAfterCustomFieldsPlacedForProductTemplatesModule()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
            $superProductTemplateId = self::getModelIdByModelNameAndName ('ProductTemplate', 'superProductTemplate');
            //Load create, edit, and details views.
            $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/create');
            $this->setGetArray(array('id' => $superProductTemplateId));
            $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/edit');
            $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/details');
            $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/list');
        }

        /**
         * @depends testLayoutsLoadOkAfterCustomFieldsPlacedForProductTemplatesModule
         */
        public function testCreateAProductTemplateAfterTheCustomFieldsArePlacedForProductTemplatesModule()
        {
            $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');

            //Set the date and datetime variable values here.
            $date           = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateFormat(), time());
            $dateAssert     = date('Y-m-d');
            $datetime       = Yii::app()->dateFormatter->format(DateTimeUtil::getLocaleDateTimeFormat(), time());
            $datetimeAssert = date('Y-m-d H:i:')."00";
            $baseCurrency   = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());

            //Create a new product based on the custom fields.
            $this->resetGetArray();
            $this->setPostArray(array('ProductTemplate' => array(
                            'name'                              => 'myNewProductTemplate',
                            'type'                              => ProductTemplate::TYPE_PRODUCT,
                            'description'                       => 'Test Description',
                            'sellPrice'                         => array ('currency' => array ('id' => $baseCurrency->id), 'value' => 200),
                            'cost'                              => array ('currency' => array ('id' => $baseCurrency->id), 'value' => 200),
                            'listPrice'                         => array ('currency' => array ('id' => $baseCurrency->id), 'value' => 200),
                            'priceFrequency'                    => 2,
                            'status'                            => ProductTemplate::STATUS_ACTIVE,
                            'sellPriceFormula'                  => array ( 'type' => SellPriceFormula::TYPE_EDITABLE ),
                            'checkboxCstm'                      => '1',
                            'currencyCstm'                      => array('value'    => 45,
                                                                         'currency' => array('id' => $baseCurrency->id)),
                            'dateCstm'                          => $date,
                            'datetimeCstm'                      => $datetime,
                            'decimalCstm'                       => '123',
                            'picklistCstm'                      => array('value' => 'a'),
                            'multiselectCstm'                   => array('values' => array('ff', 'rr')),
                            'tagcloudCstm'                      => array('values' => array('writing', 'gardening')),
                            'countrylistCstm'                   => array('value'  => 'bbbb'),
                            'statelistCstm'                     => array('value'  => 'bbb1'),
                            'citylistCstm'                      => array('value'  => 'bb1'),
                            'integerCstm'                       => '12',
                            'phoneCstm'                         => '259-784-2169',
                            'radioCstm'                         => array('value' => 'd'),
                            'textCstm'                          => 'This is a test Text',
                            'textareaCstm'                      => 'This is a test TextArea',
                            'urlCstm'                           => 'http://wwww.abc.com'
                            )));
            $this->runControllerWithRedirectExceptionAndGetUrl('productTemplates/default/create');

            //Check the details if they are saved properly for the custom fields.
            $productTemplateId = self::getModelIdByModelNameAndName('ProductTemplate', 'myNewProductTemplate');
            $productTemplate   = ProductTemplate::getById($productTemplateId);

            $this->assertEquals($productTemplate->name                       , 'myNewProductTemplate');
            $this->assertEquals($productTemplate->sellPrice->value           , 200.00);
            $this->assertEquals($productTemplate->cost->value                , 200.00);
            $this->assertEquals($productTemplate->listPrice->value           , 200.00);
            $this->assertEquals($productTemplate->description                , 'Test Description');
            $this->assertEquals($productTemplate->type                       , ProductTemplate::TYPE_PRODUCT);
            $this->assertEquals($productTemplate->status                     , ProductTemplate::STATUS_ACTIVE);
            $this->assertEquals($productTemplate->priceFrequency             , 2);
            $this->assertEquals($productTemplate->sellPriceFormula->type     , SellPriceFormula::TYPE_EDITABLE);
            $this->assertEquals($productTemplate->checkboxCstm               , '1');
            $this->assertEquals($productTemplate->currencyCstm->value        , 45);
            $this->assertEquals($productTemplate->currencyCstm->currency->id , $baseCurrency->id);
            $this->assertEquals($productTemplate->dateCstm                   , $dateAssert);
            $this->assertEquals($productTemplate->datetimeCstm               , $datetimeAssert);
            $this->assertEquals($productTemplate->decimalCstm                , '123');
            $this->assertEquals($productTemplate->picklistCstm->value        , 'a');
            $this->assertEquals($productTemplate->integerCstm                , 12);
            $this->assertEquals($productTemplate->phoneCstm                  , '259-784-2169');
            $this->assertEquals($productTemplate->radioCstm->value           , 'd');
            $this->assertEquals($productTemplate->textCstm                   , 'This is a test Text');
            $this->assertEquals($productTemplate->textareaCstm               , 'This is a test TextArea');
            $this->assertEquals($productTemplate->urlCstm                    , 'http://wwww.abc.com');
            $this->assertEquals($productTemplate->countrylistCstm->value     , 'bbbb');
            $this->assertEquals($productTemplate->statelistCstm->value       , 'bbb1');
            $this->assertEquals($productTemplate->citylistCstm->value        , 'bb1');
            $this->assertContains('ff'                                       , $productTemplate->multiselectCstm->values);
            $this->assertContains('rr'                                       , $productTemplate->multiselectCstm->values);
            $this->assertContains('writing'                                  , $productTemplate->tagcloudCstm->values);
            $this->assertContains('gardening'                                , $productTemplate->tagcloudCstm->values);
            $metadata            = CalculatedDerivedAttributeMetadata::
                                   getByNameAndModelClassName('calcnumber', 'ProductTemplate');
            $testCalculatedValue = CalculatedNumberUtil::calculateByFormulaAndModelAndResolveFormat($metadata->getFormula(), $productTemplate);
            $this->assertEquals(1476                                     , intval(str_replace(',',"", $testCalculatedValue)));
        }

        /**
         * @depends testCreateAProductTemplateAfterTheCustomFieldsArePlacedForProductTemplatesModule
         */
        public function testWhetherSearchWorksForTheCustomFieldsPlacedForProductTemplatesModuleAfterCreatingTheProductTemplate()
        {
            $super              = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
            $baseCurrency       = Currency::getByCode(Yii::app()->currencyHelper->getBaseCode());
            //Search a created opportunity using the customfield.
            $this->resetPostArray();
            $this->setGetArray(array('ProductTemplatesSearchForm' => array(
                                                'name'                      => 'myNewProductTemplate',
{'fraction_non_alphanumeric': 0.11053325891724593, 'fraction_numerical': 0.005530468313968238, 'mean_word_length': 2.242494036357654, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 471, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 48, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5837639', 'n_tokens_mistral': 9198, 'n_tokens_neox': 8833, 'n_words': 1780}