Merge branch '3'

This commit is contained in:
Daniel Hensby 2016-05-12 16:42:48 +01:00
commit 0594542e7f
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
12 changed files with 143 additions and 19 deletions

View File

@ -206,6 +206,9 @@ the third paramter of the `combine_files` function:
Requirements::combine_files('print.css', $printStylesheets, 'print');
By default, all requirements files are flushed (deleted) when ?flush querystring parameter is set.
This can be disabled by setting the `Requirements.disable_flush_combined` config to `true`.
<div class="alert" markdown='1'>
When combining CSS files, take care of relative urls, as these will not be re-written to match
the destination location of the resulting combined CSS.

View File

@ -805,10 +805,12 @@ class DataQuery {
$relationTable,
"\"$relationTable\".\"$parentField\" = \"$parentBaseClass\".\"ID\""
);
if (!$this->query->isJoinedTo($componentBaseClass)) {
$this->query->addLeftJoin(
$componentBaseClass,
"\"$relationTable\".\"$componentField\" = \"$componentBaseClass\".\"ID\""
);
}
/**
* add join clause to the component's ancestry classes so that the search filter could search on
@ -817,7 +819,7 @@ class DataQuery {
$ancestry = ClassInfo::ancestry($componentClass, true);
$ancestry = array_reverse($ancestry);
foreach($ancestry as $ancestor){
if($ancestor != $componentBaseClass){
if($ancestor != $componentBaseClass && !$this->query->isJoinedTo($ancestor)){
$this->query->addInnerJoin($ancestor, "\"$componentBaseClass\".\"ID\" = \"$ancestor\".\"ID\"");
}
}

View File

@ -32,6 +32,8 @@ class DataListTest extends SapphireTest {
'DataObjectTest_Play',
'DataObjectTest_Ploy',
'DataObjectTest_Bogey',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
public function testFilterDataObjectByCreatedDate() {

View File

@ -35,6 +35,9 @@ class DataObjectLazyLoadingTest extends SapphireTest {
'DataObjectTest_Play',
'DataObjectTest_Ploy',
'DataObjectTest_Bogey',
// From ManyManyListTest
'ManyManyListTest_Product',
'ManyManyListTest_Category',
// From VersionedTest
'VersionedTest_DataObject',
'VersionedTest_Subclass',

View File

@ -32,6 +32,8 @@ class DataObjectTest extends SapphireTest {
'DataObjectTest_Play',
'DataObjectTest_Ploy',
'DataObjectTest_Bogey',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
public function testDb() {

View File

@ -63,6 +63,28 @@ DataObjectTest_TeamComment:
Name: Phil
Comment: Phil is a unique guy, and comments on team2
Team: =>DataObjectTest_Team.team2
ManyManyListTest_Product:
producta:
Title: 'Product A'
productb:
Title: 'Product B'
RelatedProducts: =>ManyManyListTest_Product.producta
ManyManyListTest_Category:
categorya:
Title: 'Category A'
Products: =>ManyManyListTest_Product.producta,=>ManyManyListTest_Product.productb
comment1:
Name: Joe
Comment: This is a team comment by Joe
Team: =>DataObjectTest_Team.team1
comment2:
Name: Bob
Comment: This is a team comment by Bob
Team: =>DataObjectTest_Team.team1
comment3:
Name: Phil
Comment: Phil is a unique guy, and comments on team2
Team: =>DataObjectTest_Team.team2
DataObjectTest_Fan:
fan1:
Name: Damian

View File

@ -11,6 +11,7 @@ class DataQueryTest extends SapphireTest {
'DataQueryTest_D',
'DataQueryTest_E',
'DataQueryTest_F',
'DataQueryTest_G',
);
@ -63,11 +64,39 @@ class DataQueryTest extends SapphireTest {
}
public function testApplyReplationDeepInheretence() {
//test has_one relation
$newDQ = new DataQuery('DataQueryTest_E');
//apply a relation to a relation from an ancestor class
$newDQ->applyRelation('TestA');
$this->assertTrue($newDQ->query()->isJoinedTo('DataQueryTest_C'));
$this->assertContains('"DataQueryTest_A"."ID" = "DataQueryTest_C"."TestAID"', $newDQ->sql($params));
//test many_many relation
//test many_many with separate inheritance
$newDQ = new DataQuery('DataQueryTest_C');
$baseDBTable = ClassInfo::baseDataClass('DataQueryTest_C');
$newDQ->applyRelation('ManyTestAs');
//check we are "joined" to the DataObject's table (there is no distinction between FROM or JOIN clauses)
$this->assertTrue($newDQ->query()->isJoinedTo($baseDBTable));
//check we are explicitly selecting "FROM" the DO's table
$this->assertContains("FROM \"$baseDBTable\"", $newDQ->sql());
//test many_many with shared inheritance
$newDQ = new DataQuery('DataQueryTest_E');
$baseDBTable = ClassInfo::baseDataClass('DataQueryTest_E');
//check we are "joined" to the DataObject's table (there is no distinction between FROM or JOIN clauses)
$this->assertTrue($newDQ->query()->isJoinedTo($baseDBTable));
//check we are explicitly selecting "FROM" the DO's table
$this->assertContains("FROM \"$baseDBTable\"", $newDQ->sql(), 'The FROM clause is missing from the query');
$newDQ->applyRelation('ManyTestGs');
//confirm we are still joined to the base table
$this->assertTrue($newDQ->query()->isJoinedTo($baseDBTable));
//double check it is the "FROM" clause
$this->assertContains("FROM \"$baseDBTable\"", $newDQ->sql(), 'The FROM clause has been removed from the query');
//another (potentially less crude check) for checking "FROM" clause
$fromTables = $newDQ->query()->getFrom();
$this->assertEquals('"' . $baseDBTable . '"', $fromTables[$baseDBTable]);
}
public function testRelationReturn() {
@ -310,6 +339,10 @@ class DataQueryTest_E extends DataQueryTest_C implements TestOnly {
'SortOrder' => 'Int'
);
private static $many_many = array(
'ManyTestGs' => 'DataQueryTest_G',
);
private static $default_sort = '"DataQueryTest_E"."SortOrder" ASC';
}
@ -321,3 +354,11 @@ class DataQueryTest_F extends DataObject implements TestOnly {
'MyString' => 'Text'
);
}
class DataQueryTest_G extends DataQueryTest_C implements TestOnly {
private static $belongs_many_many = array(
'ManyTestEs' => 'DataQueryTest_E',
);
}

View File

@ -28,6 +28,8 @@ class HasManyListTest extends SapphireTest {
'DataObjectTest_Play',
'DataObjectTest_Ploy',
'DataObjectTest_Bogey',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
public function testRelationshipEmptyOnNewRecords() {

View File

@ -34,7 +34,9 @@ class ManyManyListTest extends SapphireTest {
'DataObjectTest_Ploy',
'DataObjectTest_Bogey',
// From ManyManyListTest
'ManyManyListTest_ExtraFields'
'ManyManyListTest_ExtraFields',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
@ -287,6 +289,17 @@ class ManyManyListTest extends SapphireTest {
$this->assertSQLEquals($expected, $list->sql($parameters));
}
public function testFilteringOnPreviouslyJoinedTable() {
/** @var ManyManyListTest_Category $category */
$category = $this->objFromFixture('ManyManyListTest_Category', 'categorya');
/** @var ManyManyList $productsRelatedToProductB */
$productsRelatedToProductB = $category->Products()->filter('RelatedProducts.Title', 'Product B');
$this->assertEquals(1, $productsRelatedToProductB->count());
}
}
@ -311,3 +324,33 @@ class ManyManyListTest_ExtraFields extends DataObject implements TestOnly {
)
);
}
class ManyManyListTest_Product extends DataObject implements TestOnly {
private static $db = array(
'Title' => 'Varchar'
);
private static $many_many = array(
'RelatedProducts' => 'ManyManyListTest_Product'
);
private static $belongs_many_many = array(
'RelatedTo' => 'ManyManyListTest_Product',
'Categories' => 'ManyManyListTest_Category'
);
}
class ManyManyListTest_Category extends DataObject implements TestOnly {
private static $db = array(
'Title' => 'Varchar'
);
private static $many_many = array(
'Products' => 'ManyManyListTest_Product'
);
}

View File

@ -32,6 +32,8 @@ class SS_MapTest extends SapphireTest {
'DataObjectTest_Play',
'DataObjectTest_Ploy',
'DataObjectTest_Bogey',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);

View File

@ -32,6 +32,8 @@ class PaginatedListTest extends SapphireTest {
'DataObjectTest_Play',
'DataObjectTest_Ploy',
'DataObjectTest_Bogey',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
public function testPageStart() {