@@ -490,22 +490,22 @@ public function testIndirectModification()
490
490
public function testHas ()
491
491
{
492
492
$ entity = new Entity (['id ' => 1 , 'name ' => 'Juan ' , 'foo ' => null ]);
493
- $ this ->assertTrue ($ entity ->has ('id ' ));
494
- $ this ->assertTrue ($ entity ->has ('name ' ));
495
- $ this ->assertFalse ($ entity ->has ('foo ' ));
496
- $ this ->assertFalse ($ entity ->has ('last_name ' ));
493
+ $ this ->assertTrue ($ entity ->hasProperty ('id ' ));
494
+ $ this ->assertTrue ($ entity ->hasProperty ('name ' ));
495
+ $ this ->assertFalse ($ entity ->hasProperty ('foo ' ));
496
+ $ this ->assertFalse ($ entity ->hasProperty ('last_name ' ));
497
497
498
- $ this ->assertTrue ($ entity ->has (['id ' ]));
499
- $ this ->assertTrue ($ entity ->has (['id ' , 'name ' ]));
500
- $ this ->assertFalse ($ entity ->has (['id ' , 'foo ' ]));
501
- $ this ->assertFalse ($ entity ->has (['id ' , 'nope ' ]));
498
+ $ this ->assertTrue ($ entity ->hasProperty (['id ' ]));
499
+ $ this ->assertTrue ($ entity ->hasProperty (['id ' , 'name ' ]));
500
+ $ this ->assertFalse ($ entity ->hasProperty (['id ' , 'foo ' ]));
501
+ $ this ->assertFalse ($ entity ->hasProperty (['id ' , 'nope ' ]));
502
502
503
503
$ entity = $ this ->getMockBuilder ('\Cake\ORM\Entity ' )
504
504
->setMethods (['_getThings ' ])
505
505
->getMock ();
506
506
$ entity ->expects ($ this ->once ())->method ('_getThings ' )
507
507
->will ($ this ->returnValue (0 ));
508
- $ this ->assertTrue ($ entity ->has ('things ' ));
508
+ $ this ->assertTrue ($ entity ->hasProperty ('things ' ));
509
509
}
510
510
511
511
/**
@@ -1573,4 +1573,67 @@ public function testIsDirtyFromClone()
1573
1573
$ this ->assertTrue ($ cloned ->dirty ('a ' ));
1574
1574
$ this ->assertTrue ($ cloned ->dirty ('b ' ));
1575
1575
}
1576
+
1577
+ /**
1578
+ * Test the isEmpty() check
1579
+ *
1580
+ * @return void
1581
+ */
1582
+ public function testIsEmpty ()
1583
+ {
1584
+ $ entity = new Entity ([
1585
+ 'array ' => ['foo ' => 'bar ' ],
1586
+ 'emptyArray ' => [],
1587
+ 'object ' => new \stdClass (),
1588
+ 'string ' => 'string ' ,
1589
+ 'emptyString ' => '' ,
1590
+ 'intZero ' => 0 ,
1591
+ 'intNotZero ' => 1 ,
1592
+ 'floatZero ' => 0.0 ,
1593
+ 'floatNonZero ' => 1.5 ,
1594
+ 'null ' => null
1595
+ ]);
1596
+
1597
+ $ this ->assertFalse ($ entity ->isEmpty ('array ' ));
1598
+ $ this ->assertTrue ($ entity ->isEmpty ('emptyArray ' ));
1599
+ $ this ->assertFalse ($ entity ->isEmpty ('object ' ));
1600
+ $ this ->assertFalse ($ entity ->isEmpty ('string ' ));
1601
+ $ this ->assertTrue ($ entity ->isEmpty ('emptyString ' ));
1602
+ $ this ->assertFalse ($ entity ->isEmpty ('intZero ' ));
1603
+ $ this ->assertFalse ($ entity ->isEmpty ('intNotZero ' ));
1604
+ $ this ->assertFalse ($ entity ->isEmpty ('floatZero ' ));
1605
+ $ this ->assertFalse ($ entity ->isEmpty ('floatNonZero ' ));
1606
+ $ this ->assertTrue ($ entity ->isEmpty ('null ' ));
1607
+ }
1608
+
1609
+ /**
1610
+ * Test hasValue()
1611
+ *
1612
+ * @return void
1613
+ */
1614
+ public function testHasValue () {
1615
+ $ entity = new Entity ([
1616
+ 'array ' => ['foo ' => 'bar ' ],
1617
+ 'emptyArray ' => [],
1618
+ 'object ' => new \stdClass (),
1619
+ 'string ' => 'string ' ,
1620
+ 'emptyString ' => '' ,
1621
+ 'intZero ' => 0 ,
1622
+ 'intNotZero ' => 1 ,
1623
+ 'floatZero ' => 0.0 ,
1624
+ 'floatNonZero ' => 1.5 ,
1625
+ 'null ' => null
1626
+ ]);
1627
+
1628
+ $ this ->assertTrue ($ entity ->hasValue ('array ' ));
1629
+ $ this ->assertFalse ($ entity ->hasValue ('emptyArray ' ));
1630
+ $ this ->assertTrue ($ entity ->hasValue ('object ' ));
1631
+ $ this ->assertTrue ($ entity ->hasValue ('string ' ));
1632
+ $ this ->assertFalse ($ entity ->hasValue ('emptyString ' ));
1633
+ $ this ->assertTrue ($ entity ->hasValue ('intZero ' ));
1634
+ $ this ->assertTrue ($ entity ->hasValue ('intNotZero ' ));
1635
+ $ this ->assertTrue ($ entity ->hasValue ('floatZero ' ));
1636
+ $ this ->assertTrue ($ entity ->hasValue ('floatNonZero ' ));
1637
+ $ this ->assertFalse ($ entity ->hasValue ('null ' ));
1638
+ }
1576
1639
}
0 commit comments