1616 * limitations under the License.
1717 */
1818
19+ use PHPUnit \Framework \Attributes \DataProvider ;
1920use PHPUnit \Framework \TestCase ;
2021
2122class EngineBlock_Test_TypeTest extends TestCase
@@ -26,13 +27,22 @@ class EngineBlock_Test_TypeTest extends TestCase
2627 * @param $options
2728 * @param $attributes
2829 */
29- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('validAttributesProvider ' )]
30+ #[DataProvider('validAttributesProvider ' )]
3031 public function testAttributeValidates ($ attributeName , $ options , $ attributes )
3132 {
3233 $ validator = new EngineBlock_Attributes_Validator_Type ($ attributeName , $ options );
3334 $ this ->assertTrue ($ validator ->validate ($ attributes ));
3435 }
3536
37+ #[DataProvider('invalidAttributesProvider ' )]
38+ public function testAttributeValidationFails ($ attributeName , $ options , $ attributes , $ expectedMessage )
39+ {
40+ $ validator = new EngineBlock_Attributes_Validator_Type ($ attributeName , $ options );
41+
42+ $ this ->assertFalse ($ validator ->validate ($ attributes ));
43+ $ this ->assertSame ([$ expectedMessage , $ attributeName , $ options , $ attributes [$ attributeName ][0 ]], $ validator ->getMessages ()[0 ]);
44+ }
45+
3646 public static function validAttributesProvider ()
3747 {
3848 return array (
@@ -59,7 +69,8 @@ public static function validAttributesProvider()
5969 'options ' => 'URI ' ,
6070 'attributes ' => array (
6171 'foo ' => array (
62- '? '
72+ '? ' ,
73+ 'urn:mace:dir:entitlement:common-lib-terms ' ,
6374 )
6475 )
6576 ),
@@ -78,4 +89,20 @@ public static function validAttributesProvider()
7889 )
7990 );
8091 }
92+
93+ public static function invalidAttributesProvider ()
94+ {
95+ return array (
96+ array (
97+ 'attributeName ' => 'foo ' ,
98+ 'options ' => 'URL ' ,
99+ 'attributes ' => array (
100+ 'foo ' => array (
101+ 'mailto:test@example.org ' ,
102+ )
103+ ),
104+ 'expectedMessage ' => EngineBlock_Attributes_Validator_Type::ERROR_ATTRIBUTE_VALIDATOR_URL ,
105+ ),
106+ );
107+ }
81108}
0 commit comments