@@ -61,7 +61,7 @@ public function testNewEntity()
6161 $ mock ->data = ['name ' => 'filename ' ];
6262 $ mock ->field = 'field ' ;
6363 $ mock ->entity ->expects ($ this ->once ())->method ('isNew ' )->will ($ this ->returnValue (true ));
64- $ this -> assertEquals ( ' webroot/files/Table-field/1/ ' , $ mock ->basepath () );
64+ $ mock ->basepath ();
6565 }
6666
6767 public function testExitingEntityWithCompositePrimaryKey ()
@@ -76,7 +76,7 @@ public function testExitingEntityWithCompositePrimaryKey()
7676 $ mock ->field = 'field ' ;
7777 $ mock ->entity ->expects ($ this ->once ())->method ('isNew ' )->will ($ this ->returnValue (false ));
7878 $ mock ->table ->expects ($ this ->once ())->method ('primaryKey ' )->will ($ this ->returnValue (['id ' , 'other_id ' ]));
79- $ this -> assertEquals ( ' webroot/files/Table-field/1/ ' , $ mock ->basepath () );
79+ $ mock ->basepath ();
8080 }
8181
8282 public function testYearWithMonthPath ()
@@ -118,4 +118,59 @@ public function testModelFieldYearWithMonthAndDayPath()
118118
119119 $ this ->assertEquals ('webroot/files/Table/field/ ' . date ("Y " ) . '/ ' . date ("m " ) . '/ ' . date ("d " ) . '/ ' , $ mock ->basepath ());
120120 }
121+
122+ public function testFieldValueMissing ()
123+ {
124+ $ this ->setExpectedException ('LogicException ' , 'Field value for substitution is missing: field ' );
125+
126+ $ mock = $ this ->getMockForTrait ('Josegonzalez\Upload\File\Path\Basepath\DefaultTrait ' );
127+ $ mock ->entity = $ this ->getMock ('Cake\ORM\Entity ' );
128+ $ mock ->table = $ this ->getMock ('Cake\ORM\Table ' );
129+ $ mock ->settings = ['path ' => 'webroot{DS}files{DS}{model}{DS}{field-value:field}{DS} ' ];
130+ $ mock ->data = ['name ' => 'filename ' ];
131+ $ mock ->field = 'field ' ;
132+ $ mock ->entity ->expects ($ this ->any ())->method ('get ' )->will ($ this ->returnValue (null ));
133+ $ mock ->basepath ();
134+ }
135+
136+ public function testFieldValueNonScalar ()
137+ {
138+ $ this ->setExpectedException ('LogicException ' , 'Field value for substitution must be a integer, float, string or boolean: field ' );
139+
140+ $ mock = $ this ->getMockForTrait ('Josegonzalez\Upload\File\Path\Basepath\DefaultTrait ' );
141+ $ mock ->entity = $ this ->getMock ('Cake\ORM\Entity ' );
142+ $ mock ->table = $ this ->getMock ('Cake\ORM\Table ' );
143+ $ mock ->settings = ['path ' => 'webroot{DS}files{DS}{model}{DS}{field-value:field}{DS} ' ];
144+ $ mock ->data = ['name ' => 'filename ' ];
145+ $ mock ->field = 'field ' ;
146+ $ mock ->entity ->expects ($ this ->any ())->method ('get ' )->will ($ this ->returnValue ([]));
147+ $ mock ->basepath ();
148+ }
149+
150+ public function testFieldValueZeroLength ()
151+ {
152+ $ this ->setExpectedException ('LogicException ' , 'Field value for substitution must be non-zero in length: field ' );
153+
154+ $ mock = $ this ->getMockForTrait ('Josegonzalez\Upload\File\Path\Basepath\DefaultTrait ' );
155+ $ mock ->entity = $ this ->getMock ('Cake\ORM\Entity ' );
156+ $ mock ->table = $ this ->getMock ('Cake\ORM\Table ' );
157+ $ mock ->settings = ['path ' => 'webroot{DS}files{DS}{model}{DS}{field-value:field}{DS} ' ];
158+ $ mock ->data = ['name ' => 'filename ' ];
159+ $ mock ->field = 'field ' ;
160+ $ mock ->entity ->expects ($ this ->any ())->method ('get ' )->will ($ this ->returnValue ('' ));
161+ $ mock ->basepath ();
162+ }
163+
164+ public function testFieldValue ()
165+ {
166+ $ mock = $ this ->getMockForTrait ('Josegonzalez\Upload\File\Path\Basepath\DefaultTrait ' );
167+ $ mock ->entity = $ this ->getMock ('Cake\ORM\Entity ' );
168+ $ mock ->table = $ this ->getMock ('Cake\ORM\Table ' );
169+ $ mock ->settings = ['path ' => 'webroot{DS}files{DS}{model}{DS}{field-value:field}{DS} ' ];
170+ $ mock ->data = ['name ' => 'filename ' ];
171+ $ mock ->field = 'field ' ;
172+ $ mock ->entity ->expects ($ this ->any ())->method ('get ' )->will ($ this ->returnValue ('value ' ));
173+ $ mock ->table ->expects ($ this ->once ())->method ('alias ' )->will ($ this ->returnValue ('Table ' ));
174+ $ this ->assertEquals ('webroot/files/Table/value/ ' , $ mock ->basepath ());
175+ }
121176}
0 commit comments