Ejemplo n.º 1
0
 /**
  * @param string $itemType
  * @param string $itemEvent
  * @param array $itemIds
  *
  * @return int
  */
 protected function insertChunk($itemType, $itemEvent, array $itemIds)
 {
     $propelCollection = new ObjectCollection();
     $propelCollection->setModel(SpyTouch::class);
     foreach ($itemIds as $itemId) {
         $touchEntity = new SpyTouch();
         $touchEntity->setItemEvent($itemEvent)->setItemId($itemId)->setItemType($itemType)->setTouched(new \DateTime());
         $propelCollection->append($touchEntity);
     }
     $propelCollection->save();
     return $propelCollection->count();
 }
Ejemplo n.º 2
0
 public function testIssue1133OffsetSet()
 {
     $testCollection = new ObjectCollection();
     $testCollection->setModel(DummyObject::class);
     for ($i = 0; $i < 3; $i++) {
         $testCollection->append(new DummyObject($i));
     }
     $firstToRemove = $testCollection[0];
     $objectThatShouldNotBeRemoved = $testCollection[2];
     // breaks index numbering
     $testCollection->removeObject($firstToRemove);
     $objectThatWillBeRemoved = new DummyObject(3);
     // calls offsetSet
     $testCollection[] = $objectThatWillBeRemoved;
     $testCollection->removeObject($objectThatWillBeRemoved);
     $this->assertContains($objectThatShouldNotBeRemoved, $testCollection, 'ObjectCollection does not contain item that should be in collection.');
     $this->assertNotContains($objectThatWillBeRemoved, $testCollection, 'ObjectCollection contains item that should be removed.');
 }
Ejemplo n.º 3
0
 public function testSerializeUnserialize()
 {
     $collection = new ObjectCollection();
     $collection->setModel('Propel\\Bundle\\PropelBundle\\Model\\Acl\\Entry');
     $entry = $this->createEntry();
     $entry->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity('ROLE_ADMIN')))->setAclClass($this->getAclClass());
     $collection->append($entry);
     $acl = new MutableAcl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
     $serialized = serialize($acl);
     $unserialized = unserialize($serialized);
     $this->assertNotEmpty($serialized);
     $this->assertNotEmpty($unserialized);
     $this->assertInstanceOf('Propel\\Bundle\\PropelBundle\\Security\\Acl\\Domain\\MutableAcl', $unserialized);
     $this->assertEquals($serialized, serialize($unserialized));
 }
Ejemplo n.º 4
0
 /**
  * @depends testUpdateObjectAuditing
  */
 public function testUpdateClassFieldAuditing()
 {
     $collection = new ObjectCollection();
     $collection->setModel('Propel\\Bundle\\PropelBundle\\Model\\Acl\\Entry');
     $entry = $this->createEntry();
     $entry->setFieldName('name')->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity()))->setAclClass($this->getAclClass());
     $collection->append($entry);
     $acl = new AuditableAcl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy());
     $aces = $acl->getClassFieldAces('name');
     $this->assertCount(1, $aces);
     $acl->updateClassFieldAuditing(0, 'name', true, true);
     $aces = $acl->getClassFieldAces('name');
     $this->assertTrue($aces[0]->isAuditSuccess());
     $this->assertTrue($aces[0]->isAuditFailure());
     $acl->updateClassFieldAuditing(0, 'name', false, false);
     $aces = $acl->getClassFieldAces('name');
     $this->assertFalse($aces[0]->isAuditSuccess());
     $this->assertFalse($aces[0]->isAuditFailure());
 }
Ejemplo n.º 5
0
 public function testGetUntaxedPriceAndGetTaxAmountFromTaxedPrice()
 {
     $taxRulesCollection = new ObjectCollection();
     $taxRulesCollection->setModel('\\Thelia\\Model\\Tax');
     $tax = new Tax();
     $tax->setType('\\Thelia\\TaxEngine\\TaxType\\PricePercentTaxType')->setRequirements(array('percent' => 10))->setVirtualColumn('taxRuleCountryPosition', 1);
     $taxRulesCollection->append($tax);
     $tax = new Tax();
     $tax->setType('\\Thelia\\TaxEngine\\TaxType\\PricePercentTaxType')->setRequirements(array('percent' => 8))->setVirtualColumn('taxRuleCountryPosition', 1);
     $taxRulesCollection->append($tax);
     $tax = new Tax();
     $tax->setType('\\Thelia\\TaxEngine\\TaxType\\FixAmountTaxType')->setRequirements(array('amount' => 5))->setVirtualColumn('taxRuleCountryPosition', 2);
     $taxRulesCollection->append($tax);
     $tax = new Tax();
     $tax->setType('\\Thelia\\TaxEngine\\TaxType\\PricePercentTaxType')->setRequirements(array('percent' => 1))->setVirtualColumn('taxRuleCountryPosition', 3);
     $taxRulesCollection->append($tax);
     $aProduct = ProductQuery::create()->findOne();
     if (null === $aProduct) {
         return;
     }
     $calculator = new Calculator();
     $rewritingUrlQuery = $this->getProperty('taxRulesCollection');
     $rewritingUrlQuery->setValue($calculator, $taxRulesCollection);
     $product = $this->getProperty('product');
     $product->setValue($calculator, $aProduct);
     $taxAmount = $calculator->getTaxAmountFromTaxedPrice(600.95);
     $untaxedPrice = $calculator->getUntaxedPrice(600.95);
     /*
      * expect :
      *  tax 3 = 600.95 - 600.95 / (1 + 0.01) = 5,95 // amount without tax 3 : 595
      *  tax 2 = 5 // amount without tax 2 : 590
      *  tax 1 = 590 - 590 / (1 + 0.08 + 0.10) = 90 // amount without tax 1 : 500
      * total tax amount = 100.95
      */
     $this->assertEquals(100.95, $taxAmount);
     $this->assertEquals(500, $untaxedPrice);
 }
 public static function addProductWhenAjaxChangeActive($arg)
 {
     /* @var $model SProducts */
     $models = $arg['model'];
     /* @var $ci MY_Controller */
     $ci =& get_instance();
     if (!$models instanceof PropelObjectCollection) {
         $model = $models;
         $models = new PropelObjectCollection();
         $models->append($model);
     }
     foreach ($models as $model) {
         if ($model->getActive()) {
             $ci->db->where('trash_url', 'shop/product/' . $model->getUrl())->delete('trash');
         } else {
             $array = array('trash_id' => $model->getCategoryId(), 'trash_url' => 'shop/product/' . $model->getUrl(), 'trash_redirect_type' => 'category', 'trash_type' => '302', 'trash_redirect' => shop_url('category/' . $model->getMainCategory()->getFullPath()));
             $ci->db->insert('trash', $array);
         }
     }
 }
Ejemplo n.º 7
0
 public function testLoad()
 {
     $collection = new ObjectCollection();
     $collection->setModel('\\Thelia\\Model\\RewritingArgument');
     for ($i = 0; $i < 3; $i++) {
         $ra = new RewritingArgument();
         $ra->setParameter('foo' . $i);
         $ra->setValue('bar' . $i);
         $ra->setVirtualColumn('ru_view', 'view');
         $ra->setVirtualColumn('ru_viewId', 'viewId');
         $ra->setVirtualColumn('ru_locale', 'locale');
         $ra->setVirtualColumn('ru_redirected_to_url', null);
         $collection->append($ra);
     }
     $resolverQuery = $this->getMock('\\Thelia\\Model\\RewritingUrlQuery', array('getResolverSearch'));
     $resolverQuery->expects($this->any())->method('getResolverSearch')->with('foo.html')->will($this->returnValue($collection));
     $resolver = new RewritingResolver();
     $rewritingUrlQuery = $this->getProperty('rewritingUrlQuery');
     $rewritingUrlQuery->setValue($resolver, $resolverQuery);
     $resolver->load('foo.html');
     $this->assertEquals('view', $resolver->view);
     $this->assertEquals('viewId', $resolver->viewId);
     $this->assertEquals('locale', $resolver->locale);
     $this->assertEquals(array('foo0' => 'bar0', 'foo1' => 'bar1', 'foo2' => 'bar2'), $resolver->otherParameters);
 }