Code Duplication    Length = 30-31 lines in 4 locations

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

@@ 1641-1671 (lines=31) @@
1638
 *
1639
 * @return void
1640
 */
1641
	public function testGenerateAssociationQueryHasManyWithOffsetAndLimit() {
1642
		$this->Model = new TestModel5();
1643
		$this->Model->schema();
1644
		$this->_buildRelatedModels($this->Model);
1645
1646
		$backup = $this->Model->hasMany['TestModel6'];
1647
1648
		$this->Model->hasMany['TestModel6']['offset'] = 2;
1649
		$this->Model->hasMany['TestModel6']['limit'] = 5;
1650
1651
		$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
1652
		$queryData = array();
1653
		$resultSet = null;
1654
		$null = null;
1655
1656
		$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
1657
1658
		$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
1659
1660
		$this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
1661
		$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
1662
		$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
1663
		$this->assertRegExp('/\s+LIMIT 2,\s*5\s*$/', $result);
1664
1665
		$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
1666
		$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
1667
		$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
1668
		$this->assertRegExp('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
1669
1670
		$this->Model->hasMany['TestModel6'] = $backup;
1671
	}
1672
1673
/**
1674
 * testGenerateAssociationQueryHasManyWithPageAndLimit method
@@ 1678-1707 (lines=30) @@
1675
 *
1676
 * @return void
1677
 */
1678
	public function testGenerateAssociationQueryHasManyWithPageAndLimit() {
1679
		$this->Model = new TestModel5();
1680
		$this->Model->schema();
1681
		$this->_buildRelatedModels($this->Model);
1682
1683
		$backup = $this->Model->hasMany['TestModel6'];
1684
1685
		$this->Model->hasMany['TestModel6']['page'] = 2;
1686
		$this->Model->hasMany['TestModel6']['limit'] = 5;
1687
1688
		$binding = array('type' => 'hasMany', 'model' => 'TestModel6');
1689
		$queryData = array();
1690
		$resultSet = null;
1691
		$null = null;
1692
1693
		$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
1694
1695
		$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
1696
		$this->assertRegExp('/^SELECT\s+`TestModel6`\.`id`, `TestModel6`\.`test_model5_id`, `TestModel6`\.`name`, `TestModel6`\.`created`, `TestModel6`\.`updated`\s+/', $result);
1697
		$this->assertRegExp('/\s+FROM\s+\S+`test_model6` AS `TestModel6`\s+WHERE\s+/', $result);
1698
		$this->assertRegExp('/WHERE\s+(?:\()?`TestModel6`\.`test_model5_id`\s+=\s+\({\$__cakeID__\$}\)(?:\))?/', $result);
1699
		$this->assertRegExp('/\s+LIMIT 5,\s*5\s*$/', $result);
1700
1701
		$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
1702
		$this->assertRegExp('/^SELECT\s+`TestModel5`\.`id`, `TestModel5`\.`test_model4_id`, `TestModel5`\.`name`, `TestModel5`\.`created`, `TestModel5`\.`updated`\s+/', $result);
1703
		$this->assertRegExp('/\s+FROM\s+\S+`test_model5` AS `TestModel5`\s+WHERE\s+/', $result);
1704
		$this->assertRegExp('/\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
1705
1706
		$this->Model->hasMany['TestModel6'] = $backup;
1707
	}
1708
1709
/**
1710
 * testGenerateAssociationQueryHasManyWithFields method
@@ 1920-1949 (lines=30) @@
1917
 *
1918
 * @return void
1919
 */
1920
	public function testGenerateAssociationQueryHasAndBelongsToManyWithOffsetAndLimit() {
1921
		$this->Model = new TestModel4();
1922
		$this->Model->schema();
1923
		$this->_buildRelatedModels($this->Model);
1924
1925
		$backup = $this->Model->hasAndBelongsToMany['TestModel7'];
1926
1927
		$this->Model->hasAndBelongsToMany['TestModel7']['offset'] = 2;
1928
		$this->Model->hasAndBelongsToMany['TestModel7']['limit'] = 5;
1929
1930
		$binding = array('type' => 'hasAndBelongsToMany', 'model' => 'TestModel7');
1931
		$queryData = array();
1932
		$resultSet = null;
1933
		$null = null;
1934
1935
		$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
1936
1937
		$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
1938
		$this->assertRegExp('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
1939
		$this->assertRegExp('/\s+FROM\s+\S+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+\S+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result);
1940
		$this->assertRegExp('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}\s+/', $result);
1941
		$this->assertRegExp('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result);
1942
		$this->assertRegExp('/\s+(?:\()?1\s+=\s+1(?:\))?\s*\s+LIMIT 2,\s*5\s*$/', $result);
1943
1944
		$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
1945
		$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
1946
		$this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
1947
1948
		$this->Model->hasAndBelongsToMany['TestModel7'] = $backup;
1949
	}
1950
1951
/**
1952
 * testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit method
@@ 1956-1985 (lines=30) @@
1953
 *
1954
 * @return void
1955
 */
1956
	public function testGenerateAssociationQueryHasAndBelongsToManyWithPageAndLimit() {
1957
		$this->Model = new TestModel4();
1958
		$this->Model->schema();
1959
		$this->_buildRelatedModels($this->Model);
1960
1961
		$backup = $this->Model->hasAndBelongsToMany['TestModel7'];
1962
1963
		$this->Model->hasAndBelongsToMany['TestModel7']['page'] = 2;
1964
		$this->Model->hasAndBelongsToMany['TestModel7']['limit'] = 5;
1965
1966
		$binding = array('type' => 'hasAndBelongsToMany', 'model' => 'TestModel7');
1967
		$queryData = array();
1968
		$resultSet = null;
1969
		$null = null;
1970
1971
		$params = &$this->_prepareAssociationQuery($this->Model, $queryData, $binding);
1972
1973
		$result = $this->Dbo->generateAssociationQuery($this->Model, $params['linkModel'], $params['type'], $params['assoc'], $params['assocData'], $queryData, $params['external'], $resultSet);
1974
		$this->assertRegExp('/^SELECT\s+`TestModel7`\.`id`, `TestModel7`\.`name`, `TestModel7`\.`created`, `TestModel7`\.`updated`, `TestModel4TestModel7`\.`test_model4_id`, `TestModel4TestModel7`\.`test_model7_id`\s+/', $result);
1975
		$this->assertRegExp('/\s+FROM\s+\S+`test_model7`\s+AS\s+`TestModel7`\s+JOIN\s+\S+`test_model4_test_model7`\s+AS\s+`TestModel4TestModel7`/', $result);
1976
		$this->assertRegExp('/\s+ON\s+\(`TestModel4TestModel7`\.`test_model4_id`\s+=\s+{\$__cakeID__\$}/', $result);
1977
		$this->assertRegExp('/\s+AND\s+`TestModel4TestModel7`\.`test_model7_id`\s+=\s+`TestModel7`\.`id`\)\s+WHERE\s+/', $result);
1978
		$this->assertRegExp('/\s+(?:\()?1\s+=\s+1(?:\))?\s*\s+LIMIT 5,\s*5\s*$/', $result);
1979
1980
		$result = $this->Dbo->generateAssociationQuery($this->Model, $null, null, null, null, $queryData, false, $null);
1981
		$this->assertRegExp('/^SELECT\s+`TestModel4`\.`id`, `TestModel4`\.`name`, `TestModel4`\.`created`, `TestModel4`\.`updated`\s+/', $result);
1982
		$this->assertRegExp('/\s+FROM\s+\S+`test_model4` AS `TestModel4`\s+WHERE\s+(?:\()?1\s+=\s+1(?:\))?\s*$/', $result);
1983
1984
		$this->Model->hasAndBelongsToMany['TestModel7'] = $backup;
1985
	}
1986
1987
/**
1988
 * testSelectDistict method