mockWebApplication(); } public function testAttributeValue() { $model = new ModelMock(); $model->id = 'id'; $this->detailView = new PublicDetailView([ 'model' => $model, 'template' => '{label}:{value}', 'attributes' => [ 'id', [ 'attribute' => 'id', 'value' => 1, ], [ 'attribute' => 'id', 'value' => '1', ], [ 'attribute' => 'id', 'value' => $model->getDisplayedId(), ], [ 'attribute' => 'id', 'value' => function ($model) { return $model->getDisplayedId(); }, ], ], ]); $this->assertEquals('Id:id', $this->detailView->renderAttribute($this->detailView->attributes[0], 0)); $this->assertEquals('Id:1', $this->detailView->renderAttribute($this->detailView->attributes[1], 1)); $this->assertEquals('Id:1', $this->detailView->renderAttribute($this->detailView->attributes[2], 2)); $this->assertEquals('Id:Displayed id', $this->detailView->renderAttribute($this->detailView->attributes[3], 3)); $this->assertEquals('Id:Displayed id', $this->detailView->renderAttribute($this->detailView->attributes[4], 4)); $this->assertEquals(2, $model->getDisplayedIdCallCount()); } /** * @see https://github.com/yiisoft/yii2/issues/13243 */ public function testUnicodeAttributeNames() { $model = new UnicodeAttributesModelMock(); $model->ИдентификаторТовара = 'A00001'; $model->το_αναγνωριστικό_του = 'A00002'; $this->detailView = new PublicDetailView([ 'model' => $model, 'template' => '{label}:{value}', 'attributes' => [ 'ИдентификаторТовара', 'το_αναγνωριστικό_του', ], ]); $this->assertEquals( 'ИдентификаторТовара:A00001', $this->detailView->renderAttribute($this->detailView->attributes[0], 0) ); $this->assertEquals( 'το αναγνωριστικό του:A00002', $this->detailView->renderAttribute($this->detailView->attributes[1], 1) ); } public function testAttributeVisible() { $model = new ModelMock(); $model->id = 'id'; $this->detailView = new PublicDetailView([ 'model' => $model, 'template' => '{label}:{value}', 'attributes' => [ [ 'attribute' => 'id', 'value' => $model->getDisplayedId(), ], [ 'attribute' => 'id', 'value' => $model->getDisplayedId(), 'visible' => false, ], [ 'attribute' => 'id', 'value' => $model->getDisplayedId(), 'visible' => true, ], [ 'attribute' => 'id', 'value' => function ($model) { return $model->getDisplayedId(); }, ], [ 'attribute' => 'id', 'value' => function ($model) { return $model->getDisplayedId(); }, 'visible' => false, ], [ 'attribute' => 'id', 'value' => function ($model) { return $model->getDisplayedId(); }, 'visible' => true, ], ], ]); $this->assertEquals([ 0 => [ 'attribute' => 'id', 'format' => 'text', 'label' => 'Id', 'value' => 'Displayed id', ], 2 => [ 'attribute' => 'id', 'format' => 'text', 'label' => 'Id', 'value' => 'Displayed id', 'visible' => true, ], 3 => [ 'attribute' => 'id', 'format' => 'text', 'label' => 'Id', 'value' => 'Displayed id', ], 5 => [ 'attribute' => 'id', 'format' => 'text', 'label' => 'Id', 'value' => 'Displayed id', 'visible' => true, ], ], $this->detailView->attributes); $this->assertEquals(5, $model->getDisplayedIdCallCount()); } public function testRelationAttribute() { $model = new ModelMock(); $model->id = 'model'; $model->related = new ModelMock(); $model->related->id = 'related'; $this->detailView = new PublicDetailView([ 'model' => $model, 'template' => '{label}:{value}', 'attributes' => [ 'id', 'related.id', ], ]); $this->assertEquals('Id:model', $this->detailView->renderAttribute($this->detailView->attributes[0], 0)); $this->assertEquals('Related Id:related', $this->detailView->renderAttribute($this->detailView->attributes[1], 1)); // test null relation $model->related = null; $this->detailView = new PublicDetailView([ 'model' => $model, 'template' => '{label}:{value}', 'attributes' => [ 'id', 'related.id', ], ]); $this->assertEquals('Id:model', $this->detailView->renderAttribute($this->detailView->attributes[0], 0)); $this->assertEquals('Related Id:(not set)', $this->detailView->renderAttribute($this->detailView->attributes[1], 1)); } public function testArrayableModel() { $expectedValue = [ [ 'attribute' => 'id', 'format' => 'text', 'label' => 'Id', 'value' => 1, ], [ 'attribute' => 'text', 'format' => 'text', 'label' => 'Text', 'value' => 'I`m arrayable', ], ]; $model = new ArrayableMock(); $model->id = 1; $model->text = 'I`m arrayable'; $this->detailView = new DetailView([ 'model' => $model, ]); $this->assertEquals($expectedValue, $this->detailView->attributes); } public function testObjectModel() { $expectedValue = [ [ 'attribute' => 'id', 'format' => 'text', 'label' => 'Id', 'value' => 1, ], [ 'attribute' => 'text', 'format' => 'text', 'label' => 'Text', 'value' => 'I`m an object', ], ]; $model = new ModelMock(); $model->id = 1; $model->text = 'I`m an object'; $this->detailView = new DetailView([ 'model' => $model, ]); $this->assertEquals($expectedValue, $this->detailView->attributes); } public function testArrayModel() { $expectedValue = [ [ 'attribute' => 'id', 'format' => 'text', 'label' => 'Id', 'value' => 1, ], [ 'attribute' => 'text', 'format' => 'text', 'label' => 'Text', 'value' => 'I`m an array', ], ]; $model = [ 'id' => 1, 'text' => 'I`m an array', ]; $this->detailView = new DetailView([ 'model' => $model, ]); $this->assertEquals($expectedValue, $this->detailView->attributes); } public function testOptionsTags() { $expectedValue = '