Many many bug

This commit is contained in:
Loz Calver 2016-05-10 15:56:15 +01:00 committed by Daniel Hensby
parent dd554d883f
commit 5b275376d3
No known key found for this signature in database
GPG Key ID: B00D1E9767F0B06E
8 changed files with 113 additions and 48 deletions

View File

@ -20,6 +20,8 @@ class DataListTest extends SapphireTest {
'DataObjectTest_Player',
'DataObjectTest_TeamComment',
'DataObjectTest\NamespacedClass',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
public function testFilterDataObjectByCreatedDate() {

View File

@ -23,7 +23,9 @@ class DataObjectLazyLoadingTest extends SapphireTest {
'DataObjectTest_Player',
'DataObjectTest_TeamComment',
'VersionedTest_DataObject',
'VersionedTest_Subclass'
'VersionedTest_Subclass',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
public function testQueriedColumnsID() {
@ -412,4 +414,4 @@ class VersionedLazySub_DataObject extends VersionedLazy_DataObject {
private static $extensions = array(
"Versioned('Stage', 'Live')"
);
}
}

View File

@ -17,7 +17,9 @@ class DataObjectTest extends SapphireTest {
'DataObjectTest_ValidatedObject',
'DataObjectTest_Player',
'DataObjectTest_TeamComment',
'DataObjectTest_ExtendedTeamComment'
'DataObjectTest_ExtendedTeamComment',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
public function testDb() {

View File

@ -1,47 +1,57 @@
DataObjectTest_Team:
team1:
Title: Team 1
team2:
Title: Team 2
team3:
Title: Team 3
team1:
Title: Team 1
team2:
Title: Team 2
team3:
Title: Team 3
DataObjectTest_Player:
captain1:
FirstName: Captain
ShirtNumber: 007
FavouriteTeam: =>DataObjectTest_Team.team1
Teams: =>DataObjectTest_Team.team1
IsRetired: 1
captain2:
FirstName: Captain 2
Teams: =>DataObjectTest_Team.team2
player1:
FirstName: Player 1
player2:
FirstName: Player 2
Teams: =>DataObjectTest_Team.team1,=>DataObjectTest_Team.team2
captain1:
FirstName: Captain
ShirtNumber: 007
FavouriteTeam: =>DataObjectTest_Team.team1
Teams: =>DataObjectTest_Team.team1
IsRetired: 1
captain2:
FirstName: Captain 2
Teams: =>DataObjectTest_Team.team2
player1:
FirstName: Player 1
player2:
FirstName: Player 2
Teams: =>DataObjectTest_Team.team1,=>DataObjectTest_Team.team2
DataObjectTest_SubTeam:
subteam1:
Title: Subteam 1
SubclassDatabaseField: Subclassed 1
ExtendedDatabaseField: Extended 1
ParentTeam: =>DataObjectTest_Team.team1
subteam2_with_player_relation:
Title: Subteam 2
SubclassDatabaseField: Subclassed 2
ExtendedHasOneRelationship: =>DataObjectTest_Player.player1
subteam3_with_empty_fields:
Title: Subteam 3
subteam1:
Title: Subteam 1
SubclassDatabaseField: Subclassed 1
ExtendedDatabaseField: Extended 1
ParentTeam: =>DataObjectTest_Team.team1
subteam2_with_player_relation:
Title: Subteam 2
SubclassDatabaseField: Subclassed 2
ExtendedHasOneRelationship: =>DataObjectTest_Player.player1
subteam3_with_empty_fields:
Title: Subteam 3
DataObjectTest_TeamComment:
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
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
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

View File

@ -9,6 +9,8 @@ class HasManyListTest extends SapphireTest {
'DataObjectTest_Team',
'DataObjectTest_SubTeam',
'DataObjectTest_Player',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
public function testRelationshipEmptyOnNewRecords() {

View File

@ -15,6 +15,8 @@ class ManyManyListTest extends SapphireTest {
'DataObjectTest_Company',
'DataObjectTest_TeamComment',
'ManyManyListTest_ExtraFields',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
@ -267,6 +269,17 @@ class ManyManyListTest extends SapphireTest {
$this->assertEquals($expected, $list->sql());
}
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());
}
}
@ -291,3 +304,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

@ -18,7 +18,9 @@ class SS_MapTest extends SapphireTest {
'DataObjectTest_FieldlessSubTable',
'DataObjectTest_ValidatedObject',
'DataObjectTest_Player',
'DataObjectTest_TeamComment'
'DataObjectTest_TeamComment',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);

View File

@ -12,7 +12,9 @@ class PaginatedListTest extends SapphireTest {
protected $extraDataObjects = array(
'DataObjectTest_Team',
'DataObjectTest_SubTeam',
'DataObjectTest_Player'
'DataObjectTest_Player',
'ManyManyListTest_Product',
'ManyManyListTest_Category',
);
public function testPageStart() {