123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- <?php
- abstract class ElggCoreUnitTest extends UnitTestCase {
-
- public function __construct() {
- parent::__construct();
- }
-
- public function __destruct() {
- }
-
- public function assertIdenticalEntities(\ElggEntity $first, \ElggEntity $second, $message = '%s') {
- if (!($res = $this->assertIsA($first, '\ElggEntity'))) {
- return $res;
- }
- if (!($res = $this->assertIsA($second, '\ElggEntity'))) {
- return $res;
- }
- if (!($res = $this->assertEqual(get_class($first), get_class($second)))) {
- return $res;
- }
- return $this->assert(new IdenticalEntityExpectation($first), $second, $message);
- }
- }
- class IdenticalEntityExpectation extends EqualExpectation {
-
- public function __construct($value, $message = '%s') {
- parent::__construct($value, $message);
- }
-
- public function test($compare) {
- $value = $this->entityToFilteredArray($this->getValue());
- $compare = $this->entityToFilteredArray($compare);
- return SimpleTestCompatibility::isIdentical($value, $compare);
- }
-
- protected function entityToFilteredArray($entity) {
- $skippedKeys = array('last_action');
- $array = (array)$entity;
- unset($array["\0*\0tables_loaded"]);
- foreach ($skippedKeys as $key) {
-
- $array["\0*\0attributes"][$key] = null;
- }
- ksort($array["\0*\0attributes"]);
- return $array;
- }
-
- public function testMessage($compare) {
- $dumper = $this->getDumper();
- $value2 = $this->entityToFilteredArray($this->getValue());
- $compare2 = $this->entityToFilteredArray($compare);
- if ($this->test($compare)) {
- return "Identical entity expectation [" . $dumper->describeValue($this->getValue()) . "]";
- } else {
- return "Identical entity expectation [" . $dumper->describeValue($this->getValue()) .
- "] fails with [" .
- $dumper->describeValue($compare) . "] " .
- $dumper->describeDifference($value2, $compare2, TYPE_MATTERS);
- }
- }
- }
|