Example #1
0
 /**
  * @dataProvider modelProvider
  */
 public function testFromArray(ConfigModel $model)
 {
     $values = ['value1' => 1, 'value2' => 2, 'indexed1' => 3, 'indexed2' => 4];
     $indexed = ['indexed1' => true, 'indexed2' => true];
     $model->fromArray('test_scope', $values, $indexed);
     $this->assertEquals($values, $model->toArray('test_scope'));
     $indexedValues = $model->getIndexedValues();
     $expectedCount = $model instanceof EntityConfigModel ? 4 : 2;
     $this->assertCount($expectedCount, $indexedValues);
     $indexedValues = $indexedValues->toArray();
     /** @var ConfigModelIndexValue $indexedValue */
     if ($model instanceof EntityConfigModel) {
         $indexedValue = array_shift($indexedValues);
         $this->assertEquals('entity_config', $indexedValue->getScope());
         $this->assertEquals('module_name', $indexedValue->getCode());
         $this->assertEquals(self::TEST_MODULE, $indexedValue->getValue());
         $indexedValue = array_shift($indexedValues);
         $this->assertEquals('entity_config', $indexedValue->getScope());
         $this->assertEquals('entity_name', $indexedValue->getCode());
         $this->assertEquals(self::TEST_ENTITY, $indexedValue->getValue());
     }
     $indexedValue = array_shift($indexedValues);
     $this->assertEquals('test_scope', $indexedValue->getScope());
     $this->assertEquals('indexed1', $indexedValue->getCode());
     $this->assertEquals(3, $indexedValue->getValue());
     $indexedValue = array_shift($indexedValues);
     $this->assertEquals('test_scope', $indexedValue->getScope());
     $this->assertEquals('indexed2', $indexedValue->getCode());
     $this->assertEquals(4, $indexedValue->getValue());
     $values = ['value2' => 1, 'indexed2' => 2];
     $model->fromArray('test_scope', $values, $indexed);
     $this->assertEquals($values, $model->toArray('test_scope'));
     $indexedValues = $model->getIndexedValues();
     $expectedCount = $model instanceof EntityConfigModel ? 3 : 1;
     $this->assertCount($expectedCount, $indexedValues);
     $indexedValues = $indexedValues->toArray();
     if ($model instanceof EntityConfigModel) {
         $indexedValue = array_shift($indexedValues);
         $this->assertEquals('entity_config', $indexedValue->getScope());
         $this->assertEquals('module_name', $indexedValue->getCode());
         $this->assertEquals(self::TEST_MODULE, $indexedValue->getValue());
         $indexedValue = array_shift($indexedValues);
         $this->assertEquals('entity_config', $indexedValue->getScope());
         $this->assertEquals('entity_name', $indexedValue->getCode());
         $this->assertEquals(self::TEST_ENTITY, $indexedValue->getValue());
     }
     $indexedValue = array_shift($indexedValues);
     $this->assertEquals('test_scope', $indexedValue->getScope());
     $this->assertEquals('indexed2', $indexedValue->getCode());
     $this->assertEquals(2, $indexedValue->getValue());
     $values = [];
     $model->fromArray('test_scope', $values, $indexed);
     $this->assertEquals($values, $model->toArray('test_scope'));
 }