@@ -81,7 +81,7 @@ public function testAnotherOwnerGallery()
81
81
'saveAfterUpload ' => true
82
82
]);
83
83
84
- $ model ->image_gallery = [$ response ['id ' ] => 'test ' ];
84
+ $ model ->image_gallery = [' files ' => [ $ response ['id ' ] => 'test ' ] ];
85
85
$ model ->save ();
86
86
87
87
$ file = File::findOne ($ response ['id ' ]);
@@ -108,6 +108,34 @@ public function testEmptyGallery()
108
108
$ this ->assertCount (0 , $ model ->getFiles ('image_gallery ' ));
109
109
}
110
110
111
+ public function testRemoveFileFromGallery ()
112
+ {
113
+ extract ($ this ->uploadGallery ([
114
+ 'modelName ' => News::className (),
115
+ 'attribute ' => 'image_gallery ' ,
116
+ 'inputName ' => 'file-300 ' ,
117
+ 'multiple ' => true ,
118
+ 'template ' => Yii::getAlias ('@tests/data/views/gallery-item.php ' )
119
+ ]));
120
+
121
+ $ this ->assertCount (1 , $ model ->getFiles ('image_gallery ' ));
122
+
123
+ $ response = $ this ->runAction ([
124
+ 'modelName ' => News::className (),
125
+ 'attribute ' => 'image_gallery ' ,
126
+ 'inputName ' => 'file-500 ' ,
127
+ 'saveAfterUpload ' => true ,
128
+ 'ownerId ' => $ model ->id
129
+ ]);
130
+
131
+ $ this ->assertCount (2 , $ model ->getFiles ('image_gallery ' ));
132
+
133
+ $ model ->image_gallery = ['files ' => [$ response ['id ' ] => 'test ' ]];
134
+ $ model ->save ();
135
+
136
+ $ this ->assertCount (1 , $ model ->getFiles ('image_gallery ' ));
137
+ }
138
+
111
139
public function testWrongGallery ()
112
140
{
113
141
extract ($ this ->uploadGallery ([
@@ -118,7 +146,7 @@ public function testWrongGallery()
118
146
'template ' => Yii::getAlias ('@tests/data/views/gallery-item.php ' )
119
147
]));
120
148
121
- $ model ->image_gallery = ['1000 ' => 'test ' ];
149
+ $ model ->image_gallery = ['files ' => [ ' 1000 ' => 'test ' ] ];
122
150
$ model ->save ();
123
151
124
152
$ this ->assertCount (0 , $ model ->getFiles ('image_gallery ' ));
@@ -144,7 +172,11 @@ public function testSaveNotTmpGallery()
144
172
'saveAfterUpload ' => true
145
173
]);
146
174
147
- $ model ->image_gallery = [$ response ['id ' ] => 'test ' ];
175
+ $ model ->image_gallery = ['files ' => [
176
+ $ files [0 ]->id => 'test2 ' ,
177
+ $ response ['id ' ] => 'test '
178
+ ]];
179
+
148
180
$ model ->save ();
149
181
150
182
$ this ->assertCount (2 , $ model ->getFiles ('image_gallery ' ));
@@ -171,12 +203,11 @@ public function testFailSaveGallery()
171
203
$ file = File::findOne ($ response ['id ' ]);
172
204
unlink ($ file ->path (true ));
173
205
174
- $ model ->image_gallery = [$ response ['id ' ] => 'test ' ];
206
+ $ model ->image_gallery = [' files ' => [ $ response ['id ' ] => 'test ' ] ];
175
207
$ model ->save ();
176
208
177
209
$ files = $ model ->getFiles ('image_gallery ' );
178
210
179
- $ this ->assertCount (1 , $ files );
180
- $ this ->assertTrue ($ files [0 ]->id === $ oldFiles [0 ]->id );
211
+ $ this ->assertCount (0 , $ files );
181
212
}
182
213
}
0 commit comments