)
) );
}
-
- /**
- * Recursively merges the expected values in the $item into the $all
- */
- private function mergeExpected( &$all, $item ) {
- foreach ( $item as $k => $v ) {
- if ( array_key_exists( $k, $all ) ) {
- if ( is_array( $all[$k] ) ) {
- $this->mergeExpected( $all[$k], $v );
- } else {
- $this->assertEquals( $all[$k], $v );
- }
- } else {
- $all[$k] = $v;
- }
- }
- }
-
- /**
- * Recursively compare arrays, ignoring mismatches in numeric key and pageids.
- *
- * @param $expectedArray array expected values
- * @param $resultArray array returned values
- */
- private function assertQueryResults( $expectedArray, $resultArray ) {
- reset( $expectedArray );
- reset( $resultArray );
- while ( true ) {
- $expectedValue = each( $expectedArray );
- $resultValue = each( $resultArray );
- // If either of the arrays is shorter, abort. If both are done, success.
- $this->assertEquals( (bool)$expectedValue, (bool)$resultValue );
- if ( !$expectedValue ) {
- break; // done
- }
- // continue only if keys are identical or both keys are numeric
- $this->assertTrue( $expectedValue['key'] === $resultValue['key'] || ( is_numeric( $expectedValue['key'] ) && is_numeric( $resultValue['key'] ) ) );
- // don't compare pageids
- if ( $expectedValue['key'] !== 'pageid' ) {
- // If values are arrays, compare recursively, otherwise compare with ===
- if ( is_array( $expectedValue['value'] ) && is_array( $resultValue['value'] ) ) {
- $this->assertQueryResults( $expectedValue['value'], $resultValue['value'] );
- } else {
- $this->assertEquals( $expectedValue['value'], $resultValue['value'] );
- }
- }
- }
- }
}