123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- namespace Elgg\Database;
- class RelationshipsTest extends \PHPUnit_Framework_TestCase {
- private $guids;
-
- /**
- * Create the entities used for each test
- */
- protected function setUp() {
- $this->markTestSkipped("Skipped test as Elgg can not yet run PHP Unit tests that interact with the database");
-
- $this->guids = array();
-
- $obj1 = new \ElggObject();
- $obj1->save();
-
- $this->guids[] = $obj1->guid;
-
- $obj2 = new \ElggObject();
- $obj2->save();
-
- $this->guids[] = $obj2->guid;
-
- }
-
- /**
- * Remove the entities that are created for each test
- */
- protected function tearDown() {
- foreach ($this->guids as $guid) {
- $e = get_entity($guid);
- $e->delete();
- }
- }
-
- /**
- * Check that you can get entities by filtering them on relationship time created lower
- */
- public function testGetEntitiesFromRelationshipFilterByTimeCreatedLower() {
-
- // get a timestamp before creating the relationship
- $ts_lower = time() - 1;
-
- add_entity_relationship($this->guids[0], 'testGetEntitiesFromRelationship', $this->guids[1]);
-
- // get a timestamp after creating the relationship
- $ts_upper = time() + 1;
-
- // check that if ts_lower is before the relationship you get the just created entity
- $options = array(
- 'relationship' => 'testGetEntitiesFromRelationship',
- 'relationship_guid' => $this->guids[0],
- 'relationship_created_time_lower' => $ts_lower
- );
-
- $es = elgg_get_entities_from_relationship($options);
- $this->assertTrue(is_array($es));
- $this->assertIdentical(count($es), 1);
-
- foreach ($es as $e) {
- $this->assertEqual($this->guids[1], $e->guid);
- }
-
- // check that if ts_lower is after the relationship you get no entities
- $options = array(
- 'relationship' => 'testGetEntitiesFromRelationship',
- 'relationship_guid' => $this->guids[0],
- 'relationship_created_time_lower' => $ts_upper
- );
-
- $es = elgg_get_entities_from_relationship($options);
- $this->assertTrue(is_array($es));
- $this->assertIdentical(count($es), 0);
- }
- /**
- * Check that you can get entities by filtering them on relationship time created upper
- */
- public function testGetEntitiesFromRelationshipFilterByTimeCreatedUpper() {
- // get a timestamp before creating the relationship
- $ts_lower = time() - 1;
-
- add_entity_relationship($this->guids[0], 'testGetEntitiesFromRelationship', $this->guids[1]);
-
- // get a timestamp after creating the relationship
- $ts_upper = time() + 1;
-
- // check that if ts_upper is after the relationship you get the just created entity
- $options = array(
- 'relationship' => 'testGetEntitiesFromRelationship',
- 'relationship_guid' => $this->guids[0],
- 'relationship_created_time_upper' => $ts_upper
- );
-
- $es = elgg_get_entities_from_relationship($options);
- $this->assertTrue(is_array($es));
- $this->assertIdentical(count($es), 1);
-
- foreach ($es as $e) {
- $this->assertEqual($this->guids[1], $e->guid);
- }
-
- // check that if ts_upper is before the relationship you get no entities
- $options = array(
- 'relationship' => 'testGetEntitiesFromRelationship',
- 'relationship_guid' => $this->guids[0],
- 'relationship_created_time_upper' => $ts_lower
- );
-
- $es = elgg_get_entities_from_relationship($options);
- $this->assertTrue(is_array($es));
- $this->assertIdentical(count($es), 0);
- }
- /**
- * Check that you can get entities by filtering them on relationship time created lower and upper
- */
- public function testGetEntitiesFromRelationshipFilterByTimeCreatedLowerAndUpper() {
- // get a timestamp before creating the relationship
- $ts_lower = time() - 1;
-
- add_entity_relationship($this->guids[0], 'testGetEntitiesFromRelationship', $this->guids[1]);
-
- // get a timestamp after creating the relationship
- $ts_upper = time() + 1;
-
- // check that if relationship time created is between lower and upper you get the just created entity
- $options = array(
- 'relationship' => 'testGetEntitiesFromRelationship',
- 'relationship_guid' => $this->guids[0],
- 'relationship_created_time_lower' => $ts_lower,
- 'relationship_created_time_upper' => $ts_upper
- );
-
- $es = elgg_get_entities_from_relationship($options);
- $this->assertTrue(is_array($es));
- $this->assertIdentical(count($es), 1);
-
- foreach ($es as $e) {
- $this->assertEqual($this->guids[1], $e->guid);
- }
-
- // check that if ts_lower > ts_upper you get no entities
- $options = array(
- 'relationship' => 'testGetEntitiesFromRelationship',
- 'relationship_guid' => $this->guids[0],
- 'relationship_created_time_lower' => $ts_upper,
- 'relationship_created_time_upper' => $ts_lower
- );
-
- $es = elgg_get_entities_from_relationship($options);
- $this->assertTrue(is_array($es));
- $this->assertIdentical(count($es), 0);
- }
- }
|