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); }
public function testWithPaginate() { QuerycacheTable1Query::create()->deleteAll(); $coll = new ObjectCollection(); $coll->setModel('\\Propel\\Tests\\Bookstore\\Behavior\\QuerycacheTable1'); for ($i = 0; $i < 5; $i++) { $b = new QuerycacheTable1(); $b->setTitle('Title' . $i); $coll[] = $b; } $coll->save(); $pager = $this->getPager(2, 1); $this->assertEquals(5, $pager->getNbResults()); $results = $pager->getResults(); $this->assertEquals('query cache with paginate offset 0 limit 2', $pager->getQuery()->getQueryKey()); $this->assertEquals(2, count($results)); $this->assertEquals('Title1', $results[1]->getTitle()); //jump to page 3 $pager = $this->getPager(2, 3); $this->assertEquals(5, $pager->getNbResults()); $results = $pager->getResults(); $this->assertEquals('query cache with paginate offset 4 limit 2', $pager->getQuery()->getQueryKey()); $this->assertEquals(1, count($results)); $this->assertEquals('Title4', $results[0]->getTitle()); }
protected function createBooks($nb = 15, $con = null) { BookQuery::create()->deleteAll($con); $books = new ObjectCollection(); $books->setModel('\\Propel\\Tests\\Bookstore\\Book'); for ($i = 0; $i < $nb; $i++) { $b = new Book(); $b->setTitle('Book' . $i); $books[] = $b; } $books->save($con); }
/** * @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(); }
public function testFromArray() { $author = new Author(); $author->setFirstName('Jane'); $author->setLastName('Austen'); $author->save(); $books = array(array('Title' => 'Mansfield Park', 'ISBN' => 'FA404', 'AuthorId' => $author->getId()), array('Title' => 'Pride And Prejudice', 'ISBN' => 'FA404', 'AuthorId' => $author->getId())); $col = new ObjectCollection(); $col->setModel('Propel\\Tests\\Bookstore\\Book'); $col->fromArray($books); $col->save(); $nbBooks = PropelQuery::from('Propel\\Tests\\Bookstore\\Book')->count(); $this->assertEquals(6, $nbBooks); $booksByJane = PropelQuery::from('Propel\\Tests\\Bookstore\\Book b')->join('b.Author a')->where('a.LastName = ?', 'Austen')->count(); $this->assertEquals(2, $booksByJane); }
public function save($key = null) { if ($key === null) { $data = []; foreach (array_keys($this->preferences) as $key) { $data[] = $this->getPreference($key); } $collection = new ObjectCollection($data); $collection->setModel(PreferenceTableMap::CLASS_NAME); $collection->save(); } else { if ($this->has($key)) { $p = $this->getPreference($key); $p->save(); } } }
public function testConstruct() { $collection = new ObjectCollection(); $collection->setModel('Propel\\Bundle\\PropelBundle\\Model\\Acl\\Entry'); $acl = new Acl($collection, $this->getAclObjectIdentity(), new PermissionGrantingStrategy()); $model = $this->createEntry(); $model->setAuditFailure(true); $model->setSecurityIdentity(SecurityIdentity::fromAclIdentity($this->getRoleSecurityIdentity())); $entry = new Entry($model, $acl); $this->assertEquals($model->getMask(), $entry->getMask()); $this->assertEquals($model->getGranting(), $entry->isGranting()); $this->assertEquals($model->getGrantingStrategy(), $entry->getStrategy()); $this->assertEquals($model->getAuditFailure(), $entry->isAuditFailure()); $this->assertEquals($model->getAuditSuccess(), $entry->isAuditSuccess()); $this->assertEquals($this->getRoleSecurityIdentity(), $entry->getSecurityIdentity()); return $entry; }
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.'); }
protected function populateCreatedAt() { Table2Query::create()->deleteAll(); $ts = new ObjectCollection(); $ts->setModel('\\Propel\\Tests\\Bookstore\\Behavior\\Table2'); for ($i = 0; $i < 10; $i++) { $t = new Table2(); $t->setTitle('CreatedAt' . $i); $t->setCreatedAt(time() - $i * 24 * 60 * 60 - 30); $ts[] = $t; } $ts->save(); }
/** * Basic deletion of a 1-to-n relation through set<RelationName>(). * */ public function testContentsDeletion() { $contentCollection = new ObjectCollection(); $contentCollection->setModel('MoreRelationTest\\Content'); $content = new \MoreRelationTest\Content(); $content->setTitle('I should be alone :-('); $contentCollection[] = $content; $page = \MoreRelationTest\PageQuery::create()->findOne(); $id = $page->getId(); $count = \MoreRelationTest\ContentQuery::create()->filterByPageId($id)->count(); $this->assertEquals(3, $count, 'We created for each page 3 contents.'); $page->setContents($contentCollection); $page->save(); unset($page); $count = \MoreRelationTest\ContentQuery::create()->filterByPageId($id)->count(); $this->assertEquals(1, $count, 'We assigned a collection of only one item.'); }
public function testToArrayDeep() { $author = new Author(); $author->setId(5678); $author->setFirstName('George'); $author->setLastName('Byron'); $book = new Book(); $book->setId(9012); $book->setTitle('Don Juan'); $book->setISBN('0140422161'); $book->setPrice(12.99); $book->setAuthor($author); $coll = new ObjectCollection(); $coll->setModel('\\Propel\\Tests\\Bookstore\\Book'); $coll[] = $book; $expected = array(array('Id' => 9012, 'Title' => 'Don Juan', 'ISBN' => '0140422161', 'Price' => 12.99, 'PublisherId' => null, 'AuthorId' => 5678, 'Author' => array('Id' => 5678, 'FirstName' => 'George', 'LastName' => 'Byron', 'Email' => null, 'Age' => null, 'Books' => array('Book_0' => '*RECURSION*')))); $this->assertEquals($expected, $coll->toArray()); }
public function testToStringUsesCustomStringFormat() { $coll = new ObjectCollection(); $coll->setModel('\\Propel\\Tests\\Bookstore\\Publisher'); $publisher = new Publisher(); $publisher->setId(12345); $publisher->setName('Penguinoo'); $coll[] = $publisher; $expected = <<<EOF <?xml version="1.0" encoding="UTF-8"?> <Publishers> <Publisher> <Id>12345</Id> <Name><![CDATA[Penguinoo]]></Name> </Publisher> </Publishers> EOF; $this->assertEquals($expected, (string) $coll); }
/** * Makes an additional query to populate the objects related to the collection objects * by a certain relation * * @param string $relation Relation name (e.g. 'Book') * @param Criteria $criteria Optional Criteria object to filter the related object collection * @param ConnectionInterface $con Optional connection object * * @return ObjectCollection The list of related objects */ public function populateRelation($relation, $criteria = null, $con = null) { if (!Propel::isInstancePoolingEnabled()) { throw new RuntimeException(__METHOD__ . ' needs instance pooling to be enabled prior to populating the collection'); } $relationMap = $this->getFormatter()->getTableMap()->getRelation($relation); if ($this->isEmpty()) { // save a useless query and return an empty collection $coll = new ObjectCollection(); $coll->setModel($relationMap->getRightTable()->getClassName()); return $coll; } $symRelationMap = $relationMap->getSymmetricalRelation(); $query = PropelQuery::from($relationMap->getRightTable()->getClassName()); if (null !== $criteria) { $query->mergeWith($criteria); } // query the db for the related objects $filterMethod = 'filterBy' . $symRelationMap->getName(); $relatedObjects = $query->{$filterMethod}($this)->find($con); if (RelationMap::ONE_TO_MANY === $relationMap->getType()) { // initialize the embedded collections of the main objects $relationName = $relationMap->getName(); foreach ($this as $mainObj) { $mainObj->initRelation($relationName); } // associate the related objects to the main objects $getMethod = 'get' . $symRelationMap->getName(); $addMethod = 'add' . $relationName; foreach ($relatedObjects as $object) { $mainObj = $object->{$getMethod}(); // instance pool is used here to avoid a query $mainObj->{$addMethod}($object); } } elseif (RelationMap::MANY_TO_ONE === $relationMap->getType()) { // nothing to do; the instance pool will catch all calls to getRelatedObject() // and return the object in memory } else { throw new UnsupportedRelationException(__METHOD__ . ' does not support this relation type'); } return $relatedObjects; }
/** * @param $item propel object * @param array $values * @param bool $ignoreNotExistingValues */ public function mapValues(&$item, &$values, $ignoreNotExistingValues = false) { $setted = []; $applyColumn = function ($name) use(&$item, &$values, &$setted, &$ignoreNotExistingValues) { $fieldName = lcfirst($name); $setted[] = $fieldName; $fieldValue = @$values[$fieldName]; if (!isset($values[$fieldName]) && $ignoreNotExistingValues) { return; } $fieldName = ucfirst($fieldName); $set = 'set' . $fieldName; $methodExist = method_exists($item, $set); if ($methodExist) { $item->{$set}($fieldValue); } }; $pluralizer = new StandardEnglishPluralizer(); $self = $this; /** * @param RelationDefinition $relation * * @throws ObjectNotFoundException * @throws \Exception */ $applyRelation = function ($relation) use($self, $pluralizer, &$item, &$values, &$setted, &$ignoreNotExistingValues) { $fieldName = lcfirst($relation->getName()); $fieldValue = isset($values[$fieldName]) ? $values[$fieldName] : null; if (!isset($values[$fieldName]) && $ignoreNotExistingValues) { return; } if ($relation->getType() == AbstractStorage::MANY_TO_MANY || $relation->getType() == AbstractStorage::ONE_TO_MANY) { $name = $pluralizer->getPluralForm($pluralizer->getSingularForm(Tools::underscore2Camelcase($fieldName))); $setItems = 'set' . $name; $clearItems = 'clear' . $name; if (is_array($fieldValue)) { $foreignQuery = $self->getQueryClass($relation->getForeignObjectKey()); $foreignClass = $self->getPhpName($relation->getForeignObjectKey()); $foreignObjClass = $self->objects->getStorageController($relation->getForeignObjectKey()); if ($relation->getType() == AbstractStorage::ONE_TO_MANY) { $coll = new ObjectCollection(); $coll->setModel(ucfirst($foreignClass)); if (!is_array($fieldValue)) { throw new \LogicException(sprintf('Relation `%s` on object %s requires array value, not %s', $relation->getName(), $this->getObjectKey(), gettype($fieldValue))); } foreach ($fieldValue as $foreignItem) { $pk = $self->objects->getObjectPk($relation->getForeignObjectKey(), $foreignItem); $item2 = null; if ($pk) { $propelPk = $self->getPropelPk($pk, $relation->getForeignObjectKey()); $item2 = $foreignQuery->findPk($propelPk); } if (!$item2) { $item2 = new $foreignClass(); } $item2->fromArray($foreignItem, TableMap::TYPE_CAMELNAME); $coll[] = $item2; } $item->{$setItems}($coll); } else { $primaryKeys = array(); if (is_array($fieldValue)) { foreach ($fieldValue as $value) { $primaryKeys[] = $foreignObjClass->normalizePrimaryKey($value); } } $propelPks = array(); foreach ($primaryKeys as $primaryKey) { $propelPks[] = $self->getPropelPk($primaryKey, $relation->getForeignObjectKey()); } $collItems = $foreignQuery->findPks($propelPks); $item->{$setItems}($collItems); } } elseif ($ignoreNotExistingValues) { $item->{$clearItems}(); } } if ($relation->getType() == AbstractStorage::MANY_TO_ONE || $relation->getType() == AbstractStorage::ONE_TO_ONE) { if (!$self->tableMap->hasRelation(ucfirst($fieldName))) { throw new \Exception(sprintf('Relation %s not found in propel object %s (%s)', ucfirst($fieldName), $self->getObjectKey(), $self->getPhpName())); } //try to set the local column of the relation directly, when we get only primary keys $propelRelation = $self->tableMap->getRelation(ucfirst($fieldName)); $localColumns = $propelRelation->getLocalColumns(); $firstColumn = current($localColumns); $hasPrimaryKey = false; if (is_array($fieldValue)) { $foreignColumns = $propelRelation->getForeignColumns(); $firstForeignColumn = current($foreignColumns); $key = lcfirst($firstForeignColumn->getPhpName()); if (isset($fieldValue[$key])) { $fieldValue = $fieldValue[$key]; $hasPrimaryKey = true; } } else { $hasPrimaryKey = true; } if ($hasPrimaryKey) { //set local column of foreign key directly $setter = 'set' . ucfirst($firstColumn->getPhpName()); $item->{$setter}($fieldValue); } else { //we got no primary key, so set values at the object directly $getter = 'get' . ucfirst($relation->getName()); $relatedItem = $item->{$getter}(); if (!$relatedItem) { $class = $propelRelation->getForeignTable()->getClassName(); $relatedItem = new $class(); $setter = 'set' . ucfirst($relation->getName()); $item->{$setter}($relatedItem); } foreach ($fieldValue as $k => $v) { $relatedItem->{'set' . ucfirst($k)}($v); } } } }; foreach ($this->getDefinition()->getFields(true) as $field) { if ($field->isPrimaryKey() && $field->isAutoIncrement()) { continue; } foreach ($field->getFieldType()->getColumns() as $column) { $applyColumn($column->getName()); } } foreach ($this->getDefinition()->getRelations() as $relation) { $applyRelation($relation); } // /* // * all virtual fields which are not present in the object. // * Virtual fields are all methods in the model which have a setter. // * Examples: // * // * setPassword => 'password' // */ // foreach ($values as $fieldName => $fieldValue) { // $fieldName = lcfirst($fieldName); // if (in_array($fieldName, $setted)) { // continue; // } // // $fieldName = ucfirst($fieldName); // $set = 'set' . $fieldName; // $methodExist = method_exists($item, $set); // // if ($methodExist) { // $item->$set($fieldValue); // } // } }
public function testSetterOneToManyWithFkRequired() { // Ensure no data BookSummaryQuery::create()->deleteAll(); BookQuery::create()->deleteAll(); $coll = new ObjectCollection(); $coll->setModel('BookSummary'); for ($i = 0; $i < 3; $i++) { $coll[] = new BookSummary(); } $this->assertEquals(3, $coll->count()); $b = new Book(); $b->setTitle('myBook'); $b->setBookSummaries($coll); $b->save(); $this->assertInstanceOf('Propel\\Runtime\\Collection\\ObjectCollection', $b->getBookSummaries()); $this->assertEquals(3, $b->getBookSummaries()->count()); $this->assertEquals(1, BookQuery::create()->count()); $this->assertEquals(3, BookSummaryQuery::create()->count()); $coll->shift(); $this->assertEquals(2, $coll->count()); $b->setBookSummaries($coll); $b->save(); $this->assertEquals(2, $b->getBookSummaries()->count()); $this->assertEquals(1, BookQuery::create()->count()); $this->assertEquals(2, BookSummaryQuery::create()->count()); $newBookSammary = new BookSummary(); $newBookSammary->setSummary('My sammary'); // Kind of new collection $coll = clone $coll; $coll[] = $newBookSammary; $b->setBookSummaries($coll); $b->save(); $this->assertEquals(3, $coll->count()); $this->assertEquals(3, $b->getBookSummaries()->count()); $this->assertEquals(1, BookQuery::create()->count()); $this->assertEquals(3, BookSummaryQuery::create()->count()); // Add a new object $newBookSammary1 = new BookSummary(); $newBookSammary1->setSummary('My sammary 1'); // Existing collection - The fix around reference is tested here. $coll[] = $newBookSammary1; $b->setBookSummaries($coll); $b->save(); $this->assertEquals(4, $coll->count()); $this->assertEquals(4, $b->getBookSummaries()->count()); $this->assertEquals(1, BookQuery::create()->count()); $this->assertEquals(4, BookSummaryQuery::create()->count()); // Add the same collection $bookSummaries = $b->getBookSummaries(); $b->setBookSummaries($bookSummaries); $b->save(); $this->assertEquals(4, $coll->count()); $this->assertEquals(4, $b->getBookSummaries()->count()); $this->assertEquals(1, BookQuery::create()->count()); $this->assertEquals(4, BookSummaryQuery::create()->count()); }
public function testSetterOneToManyWithNewObjects() { // Ensure no data BookQuery::create()->deleteAll(); AuthorQuery::create()->deleteAll(); $coll = new ObjectCollection(); $coll->setModel('\\Propel\\Tests\\Bookstore\\Book'); $coll[] = new Book(); $coll[] = new Book(); $coll[] = new Book(); $a = new Author(); $a->setBooks($coll); $a->save(); $this->assertEquals(3, $coll->count()); $this->assertEquals(3, count($a->getBooks())); $this->assertSame($coll, $a->getBooks()); $this->assertEquals(1, AuthorQuery::create()->count()); $this->assertEquals(3, BookQuery::create()->count()); }
protected function buildCollection($arr) { $coll = new ObjectCollection(); $coll->setData($arr); $coll->setModel('Table10'); return $coll; }
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); }
/** * Initializes the $collNestedSetChildren collection. * * @return void */ public function initNestedSetChildren() { $collectionClassName = \App\Propel\Map\CategoryTableMap::getTableMap()->getCollectionClassName(); $this->collNestedSetChildren = new $collectionClassName(); $this->collNestedSetChildren->setModel('\\App\\Propel\\Category'); }
/** * @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()); }
public function testSetterCollectionWithNewObjects() { // Ensure no data BookQuery::create()->deleteAll(); BookClubListQuery::create()->deleteAll(); BookListRelQuery::create()->deleteAll(); $coll = new ObjectCollection(); $coll->setModel('Book'); for ($i = 0; $i < 3; $i++) { $b = new Book(); $b->setTitle('Title ' . $i); $b->setIsbn('1245' . $i); $coll[] = $b; } $bookClubList = new BookClubList(); $bookClubList->setGroupLeader('fabpot'); $bookClubList->setBooks($coll); $bookClubList->save(); $this->assertEquals(3, $coll->count()); $this->assertEquals(3, count($bookClubList->getBooks())); $this->assertSame($coll, $bookClubList->getBooks()); $this->assertEquals(3, BookQuery::create()->count()); $this->assertEquals(1, BookClubListQuery::create()->count()); $this->assertEquals(3, BookListRelQuery::create()->count()); }
protected function createEmptyAcl($identifier = 1, array $securityIdentities = array(), AclInterface $parentAcl = null, $inherited = null) { $collection = new ObjectCollection(); $collection->setModel('Propel\\Bundle\\PropelBundle\\Model\\Acl\\Entry'); return new MutableAcl($collection, $this->getAclObjectIdentity($identifier), new PermissionGrantingStrategy(), $securityIdentities, $parentAcl, $inherited, $this->con); }
public function testSetterCollectionWithNewObjects() { // Ensure no data BookQuery::create()->deleteAll(); BookClubListQuery::create()->deleteAll(); BookListRelQuery::create()->deleteAll(); $coll = new ObjectCollection(); $coll->setModel('Book'); $coll[] = new Book(); $coll[] = new Book(); $coll[] = new Book(); $bookClubList = new BookClubList(); $bookClubList->setBooks($coll); $bookClubList->save(); $this->assertEquals(3, $coll->count()); $this->assertEquals(3, count($bookClubList->getBooks())); $this->assertSame($coll, $bookClubList->getBooks()); $this->assertEquals(3, BookQuery::create()->count()); $this->assertEquals(1, BookClubListQuery::create()->count()); $this->assertEquals(3, BookListRelQuery::create()->count()); }
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 Acl($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\\Acl', $unserialized); $this->assertEquals($serialized, serialize($unserialized)); }