|
6 | 6 |
|
7 | 7 | use \Tripod\Mongo\Composites\Views;
|
8 | 8 | use \MongoDB\Client;
|
| 9 | +use Tripod\ExtendedGraph; |
9 | 10 |
|
10 | 11 | class MongoTripodViewsTest extends MongoTripodTestBase {
|
11 | 12 | /**
|
@@ -521,14 +522,15 @@ public function testGenerateViewWithTTL()
|
521 | 522 | $this->assertInstanceOf('\MongoDB\BSON\UTCDateTime', $actualView['_cts']);
|
522 | 523 | }
|
523 | 524 |
|
524 |
| - public function testGenerateViewWithNegativeTTL() |
| 525 | + public function testNonExpiringViewWithNegativeTTL() |
525 | 526 | {
|
526 |
| - /** @var \Tripod\Mongo\Composites\Views|PHPUnit_Framework_MockObject_MockObject $mockTripodViews */ |
527 |
| - $mockTripodViews = $this->getMockBuilder('\Tripod\Mongo\Composites\Views') |
528 |
| - ->setConstructorArgs($this->viewsConstParams) |
529 |
| - ->getMock(); |
| 527 | + $views = new \Tripod\Mongo\Composites\Views( |
| 528 | + $this->viewsConstParams[0], |
| 529 | + $this->viewsConstParams[1], |
| 530 | + $this->viewsConstParams[2] |
| 531 | + ); |
530 | 532 |
|
531 |
| - $view = $mockTripodViews->getViewForResource( |
| 533 | + $view = $views->getViewForResource( |
532 | 534 | 'http://talisaspire.com/events/1234',
|
533 | 535 | 'v_event_no_expiration'
|
534 | 536 | );
|
@@ -575,9 +577,59 @@ public function testGenerateViewWithNegativeTTL()
|
575 | 577 | ]
|
576 | 578 | ]
|
577 | 579 | );
|
578 |
| - $this->assertEquals($expectedView['_id'], $actualView['_id']); |
579 |
| - $this->assertEquals($expectedView['value'], $actualView['value']); |
| 580 | + $this->assertEquals( |
| 581 | + $expectedView['_id'], |
| 582 | + $actualView['_id'], |
| 583 | + '_id does not match expected', |
| 584 | + 0.0, |
| 585 | + 10, |
| 586 | + true |
| 587 | + ); |
| 588 | + $this->assertContains( |
| 589 | + $expectedView['value'][_GRAPHS][0], |
| 590 | + $actualView['value'][_GRAPHS] |
| 591 | + ); |
| 592 | + $this->assertContains( |
| 593 | + $expectedView['value'][_GRAPHS][1], |
| 594 | + $actualView['value'][_GRAPHS] |
| 595 | + ); |
| 596 | + $this->assertCount(2, $actualView['value'][_GRAPHS]); |
| 597 | + $this->assertArrayNotHasKey(_EXPIRES, $actualView['value']); |
| 598 | + $this->assertArrayNotHasKey(_IMPACT_INDEX, $actualView['value']); |
580 | 599 | $this->assertInstanceOf('\MongoDB\BSON\UTCDateTime', $actualView['_cts']);
|
| 600 | + |
| 601 | + // Fetch the joined resource and change it |
| 602 | + $graph = $this->tripod->describeResource('http://talisaspire.com/resources/1234'); |
| 603 | + |
| 604 | + $updatedGraph = new ExtendedGraph($graph->to_ntriples()); |
| 605 | + $updatedGraph->replace_literal_triple( |
| 606 | + 'http://talisaspire.com/resources/1234', |
| 607 | + 'http://purl.org/dc/terms/title', |
| 608 | + 'A real piece of work', |
| 609 | + 'A literal treasure' |
| 610 | + ); |
| 611 | + |
| 612 | + // This should not affect the view at all |
| 613 | + $this->tripod->saveChanges($graph, $updatedGraph); |
| 614 | + |
| 615 | + $view = $views->getViewForResource( |
| 616 | + 'http://talisaspire.com/events/1234', |
| 617 | + 'v_event_no_expiration' |
| 618 | + ); |
| 619 | + |
| 620 | + // get the view direct from mongo, it should the same as earlier |
| 621 | + $actualView2 = \Tripod\Mongo\Config::getInstance() |
| 622 | + ->getCollectionForView('tripod_php_testing', 'v_event_no_expiration') |
| 623 | + ->findOne( |
| 624 | + [ |
| 625 | + '_id' => [ |
| 626 | + 'r' => 'http://talisaspire.com/events/1234', |
| 627 | + 'c' => 'http://talisaspire.com/', |
| 628 | + 'type' => 'v_event_no_expiration' |
| 629 | + ] |
| 630 | + ] |
| 631 | + ); |
| 632 | + $this->assertEquals($actualView, $actualView2); |
581 | 633 | }
|
582 | 634 |
|
583 | 635 | /**
|
|
0 commit comments