/**
  *  Convert data array into entity
  *
  *  @return VoucherGroup
  *  @param array $data
  *  @access public
  */
 public function build($data)
 {
     $oEntity = new VoucherGenRule();
     $sAlias = $this->getTableQueryAlias();
     $iVoucherGenId = $this->getField($data, 'voucher_gen_rule_id', $sAlias);
     $sVoucherRuleNameSlug = $this->getField($data, 'voucher_rule_slug', $sAlias);
     $sVoucherRuleName = $this->getField($data, 'voucher_rule_name', $sAlias);
     $sVoucherPaddingCharacter = $this->getField($data, 'voucher_padding_char', $sAlias);
     $sVoucherSuffix = $this->getField($data, 'voucher_suffix', $sAlias);
     $sVoucherPrefix = $this->getField($data, 'voucher_prefix', $sAlias);
     $iVoucherLength = $this->getField($data, 'voucher_length', $sAlias);
     $oDateCreated = $this->getField($data, 'date_created', $sAlias);
     $sSequenceStrategy = $this->getField($data, 'voucher_sequence_strategy', $sAlias);
     $oEntity->setVoucherGenRuleId($iVoucherGenId);
     $oEntity->setSlugRuleName($sVoucherRuleNameSlug);
     $oEntity->setVoucherRuleName($sVoucherRuleName);
     $oEntity->setVoucherPaddingCharacter($sVoucherPaddingCharacter);
     $oEntity->setVoucherSuffix($sVoucherSuffix);
     $oEntity->setVoucherPrefix($sVoucherPrefix);
     $oEntity->setVoucherLength($iVoucherLength);
     $oEntity->setDateCreated($oDateCreated);
     $oEntity->setSequenceStrategyName($sSequenceStrategy);
     return $oEntity;
 }
 public function testVoucherEntityFailure()
 {
     $oRule = new VoucherGenRule();
     $iVoucherGeneratorRuleId = 1;
     $sVoucherRuleNameSlug = '';
     $sVoucherRuleName = '';
     $sVoucherPaddingCharacter = 'A';
     $sVoucherSuffix = str_repeat('a', 100);
     $sVoucherPrefix = str_repeat('a', 100);
     $iVoucherLength = 101;
     $oDateCreated = new DateTime();
     $sSequenceStrategy = 'BAD';
     $oRule->setVoucherGenRuleId($iVoucherGeneratorRuleId);
     $oRule->setSlugRuleName($sVoucherRuleNameSlug);
     $oRule->setVoucherRuleName($sVoucherRuleName);
     $oRule->setVoucherPaddingCharacter($sVoucherPaddingCharacter);
     $oRule->setVoucherSuffix($sVoucherSuffix);
     $oRule->setVoucherPrefix($sVoucherPrefix);
     $oRule->setVoucherLength($iVoucherLength);
     $oRule->setDateCreated($oDateCreated);
     $oRule->setSequenceStrategyName($sSequenceStrategy);
     $oResults = $oRule->validate();
     $this->assertInternalType('array', $oResults);
     $this->assertEquals(count($oResults['voucherSuffix']), 1);
     $this->assertEquals(count($oResults['voucherPrefix']), 1);
     $this->assertEquals(count($oResults['sequenceStrategy']), 1);
     $this->assertEquals(count($oResults['voucherRuleName']), 1);
     $this->assertEquals(count($oResults['slugName']), 3);
     $this->assertEquals(count($oResults['voucherLength']), 1);
 }
 public function testVoucherRuleUpdate()
 {
     $oContainer = $this->getContainer();
     $aOperations = $oContainer->getVoucherRuleOperations();
     $oOperation = $aOperations['update'];
     # assert correct operation was returned
     $this->assertInstanceOf('\\IComeFromTheNet\\Ledger\\Voucher\\Operations\\RuleRevise', $oOperation);
     $oRule = new VoucherGenRule();
     $oRule->setVoucherRuleName('Rule A');
     $oRule->setSlugRuleName('rule_a');
     $oRule->setVoucherPaddingCharacter('a');
     $oRule->setVoucherSuffix('_rule');
     $oRule->setVoucherPrefix('my_');
     $oRule->setVoucherLength(5);
     $oRule->setSequenceStrategyName('SEQUENCE');
     $oRule->setVoucherGenRuleId(1);
     $oOperation->execute($oRule);
     $this->assertNotEmpty($oRule->getVoucherGenRuleId());
 }