getMock() public static method

Get an isolated ElggSession that does not persist between requests
public static getMock ( ) : self
return self
Esempio n. 1
0
 /**
  * Constructor
  */
 public function __construct()
 {
     $sp = _elgg_services();
     $this->setValue('session', \ElggSession::getMock());
     $this->setFactory('db', function (MockServiceProvider $m) use($sp) {
         $config = $this->getTestingDatabaseConfig();
         return new \Elgg\Mocks\Database($config, $sp->logger);
     });
     $this->setFactory('entityTable', function (MockServiceProvider $m) use($sp) {
         return new \Elgg\Mocks\Database\EntityTable($sp->config, $m->db, $sp->entityCache, $sp->metadataCache, $m->subtypeTable, $sp->events, $sp->session, $sp->translator, $sp->logger);
     });
     $this->setFactory('metadataTable', function (MockServiceProvider $m) use($sp) {
         return new \Elgg\Mocks\Database\MetadataTable($sp->metadataCache, $m->db, $m->entityTable, $sp->events, $m->session);
     });
     $this->setFactory('annotations', function (MockServiceProvider $m) use($sp) {
         return new \Elgg\Mocks\Database\Annotations($m->db, $m->session, $sp->events);
     });
     $this->setFactory('relationshipsTable', function (MockServiceProvider $m) use($sp) {
         return new \Elgg\Mocks\Database\RelationshipsTable($m->db, $m->entityTable, $m->metadataTable, $sp->events);
     });
     $this->setFactory('subtypeTable', function (MockServiceProvider $m) {
         return new \Elgg\Mocks\Database\SubtypeTable($m->db);
     });
     $this->setFactory('accessCollections', function (MockServiceProvider $m) use($sp) {
         return new \Elgg\Mocks\Database\AccessCollections($sp->config, $m->db, $m->entityTable, $sp->accessCache, $sp->hooks, $sp->session, $sp->translator);
     });
     $this->setFactory('privateSettings', function (MockServiceProvider $m) use($sp) {
         return new \Elgg\Mocks\Database\PrivateSettingsTable($m->db, $m->entityTable, $sp->pluginSettingsCache);
     });
 }
Esempio n. 2
0
 public function setUp()
 {
     _elgg_filestore_init();
     // we will need simpletype hook to work
     $this->hooks = new \Elgg\PluginHooksService();
     $path_key = \Elgg\Application::GET_PATH_KEY;
     $this->request = \Elgg\Http\Request::create("?{$path_key}=action/upload");
     $this->logger = new \Elgg\Logger($this->hooks, $this->config(), new \Elgg\Context());
     $this->setupMockServices(false);
     $this->entities = _elgg_services()->entityTable;
     $this->user = $this->mocks()->getUser();
     $this->entity = $this->mocks()->getObject(['owner_guid' => $this->user->guid, 'subtype' => 'foo']);
     $dir = (new \Elgg\EntityDirLocator($this->entity->guid))->getPath();
     $this->entity_dir_path = $this->config()->get('dataroot') . $dir;
     if (is_dir($this->entity_dir_path)) {
         _elgg_rmdir($this->entity_dir_path);
     }
     $dir = (new \Elgg\EntityDirLocator($this->entity->owner_guid))->getPath();
     $this->owner_dir_path = $this->config()->get('dataroot') . $dir;
     if (is_dir($this->owner_dir_path)) {
         _elgg_rmdir($this->owner_dir_path);
     }
     // Needed to test elgg_get_inline_url()
     $session = \ElggSession::getMock();
     _elgg_services()->setValue('session', $session);
     _elgg_services()->session->start();
 }
Esempio n. 3
0
 public function setUp()
 {
     // required by \ElggEntity when setting the owner/container
     _elgg_services()->setValue('session', \ElggSession::getMock());
     $this->obj = $this->getMockBuilder('\\ElggUpgrade')->setMethods(null)->getMock();
     $this->obj->_callable_egefps = array($this, 'mock_egefps');
 }
Esempio n. 4
0
 public function setUp()
 {
     $this->hooks = new \Elgg\PluginHooksService();
     $this->queue = new \Elgg\Queue\MemoryQueue();
     $dbMock = $this->getMockBuilder('\\Elgg\\Database')->disableOriginalConstructor()->getMock();
     $this->sub = new \Elgg\Notifications\SubscriptionsService($dbMock);
     $this->session = \ElggSession::getMock();
     // Event class has dependency on elgg_get_logged_in_user_guid()
     _elgg_services()->setValue('session', $this->session);
 }
Esempio n. 5
0
 public function setUp()
 {
     $this->viewsDir = dirname(dirname(__FILE__)) . "/test_files/views";
     $this->hooks = new \Elgg\PluginHooksService();
     $this->logger = $this->getMock('\\Elgg\\Logger', array(), array(), '', false);
     $this->views = new \Elgg\ViewsService($this->hooks, $this->logger);
     $this->views->autoregisterViews('', "{$this->viewsDir}/default", 'default');
     // supports deprecation wrapper for $vars['user']
     _elgg_services()->setValue('session', \ElggSession::getMock());
 }
Esempio n. 6
0
 public function testMigrate()
 {
     $session = \ElggSession::getMock();
     $session->start();
     $session->set('foo', 5);
     $id = $session->getId();
     $this->assertTrue($session->migrate());
     $this->assertTrue($session->has('foo'));
     $this->assertNotEquals($id, $session->getId());
     $this->assertTrue($session->has('__elgg_session'));
 }
Esempio n. 7
0
 public function setUp()
 {
     $session = \ElggSession::getMock();
     _elgg_services()->setValue('session', $session);
     _elgg_services()->session->start();
     $this->handler = _elgg_services()->serveFileHandler;
     $file = new \ElggFile();
     $file->owner_guid = 1;
     $file->setFilename("foobar.txt");
     $this->file = $file;
 }
Esempio n. 8
0
 protected function setUp()
 {
     _elgg_services()->setValue('session', \ElggSession::getMock());
     $this->obj = $this->getMockForAbstractClass('\\ElggEntity');
     $reflection = new ReflectionClass('\\ElggEntity');
     $method = $reflection->getMethod('initializeAttributes');
     if (method_exists($method, 'setAccessible')) {
         $method->setAccessible(true);
         $method->invokeArgs($this->obj, array());
     }
 }
Esempio n. 9
0
 public function testPropertiesReturnCorrectClassNames()
 {
     $mgr = $this->getMock('\\Elgg\\AutoloadManager', array(), array(), '', false);
     $sp = new \Elgg\Di\ServiceProvider($mgr);
     $sp->setValue('session', \ElggSession::getMock());
     $svcClasses = array('accessCache' => '\\ElggStaticVariableCache', 'accessCollections' => '\\Elgg\\Database\\AccessCollections', 'actions' => '\\Elgg\\ActionsService', 'adminNotices' => '\\Elgg\\Database\\AdminNotices', 'annotations' => '\\Elgg\\Database\\Annotations', 'autoP' => '\\ElggAutoP', 'autoloadManager' => '\\Elgg\\AutoloadManager', 'config' => '\\Elgg\\Config', 'configTable' => '\\Elgg\\Database\\ConfigTable', 'context' => '\\Elgg\\Context', 'datalist' => '\\Elgg\\Database\\Datalist', 'db' => '\\Elgg\\Database', 'entityTable' => '\\Elgg\\Database\\EntityTable', 'events' => '\\Elgg\\EventsService', 'externalFiles' => '\\Elgg\\Assets\\ExternalFiles', 'hooks' => '\\Elgg\\PluginHooksService', 'input' => '\\Elgg\\Http\\Input', 'logger' => '\\Elgg\\Logger', 'metadataCache' => '\\Elgg\\Cache\\MetadataCache', 'metadataTable' => '\\Elgg\\Database\\MetadataTable', 'metastringsTable' => '\\Elgg\\Database\\MetastringsTable', 'passwords' => '\\Elgg\\PasswordService', 'plugins' => '\\Elgg\\Database\\Plugins', 'request' => '\\Elgg\\Http\\Request', 'relationshipsTable' => '\\Elgg\\Database\\RelationshipsTable', 'router' => '\\Elgg\\Router', 'session' => '\\ElggSession', 'simpleCache' => '\\Elgg\\Cache\\SimpleCache', 'siteSecret' => '\\Elgg\\Database\\SiteSecret', 'stickyForms' => '\\Elgg\\Forms\\StickyForms', 'subtypeTable' => '\\Elgg\\Database\\SubtypeTable', 'systemCache' => '\\Elgg\\Cache\\SystemCache', 'translator' => '\\Elgg\\I18n\\Translator', 'usersTable' => '\\Elgg\\Database\\UsersTable', 'views' => '\\Elgg\\ViewsService', 'widgets' => '\\Elgg\\WidgetsService');
     foreach ($svcClasses as $key => $class) {
         $obj1 = $sp->{$key};
         $obj2 = $sp->{$key};
         $this->assertInstanceOf($class, $obj1);
         $this->assertSame($obj1, $obj2);
     }
 }
Esempio n. 10
0
 function setUp()
 {
     $this->thirtyDaysAgo = strtotime("-30 days");
     $this->mockToken = 'z' . str_repeat('a', 31);
     $this->mockHash = md5($this->mockToken);
     $this->user123 = $this->getMockElggUser(123);
     $this->session = \ElggSession::getMock();
     // mock DB
     $this->dbMock = $this->getMockBuilder('\\Elgg\\Database')->disableOriginalConstructor()->getMock();
     // use addslashes as ->sanitizeString (my local CLI doesn't have MySQL)
     $this->dbMock->expects($this->any())->method('sanitizeString')->will($this->returnCallback(array($this, 'mock_sanitizeString')));
     $this->cryptoMock = $this->getMockBuilder('\\ElggCrypto')->setConstructorArgs([_elgg_services()->siteSecret])->getMock();
     $this->cryptoMock->expects($this->any())->method('getRandomString')->will($this->returnValue(str_repeat('a', 31)));
     $this->svc = $this->getSvcWithCookie("");
 }
Esempio n. 11
0
 public function setUp()
 {
     $this->containerGuid = 42;
     // mock \ElggObject that has a container guid
     $object = $this->getMock('\\ElggObject', array('getContainerGUID'), array(), '', false);
     $object->expects($this->any())->method('getContainerGUID')->will($this->returnValue($this->containerGuid));
     // mock event that holds the mock object
     $this->event = $this->getMock('\\Elgg\\Notifications\\Event', array('getObject'), array(), '', false);
     $this->event->expects($this->any())->method('getObject')->will($this->returnValue($object));
     $this->db = $this->getMock('\\Elgg\\Database', array('getData', 'getTablePrefix', 'sanitizeString'), array(), '', false);
     $this->db->expects($this->any())->method('getTablePrefix')->will($this->returnValue('elgg_'));
     $this->db->expects($this->any())->method('sanitizeString')->will($this->returnArgument(0));
     // Event class has dependency on elgg_get_logged_in_user_guid()
     _elgg_services()->setValue('session', \ElggSession::getMock());
 }
Esempio n. 12
0
 public function testCanSetLoggedInUser()
 {
     $user = $this->getMockBuilder(\ElggUser::class)->setMethods(['__get'])->disableOriginalConstructor()->getMock();
     $user->expects($this->any())->method('__get')->will($this->returnCallback(function ($name) {
         if ($name == 'guid') {
             return 123;
         }
     }));
     $session = \ElggSession::getMock();
     $session->setLoggedInUser($user);
     $this->assertEquals($user, $session->getLoggedInUser());
     $this->assertEquals(123, $session->getLoggedInUserGuid());
     $session->removeLoggedInUser();
     $this->assertNull($session->getLoggedInUser());
 }
Esempio n. 13
0
 protected function setUp()
 {
     _elgg_filestore_init();
     $session = \ElggSession::getMock();
     _elgg_services()->setValue('session', $session);
     _elgg_services()->session->start();
     $file = new \ElggFile();
     $file->owner_guid = 1;
     $file->setFilename("foobar.txt");
     $this->file = $file;
     $dataroot = elgg_get_config('dataroot');
     if (is_dir($dataroot . '1/2/')) {
         // we use this for writing new files
         _elgg_rmdir($dataroot . '1/2/');
     }
 }
Esempio n. 14
0
 public function setUp()
 {
     $app = _elgg_testing_application();
     $dataroot = _elgg_testing_config()->getDataPath();
     $session = \ElggSession::getMock();
     _elgg_services()->setValue('session', $session);
     _elgg_services()->session->start();
     $site_secret_mock = $this->getMockBuilder('\\Elgg\\Database\\SiteSecret')->getMock();
     $site_secret_mock->method('init')->willReturn('strongSiteSecret1234567890');
     _elgg_services()->setValue('siteSecret', $site_secret_mock);
     $this->handler = new ServeFileHandler($app);
     $file_mock = $this->getMockBuilder('\\ElggFile')->disableOriginalConstructor()->getMock();
     $file_mock->method('getFileNameOnFilestore')->willReturn("{$dataroot}file_service/foobar.txt");
     $file_mock->method('exists')->willReturn(true);
     $this->file = $file_mock;
 }
Esempio n. 15
0
 /**
  * Constructor bootstraps the Elgg engine
  */
 public function __construct()
 {
     global $CONFIG;
     if (!isset($CONFIG)) {
         $CONFIG = new stdClass();
     }
     $this->CONFIG = $CONFIG;
     $this->isAction = isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST';
     $this->bootstrapConfig();
     $this->bootstrapEngine();
     _elgg_services()->setValue('session', \ElggSession::getMock());
     elgg_set_viewtype('installation');
     set_error_handler('_elgg_php_error_handler');
     set_exception_handler('_elgg_php_exception_handler');
     _elgg_services()->translator->registerTranslations("{$this->getElggRoot()}/install/languages/", TRUE);
 }
 public function setUp()
 {
     $this->hooks = new \Elgg\PluginHooksService();
     $this->queue = new \Elgg\Queue\MemoryQueue();
     $dbMock = $this->getMockBuilder('\\Elgg\\Database')->disableOriginalConstructor()->getMock();
     $this->sub = new \Elgg\Notifications\SubscriptionsService($dbMock);
     $this->translator = new \Elgg\I18n\Translator();
     $this->session = \ElggSession::getMock();
     // User mock that supports calling $user->isBanned()
     $user_123 = $this->getMockBuilder('\\ElggEntity')->disableOriginalConstructor()->getMock();
     $user_123->expects($this->any())->method('isBanned')->will($this->returnValue(false));
     // Database mock that returns the user_123
     $this->entities = $this->getMockBuilder('\\Elgg\\Database\\EntityTable')->disableOriginalConstructor()->getMock();
     $this->entities->expects($this->any())->method('get')->with($this->equalTo('123'))->will($this->returnValue($user_123));
     // Event class has dependency on elgg_get_logged_in_user_guid()
     _elgg_services()->setValue('session', $this->session);
 }
Esempio n. 17
0
 public function setUp()
 {
     $this->user = $this->mocks()->getUser();
     $this->owner_guid = $this->user->guid;
     $dir = (new EntityDirLocator($this->owner_guid))->getPath();
     $this->owner_dir_path = elgg_get_config('dataroot') . $dir;
     _elgg_services()->hooks->backup();
     _elgg_services()->events->backup();
     _elgg_filestore_init();
     // we will need simpletype hook to work
     // Events service is trying to connect to the DB
     _elgg_services()->events->unregisterHandler('all', 'all', 'system_log_listener');
     _elgg_services()->events->unregisterHandler('log', 'systemlog', 'system_log_default_logger');
     $request = $this->prepareHttpRequest();
     _elgg_services()->setValue('request', $request);
     _elgg_services()->setValue('uploads', new UploadService($request));
     $session = \ElggSession::getMock();
     _elgg_services()->setValue('session', $session);
     _elgg_services()->session->start();
 }
Esempio n. 18
0
 /**
  * Constructor bootstraps the Elgg engine
  */
 public function __construct()
 {
     global $CONFIG;
     if (!isset($CONFIG)) {
         $CONFIG = new stdClass();
     }
     global $_ELGG;
     if (!isset($_ELGG)) {
         $_ELGG = new stdClass();
     }
     $this->CONFIG = $CONFIG;
     $this->isAction = isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] === 'POST';
     $this->bootstrapConfig();
     $this->bootstrapEngine();
     _elgg_services()->setValue('session', \ElggSession::getMock());
     elgg_set_viewtype('installation');
     set_error_handler('_elgg_php_error_handler');
     set_exception_handler('_elgg_php_exception_handler');
     _elgg_services()->config->set('simplecache_enabled', false);
     _elgg_services()->translator->registerTranslations(\Elgg\Application::elggDir()->getPath("/install/languages/"), TRUE);
     _elgg_services()->views->registerPluginViews(\Elgg\Application::elggDir()->getPath("/"));
 }
Esempio n. 19
0
 public function testClearActsOnAllAccessStates()
 {
     $session = ElggSession::getMock();
     $cache = new MetadataCache($session);
     $session->setIgnoreAccess(false);
     $cache->inject(1, ['foo' => 'bar']);
     $session->setIgnoreAccess(true);
     $cache->clear(1);
     $session->setIgnoreAccess(false);
     $this->assertFalse($cache->isLoaded(1));
     $session->setIgnoreAccess(true);
     $cache->inject(1, ['foo' => 'bar']);
     $session->setIgnoreAccess(false);
     $cache->clear(1);
     $session->setIgnoreAccess(true);
     $this->assertFalse($cache->isLoaded(1));
 }
Esempio n. 20
0
 protected function setUp()
 {
     // required by \ElggEntity when setting the owner/container
     _elgg_services()->setValue('session', \ElggSession::getMock());
 }
Esempio n. 21
0
 public function testLoggedOutUser()
 {
     $originalSession = _elgg_services()->session;
     _elgg_services()->setValue('session', \ElggSession::getMock());
     $sql = _elgg_get_access_where_sql();
     $access_clause = $this->getLoggedOutAccessListClause('e');
     $ans = "(({$access_clause}) AND (e.enabled = 'yes'))";
     $this->assertTrue($this->assertSqlEqual($ans, $sql), "{$sql} does not match {$ans}");
     _elgg_services()->setValue('session', $originalSession);
 }
Esempio n. 22
0
 function setup()
 {
     $this->session = \ElggSession::getMock();
     $this->svc = new SystemMessagesService($this->session);
 }
Esempio n. 23
0
 public function setUp()
 {
     $this->service = new UrlSigner();
     $this->url = '/foo?a=b&c[]=1&c[]=2&c[]=0,5&_d=@username&e=%20';
     _elgg_services()->setValue('session', \ElggSession::getMock());
 }
Esempio n. 24
0
 public function setUp()
 {
     $sp = _elgg_services();
     $sp->setValue('session', \ElggSession::getMock());
 }
Esempio n. 25
0
 public function testLoggedOutUser()
 {
     $sp = _elgg_services();
     $original_session = $sp->session;
     $original_access = $sp->accessCollections;
     $sp->setValue('session', \ElggSession::getMock());
     $sp->setValue('accessCollections', new \Elgg\Database\AccessCollections($sp->config, $sp->db, $sp->entityTable, $sp->accessCache, $sp->hooks, $sp->session, $sp->translator));
     $sql = _elgg_get_access_where_sql();
     $access_clause = $this->getLoggedOutAccessListClause('e');
     $ans = "(({$access_clause}) AND (e.enabled = 'yes'))";
     $this->assertTrue($this->assertSqlEqual($ans, $sql), "{$sql} does not match {$ans}");
     $sp->setValue('session', $original_session);
     $sp->setValue('accessCollections', $original_access);
 }