public function testMatchesRemoteValue() { $parent = new DefaultModel(); $parent->setId(1); $child = new DefaultModel(); $child->setPropertyRaw('pid', 1); $child->setId(2); $condition = new ParentChildCondition(); $condition->setFilterArray(array(array('local' => 'id', 'operation' => '=', 'remote_value' => '2'))); $this->assertTrue($condition->matches($parent, $child)); }
/** * Prepare the required collections from provided test data. * * @param array|ModelIdInterface[] $siblings List of all models. * @param array $resortingIds Resorting ids. * @param int|null $previousModelId Previous model ids. * @param CollectionInterface $siblingCollection The sibling collection. * @param CollectionInterface $modelCollection The model collection of models being moved. * @param ModelIdInterface|null $previousModel Optional previous model. * * @return void. */ protected function prepareCollections(array &$siblings, array $resortingIds, $previousModelId, $siblingCollection, $modelCollection, &$previousModel) { foreach ($siblings as $id => $sorting) { $model = new DefaultModel(); $model->setID($id); $model->setProperty('sorting', $sorting); $siblingCollection->push($model); $siblings[$id] = $model; if (in_array($id, $resortingIds)) { $modelCollection->push($model); } if ($id === $previousModelId) { $previousModel = $model; } } }
public function testGetMatch() { $condition = new PaletteConditionChain(); $condition->setConjunction(PaletteConditionChain::AND_CONJUNCTION); $condition->addCondition(new PropertyValueCondition('prop1', '0')); $condition->addCondition(new PropertyValueCondition('prop2', '1')); $this->assertEquals(0, $condition->getMatchCount()); $model = new DefaultModel(); $model->setProperty('prop1', '0'); $model->setProperty('prop2', '1'); $this->assertEquals(2, $condition->getMatchCount($model)); $model->setProperty('prop2', '0'); $this->assertEquals(0, $condition->getMatchCount($model)); $propertyValueBag = new PropertyValueBag(); $propertyValueBag->setPropertyValue('prop1', '0'); $propertyValueBag->setPropertyValue('prop2', '1'); $this->assertEquals(2, $condition->getMatchCount(null, $propertyValueBag)); $propertyValueBag->setPropertyValue('prop2', '3'); $this->assertEquals(0, $condition->getMatchCount(null, $propertyValueBag)); }
/** * Create an entity from a data row. * * @param array $row The data row. * @param string $tableName The table name. * * @return Entity */ public function createFromArray(array $row, $tableName) { $model = new DefaultModel(); $model->setProviderName($tableName); $model->setId($row['id']); foreach ($row as $name => $value) { $model->setPropertyRaw($name, $value); } return $model; }
/** * {@inheritDoc} */ public function getEmptyModel() { $objModel = new DefaultModel(); $objModel->setProviderName($this->strSource); return $objModel; }