Code Duplication    Length = 26-27 lines in 2 locations

lib/Cake/Test/Case/Model/Datasource/Database/MysqlTest.php 2 locations

@@ 1419-1445 (lines=27) @@
1416
 *
1417
 * @return void
1418
 */
1419
	public function testGenerateAssociationQueryHasOne() {
1420
		$this->Model = new TestModel4();
1421
		$this->Model->schema();
1422
		$this->_buildRelatedModels($this->Model);
1423
1424
		$binding = array('type' => 'hasOne', 'model' => 'TestModel5');
1425
1426
		$queryData = array();
1427
		$resultSet = null;
1428
		$null = null;
1429
1430
		$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
1431
1432
		$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
1433
		$this->assertTrue($result);
1434
1435
		$testModel5Table = $this->Dbo->fullTableName($this->Model->TestModel5);
1436
		$result = $this->Dbo->buildJoinStatement($queryData['joins'][0]);
1437
		$expected = ' LEFT JOIN ' . $testModel5Table . ' AS `TestModel5` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
1438
		$this->assertEquals(trim($expected), trim($result));
1439
1440
		$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
1441
		$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`, `TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
1442
		$this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+LEFT JOIN\s+/', $result);
1443
		$this->assertRegExp('/`test_model5` AS `TestModel5`\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE/', $result);
1444
		$this->assertRegExp('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result);
1445
	}
1446
1447
/**
1448
 * testGenerateAssociationQueryHasOneWithConditions method
@@ 1481-1506 (lines=26) @@
1478
 *
1479
 * @return void
1480
 */
1481
	public function testGenerateAssociationQueryBelongsTo() {
1482
		$this->Model = new TestModel5();
1483
		$this->Model->schema();
1484
		$this->_buildRelatedModels($this->Model);
1485
1486
		$binding = array('type' => 'belongsTo', 'model' => 'TestModel4');
1487
		$queryData = array();
1488
		$resultSet = null;
1489
		$null = null;
1490
1491
		$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
1492
1493
		$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
1494
		$this->assertTrue($result);
1495
1496
		$testModel4Table = $this->Dbo->fullTableName($this->Model->TestModel4, true, true);
1497
		$result = $this->Dbo->buildJoinStatement($queryData['joins'][0]);
1498
		$expected = ' LEFT JOIN ' . $testModel4Table . ' AS `TestModel4` ON (`TestModel5`.`test_model4_id` = `TestModel4`.`id`)';
1499
		$this->assertEquals(trim($expected), trim($result));
1500
1501
		$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
1502
		$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`, `TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
1503
		$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+LEFT JOIN\s+\S+`test_model4` AS `TestModel4`/', $result);
1504
		$this->assertRegExp('/\s+ON\s+\(`TestModel5`.`test_model4_id` = `TestModel4`.`id`\)\s+WHERE\s+/', $result);
1505
		$this->assertRegExp('/\s+WHERE\s+(?:\()?\s*1 = 1\s*(?:\))?\s*$/', $result);
1506
	}
1507
1508
/**
1509
 * testGenerateAssociationQueryBelongsToWithConditions method