/**
  * @dataProvider GetTestGetTransparentAuthenticationCredentials
  */
 public function testGetTransparentAuthenticationCredentials($inputData, $serverGlobals, $shouldSucceed)
 {
     $input = static::$container->input;
     // Clear input data
     ReflectionHelper::setValue($input, 'data', array());
     // Push input data if so defined
     if (!is_null($inputData)) {
         ReflectionHelper::setValue($input, 'data', $inputData);
     }
     // Override server globals if necessary
     if (!is_null($serverGlobals)) {
         foreach ($serverGlobals as $k => $v) {
             $_SERVER[$k] = $v;
         }
     }
     // Decode the transparent authentication information
     $result = $this->auth->getTransparentAuthenticationCredentials();
     if ($shouldSucceed) {
         $this->assertInternalType('array', $result);
         $this->assertArrayHasKey('username', $result);
         $this->assertArrayHasKey('password', $result);
         $this->assertEquals('FOF30test', $result['username']);
         $this->assertEquals('dummy', $result['password']);
     } else {
         $this->assertNull($result);
     }
 }
Example #2
0
 /**
  * @covers  FOF30\Timer\Timer::resetTime
  */
 public function testResetTime()
 {
     FakeTimer::$microtime = 123456;
     $timer = new Timer(8, 33);
     FakeTimer::$microtime = 876543.21;
     $timer->resetTime();
     $this->assertEquals(876543.21, ReflectionHelper::getValue($timer, 'start_time'), 'Resetting the timer must read a new value from microtime', 1.0E-10);
 }
Example #3
0
 /**
  * @group       AbstractFilter
  * @group       AbstractFilterConstruct
  * @covers      FOF30\Model\DataModel\Filter\AbstractFilter::__construct
  */
 public function test__construct()
 {
     $db = \JFactory::getDbo();
     $field = (object) array('name' => 'test', 'type' => 'test');
     $filter = new FilterStub($db, $field);
     $this->assertEquals('test', ReflectionHelper::getValue($filter, 'name'), 'AbstractFilter::__construct Failed to set the field name');
     $this->assertEquals('test', ReflectionHelper::getValue($filter, 'type'), 'AbstractFilter::__construct Failed to set the fiel type');
 }
Example #4
0
 /**
  * @group           HasMany
  * @group           HasManyConstruct
  * @covers          FOF30\Model\DataModel\Relation\HasMany::__construct
  * @dataProvider    HasManyDataprovider::getTestConstruct
  */
 public function testConstruct($test, $check)
 {
     $msg = 'HasMany::__construct %s - Case: ' . $check['case'];
     $model = $this->buildModel();
     $relation = new HasMany($model, 'Children', $test['local'], $test['foreign']);
     $this->assertEquals($check['local'], ReflectionHelper::getValue($relation, 'localKey'), sprintf($msg, 'Failed to set the local key'));
     $this->assertEquals($check['foreign'], ReflectionHelper::getValue($relation, 'foreignKey'), sprintf($msg, 'Failed to set the foreign key'));
 }
Example #5
0
 /**
  * @group       RelationFilter
  * @group       RelationFilterConstruct
  * @covers      FOF30\Model\DataModel\Filter\Relation::__construct
  */
 public function test__construct()
 {
     $subquery = \JFactory::getDbo()->getQuery(true);
     $subquery->select('*')->from('test');
     $filter = new Relation(\JFactory::getDbo(), 'foo', $subquery);
     $this->assertEquals('foo', ReflectionHelper::getValue($filter, 'name'), 'Relation::__construct Failed to set filter name');
     $this->assertEquals('relation', ReflectionHelper::getValue($filter, 'type'), 'Relation::__construct Failed to set filter type');
     $this->assertEquals($subquery, ReflectionHelper::getValue($filter, 'subQuery'), 'Relation::__construct Failed to set the subQuery field');
 }
Example #6
0
 /**
  * @covers  FOF30\Download\Adapter\Fopen::__construct
  */
 public function testConstructor()
 {
     $adapter = new Fopen();
     $this->assertInstanceOf('FOF30\\Download\\Adapter\\Fopen', $adapter, 'Adapter must match correct object type');
     $this->assertEquals(100, ReflectionHelper::getValue($adapter, 'priority'), 'Adapter priority must match');
     $this->assertEquals(false, ReflectionHelper::getValue($adapter, 'supportsFileSize'), 'Adapter must not support file size');
     $this->assertEquals(true, ReflectionHelper::getValue($adapter, 'supportsChunkDownload'), 'Adapter must support chunked download');
     $this->assertEquals('fopen', ReflectionHelper::getValue($adapter, 'name'), 'Adapter must have the correct name');
     $this->assertEquals(true, ReflectionHelper::getValue($adapter, 'isSupported'), 'Adapter must be supported');
 }
Example #7
0
 /**
  * @group           Behaviour
  * @group           EnabledOnBeforeBuildQuery
  * @covers          FOF30\Model\DataModel\Behaviour\Enabled::onBeforeBuildQuery
  * @dataProvider    EnabledDataprovider::getTestOnBeforeBuildQuery
  */
 public function testOnBeforeBuildQuery($test, $check)
 {
     $msg = 'Own::onAfterBuildQuery %s - Case: ' . $check['case'];
     $config = array('idFieldName' => $test['tableid'], 'tableName' => $test['table']);
     $model = new DataModelStub(static::$container, $config);
     $query = \JFactory::getDbo()->getQuery(true)->select('*')->from('test');
     $dispatcher = $model->getBehavioursDispatcher();
     $behavior = new Enabled($dispatcher);
     $behavior->onBeforeBuildQuery($model, $query);
     $where = ReflectionHelper::getValue($model, 'whereClauses');
     $this->assertCount($check['count'], $where, sprintf($msg, 'Failed to set the where'));
 }
Example #8
0
 /**
  * @covers FOF30\Download\Download::setAdapter
  *
  * @dataProvider    FOF30\Tests\Download\DownloadDataprovider::getTestSetAdapter
  */
 public function testSetAdapter($className, $shouldChange = true)
 {
     $download = new Download(static::$container);
     $download->setAdapter('curl');
     $this->assertInstanceOf('\\FOF30\\Download\\Adapter\\Curl', ReflectionHelper::getValue($download, 'adapter'), 'Initially forced adapter should be cURL');
     $download->setAdapter($className);
     if ($shouldChange) {
         $this->assertNotInstanceOf('\\FOF30\\Download\\Adapter\\Curl', ReflectionHelper::getValue($download, 'adapter'), 'Forced adapter should be NOT still be cURL');
     } else {
         $this->assertInstanceOf('\\FOF30\\Download\\Adapter\\Curl', ReflectionHelper::getValue($download, 'adapter'), 'Forced adapter should still be cURL');
     }
 }
Example #9
0
 /**
  * @covers  FOF30\Database\Installer::__construct
  * @covers  FOF30\Database\Installer::updateSchema
  * @covers  FOF30\Database\Installer::findSchemaXml
  * @covers  FOF30\Database\Installer::openAndVerify
  * @covers  FOF30\Database\Installer::conditionMet
  *
  * @throws \Exception
  */
 public function testCreateNewTable()
 {
     $db = static::$container->db;
     $tables = $db->setQuery('SHOW TABLES')->loadColumn();
     $prefix = $db->getPrefix();
     $this->assertFalse(in_array($prefix . 'foobar_example', $tables), 'The table must not exist before testing starts');
     $installer = new Installer($db, __DIR__ . '/../_data/installer/pick_right');
     ReflectionHelper::setValue($installer, 'allTables', array());
     $installer->updateSchema();
     $tables = $db->setQuery('SHOW TABLES')->loadColumn();
     $prefix = $db->getPrefix();
     $this->assertTrue(in_array($prefix . 'foobar_example', $tables), 'The table must exist after running updateSchema');
 }
Example #10
0
 /**
  * @covers          FOF30\Dispatcher\Dispatcher::__construct
  * @dataProvider    DispatcherDataprovider::getTest__construct
  */
 public function test__construct($test, $check)
 {
     $msg = 'Dispatcher::__construct %s - Case: ' . $check['case'];
     $container = new TestContainer(array('input' => new Input($test['mock']['input'])));
     $config = array();
     if ($test['mock']['defaultView']) {
         $config['defaultView'] = $test['mock']['defaultView'];
     }
     $dispatcher = new Dispatcher($container, $config);
     $defView = ReflectionHelper::getValue($dispatcher, 'defaultView');
     $view = ReflectionHelper::getValue($dispatcher, 'view');
     $layout = ReflectionHelper::getValue($dispatcher, 'layout');
     $containerView = $container->input->get('view', null);
     $this->assertEquals($check['defaultView'], $defView, sprintf($msg, 'Failed to set the default view'));
     $this->assertEquals($check['view'], $view, sprintf($msg, 'Failed to set the view'));
     $this->assertEquals($check['layout'], $layout, sprintf($msg, 'Failed to set the layout'));
     $this->assertEquals($check['containerView'], $containerView, sprintf($msg, 'Failed to correctly update the container input'));
 }
Example #11
0
 /**
  * @covers        FOF30\Input\Input::__construct
  *
  * @dataProvider  FOF30\Tests\Input\InputProvider::getTestConstructor
  *
  * @backupGlobals enabled
  */
 public function testConstructor($source, $superGlobals, $match, $message)
 {
     // Initialise superglobals for this test
     $_GET = isset($superGlobals['get']) ? $superGlobals['get'] : array();
     $_POST = isset($superGlobals['post']) ? $superGlobals['post'] : array();
     $_FILES = isset($superGlobals['files']) ? $superGlobals['files'] : array();
     $_COOKIE = isset($superGlobals['cookie']) ? $superGlobals['cookie'] : array();
     $_ENV = isset($superGlobals['env']) ? $superGlobals['env'] : array();
     $_SERVER = isset($superGlobals['server']) ? $superGlobals['server'] : array();
     $_REQUEST = isset($superGlobals['request']) ? $superGlobals['request'] : array();
     $input = new Input($source);
     $data = ReflectionHelper::getValue($input, 'data');
     $this->assertInternalType('array', $data, $message);
     foreach ($match as $k => $v) {
         $this->assertArrayHasKey($k, $data, $message);
         $this->assertEquals($v, $data[$k], $message);
     }
 }
Example #12
0
 /**
  * @covers  FOF30\Layout\LayoutFile::getPath
  *
  * @dataProvider FOF30\Tests\Layout\LayoutFileTestProvider::getTestGetPath
  *
  * @param string $layoutId      The layout to load
  * @param array  $platformSetup Platform setup (baseDirs, template, templateSuffixes)
  * @param string $expectedPath  The expected path which should be returned
  * @param string $message       Failure message
  */
 public function testGetPath($layoutId, $platformSetup, $expectedPath, $message)
 {
     // Set up the platform
     $defaultPlatformSetup = array('baseDirs' => null, 'template' => null, 'templateSuffixes' => null);
     if (!is_array($platformSetup)) {
         $platformSetup = array();
     }
     $platformSetup = array_merge($defaultPlatformSetup, $platformSetup);
     $reflector = new \ReflectionClass('FOF30\\Tests\\Helpers\\TestJoomlaPlatform');
     foreach ($platformSetup as $k => $v) {
         $reflector->setStaticPropertyValue($k, $v);
     }
     unset($reflector);
     // Set up a fake options JRegistry object
     $fakeOptions = new \JRegistry(array('option' => 'com_foobar', 'client' => 0));
     $fakeBase = realpath(__DIR__ . '/../_data/layout/base');
     // Create the layout file object
     $layoutFile = new LayoutFile($layoutId, $fakeBase, $fakeOptions);
     $layoutFile->container = static::$container;
     // Call the protected method. Dirty, but that's what we have to test without loading and displaying an actual
     // PHP file.
     $actual = ReflectionHelper::invoke($layoutFile, 'getPath');
     $this->assertEquals($expectedPath, $actual, $message);
 }
Example #13
0
 /**
  * @covers          FOF30\Factory\Magic\ControllerFactory::make
  * @dataProvider    ControllerFactoryDataprovider::getTestMake
  */
 public function testMake($test, $check)
 {
     $msg = 'ControllerFactory::make %s - Case: ' . $check['case'];
     $config['componentName'] = $test['component'];
     if ($test['backend_path']) {
         $config['backEndPath'] = $test['backend_path'];
     }
     $container = new TestContainer($config);
     // Required so we force FOF to read the fof.xml file
     $dummy = $container->appConfig;
     $factory = new ControllerFactory($container);
     if ($check['exception']) {
         $this->setExpectedException('FOF30\\Factory\\Exception\\ControllerNotFound');
     }
     $result = $factory->make($test['name'], $test['config']);
     $this->assertEquals($check['result'], get_class($result), sprintf($msg, 'Returned the wrong result'));
     $this->assertEquals($check['autoRouting'], ReflectionHelper::getValue($result, 'autoRouting'), sprintf($msg, 'Failed to set the autorouting'));
     $this->assertEquals($check['csrf'], ReflectionHelper::getValue($result, 'csrfProtection'), sprintf($msg, 'Failed to set the csrfProtection'));
     $this->assertEquals($check['view'], ReflectionHelper::getValue($result, 'viewName'), sprintf($msg, 'Failed to set the viewName'));
     $this->assertEquals($check['model'], ReflectionHelper::getValue($result, 'modelName'), sprintf($msg, 'Failed to set the modelName'));
     $this->assertEquals($check['priv'], ReflectionHelper::getValue($result, 'taskPrivileges'), sprintf($msg, 'Failed to set the taskPrivileges'));
     $this->assertEquals($check['cache'], ReflectionHelper::getValue($result, 'cacheableTasks'), sprintf($msg, 'Failed to set the cacheableTasks'));
     $this->assertEquals($check['taskMap'], ReflectionHelper::getValue($result, 'taskMap'), sprintf($msg, 'Failed to set the taskMap'));
 }
Example #14
0
 /**
  * @covers FOF30\Platform\Joomla\Platform::getTemplateOverridePath
  *
  * @dataProvider FOF30\Tests\Platform\PlatformJoomlaProvider::getTestGetTemplateOverridePath
  *
  */
 public function testGetTemplateOverridePath($applicationType, $component, $absolute, $expected, $message)
 {
     $this->forceApplicationTypeAndResetPlatformCliAdminCache($applicationType);
     if ($applicationType != 'cli') {
         $app = \JFactory::getApplication();
         $fakeTemplate = (object) array('template' => 'system');
         ReflectionHelper::setValue($app, 'template', $fakeTemplate);
     }
     $actual = $this->platform->getTemplateOverridePath($component, $absolute);
     $this->assertEquals($expected, $actual, $message);
 }
Example #15
0
 /**
  * @group           RelationManager
  * @group           RelationManagerIsMagicProperty
  * @covers          FOF30\Model\DataModel\RelationManager::isMagicProperty
  * @dataProvider    RelationManagerDataprovider::getTestIsMagicProperty
  */
 public function testIsMagicProperty($test, $check)
 {
     $msg = 'RelationManager::isMagicProperty %s - Case: ' . $check['case'];
     $model = $this->buildModel();
     $relation = new RelationManager($model);
     ReflectionHelper::setValue($relation, 'relations', array('foobar' => ''));
     $result = $relation->isMagicProperty($test['name']);
     $this->assertEquals($check['result'], $result, sprintf($msg, 'Failed to return the corret result'));
 }
Example #16
0
 /**
  * @covers          FOF30\Controller\DataController::getModel
  * @dataProvider    DataControllerDataprovider::getTestGetModel
  */
 public function testGetModel($test, $check)
 {
     $container = new TestContainer(array('componentName' => 'com_fakeapp'));
     $config = array('idFieldName' => 'foftest_foobar_id', 'tableName' => '#__foftest_foobars');
     $controller = new DataControllerStub($container);
     ReflectionHelper::setValue($controller, 'modelName', $test['mock']['modelname']);
     if ($check['exception']) {
         $this->setExpectedException('FOF30\\Controller\\Exception\\NotADataModel');
     }
     $model = $controller->getModel($test['name'], $config);
     $this->assertInstanceOf('\\FOF30\\Model\\DataModel', $model, 'DataController::getModel should return a DataModel');
 }
Example #17
0
 /**
  * @group           DataModel
  * @group           DataModelUnpublish
  * @covers          FOF30\Model\DataModel::unpublish
  * @dataProvider    PublishDataprovider::getTestUnpublish
  */
 public function testUnpublish($test, $check)
 {
     $before = 0;
     $after = 0;
     $msg = 'DataModel::unpublish %s - Case: ' . $check['case'];
     $config = array('idFieldName' => $test['tableid'], 'tableName' => $test['table']);
     // I am passing those methods so I can double check if the method is really called
     $methods = array('onBeforeUnpublish' => function () use(&$before) {
         $before++;
     }, 'onAfterUnpublish' => function () use(&$after) {
         $after++;
     });
     $model = $this->getMock('\\FOF30\\Tests\\Stubs\\Model\\DataModelStub', array('save', 'getId'), array(static::$container, $config, $methods));
     $model->expects($this->any())->method('getId')->willReturn(1);
     // Let's mock the dispatcher, too. So I can check if events are really triggered
     $dispatcher = $this->getMock('\\FOF30\\Event\\Dispatcher', array('trigger'), array(static::$container));
     $dispatcher->expects($this->exactly($check['dispatcher']))->method('trigger')->withConsecutive(array($this->equalTo('onBeforeUnpublish')), array($this->equalTo('onAfterUnpublish')));
     ReflectionHelper::setValue($model, 'behavioursDispatcher', $dispatcher);
     $result = $model->unpublish();
     $enabled = $model->getFieldValue('enabled');
     $this->assertInstanceOf('\\FOF30\\Model\\DataModel', $result, sprintf($msg, 'Should return an instance of itself'));
     $this->assertEquals($check['before'], $before, sprintf($msg, 'Failed to call the onBefore method'));
     $this->assertEquals($check['after'], $after, sprintf($msg, 'Failed to call the onAfter method'));
     $this->assertSame($check['enabled'], $enabled, sprintf($msg, 'Failed to set the enabled field'));
 }
Example #18
0
 /**
  * @group       Model
  * @group       ModelGetIgnoreRequest
  * @covers      FOF30\Model\Model::getIgnoreRequest
  */
 public function testGetIgnoreRequest()
 {
     $model = new ModelStub(static::$container);
     ReflectionHelper::setValue($model, '_ignoreRequest', 'foobar');
     $result = $model->getIgnoreRequest();
     $this->assertEquals('foobar', $result, 'Model::getIgnoreRequest returned the wrong value');
 }
Example #19
0
 /**
  * @group           DataModel
  * @group           DataModelBlacklistFilters
  * @covers          FOF30\Model\DataModel::blacklistFilters
  * @dataProvider    DataModelGenericDataprovider::getTestBlacklistFilters
  */
 public function testBlacklistFilters($test, $check)
 {
     $msg = 'DataModel::blacklistFilters %s - Case: ' . $check['case'];
     $config = array('idFieldName' => 'foftest_bare_id', 'tableName' => '#__foftest_bares');
     $model = new DataModelStub(static::$container, $config);
     ReflectionHelper::setValue($model, '_behaviorParams', array('blacklistFilters' => array('test')));
     $result = $model->blacklistFilters($test['list'], $test['reset']);
     $behaviors = ReflectionHelper::getValue($model, '_behaviorParams');
     $filters = isset($behaviors['blacklistFilters']) ? $behaviors['blacklistFilters'] : array();
     $this->assertSame($check['result'], $result, sprintf($msg, 'Returned the wrong result'));
     $this->assertEquals($check['filters'], $filters, sprintf($msg, 'Failed to set the filters'));
 }
Example #20
0
 /**
  * @group           BasicFactory
  * @covers          FOF30\Factory\BasicFactory::setSaveScaffolding
  */
 public function testSetSaveScaffolding()
 {
     $factory = new BasicFactory(static::$container);
     $factory->setSaveScaffolding(true);
     $this->assertTrue(ReflectionHelper::getValue($factory, 'saveScaffolding'), 'BasicFactory::setSaveScaffolding Failed to set the save scaffolding flag');
 }
Example #21
0
 /**
  * @group           DataModel
  * @group           DataModelForceDelete
  * @covers          FOF30\Model\DataModel::forceDelete
  * @dataProvider    DataModelCrudDataprovider::getTestForceDelete
  */
 public function testForceDelete($test, $check)
 {
     $before = 0;
     $after = 0;
     $msg = 'DataModel::forceDelete %s - Case: ' . $check['case'];
     $config = array('idFieldName' => 'foftest_bare_id', 'tableName' => '#__foftest_bares');
     // I am passing those methods so I can double check if the method is really called
     $methods = array('onBeforeDelete' => function () use(&$before) {
         $before++;
     }, 'onAfterDelete' => function () use(&$after) {
         $after++;
     });
     $model = $this->getMock('\\FOF30\\Tests\\Stubs\\Model\\DataModelStub', array('getId', 'findOrFail', 'reset'), array(static::$container, $config, $methods));
     $model->expects($this->once())->method('reset')->willReturn(null);
     $model->expects($this->any())->method('getId')->willReturn($test['mock']['id']);
     $model->expects($check['find'] ? $this->once() : $this->never())->method('findOrFail')->willReturn(null);
     // Let's mock the dispatcher, too. So I can check if events are really triggered
     $dispatcher = $this->getMock('\\FOF30\\Event\\Dispatcher', array('trigger'), array(static::$container));
     $dispatcher->expects($this->exactly(2))->method('trigger')->withConsecutive(array($this->equalTo('onBeforeDelete')), array($this->equalTo('onAfterDelete')));
     ReflectionHelper::setValue($model, 'behavioursDispatcher', $dispatcher);
     $result = $model->delete($test['id']);
     $this->assertInstanceOf('\\FOF30\\Model\\DataModel', $result, sprintf($msg, 'Should return an instance of itself'));
     $this->assertEquals(1, $before, sprintf($msg, 'Failed to call the onBefore method'));
     $this->assertEquals(1, $after, sprintf($msg, 'Failed to call the onAfter method'));
     // Now let's check if the record was really deleted
     $db = \JFactory::getDbo();
     $query = $db->getQuery(true)->select('COUNT(*)')->from($db->qn('#__foftest_bares'))->where($db->qn('foftest_bare_id') . ' = ' . $db->q($check['id']));
     $count = $db->setQuery($query)->loadResult();
     $this->assertEquals(0, $count, sprintf($msg, 'Failed to actually delete the record in the database'));
 }
Example #22
0
 /**
  * @group           SwitchFactory
  * @covers          FOF30\Factory\SwitchFactory::__construct
  */
 public function test__construct()
 {
     $factory = new SwitchFactory(static::$container);
     $this->assertTrue(ReflectionHelper::getValue($factory, 'formLookupInOtherSide'));
 }
Example #23
0
 /**
  * @group           Relation
  * @group           RelationGetforeignKeyMap
  * @covers          FOF30\Model\DataModel\Relation::getForeignKeyMap
  */
 public function testGetForeignKeyMap()
 {
     $model = $this->buildModel();
     $relation = new RelationStub($model, 'Children');
     $keymap = array(1, 2, 3);
     ReflectionHelper::setValue($relation, 'foreignKeyMap', $keymap);
     $result = $relation->getForeignKeyMap();
     $this->assertEquals($keymap, $result, 'Relation::getForeignKeyMap Returned the wrong result');
 }
Example #24
0
 /**
  * @group               TreeModelGetRoot
  * @group               TreeModel
  * @covers              FOF30\Model\TreeModel::getRoot
  * @dataProvider        TreeModelDataprovider::getTestRoot
  */
 public function testGetRoot($test, $check)
 {
     $config = array('autoChecks' => false, 'idFieldName' => 'foftest_nestedset_id', 'tableName' => '#__foftest_nestedsets');
     $table = new TreeModelStub(static::$container, $config);
     // Am I request to create a different root?
     if ($test['newRoot']) {
         $root = $table->getClone();
         $root->title = 'New root';
         $root->insertAsRoot();
         $child = $table->getClone();
         $child->title = 'First child 2nd root';
         $child->insertAsChildOf($root);
         $child->reset();
         $child->title = 'Second child 2nd root';
         $child->insertAsChildOf($root);
         $grandson = $child->getClone();
         $grandson->reset();
         $grandson->title = 'First grandson of second child';
         $grandson->insertAsChildOf($child);
     }
     $table->findOrFail($test['loadid']);
     if (!is_null($test['cache'])) {
         if ($test['cache'] == 'loadself') {
             ReflectionHelper::setValue($table, 'treeRoot', $table);
         } else {
             ReflectionHelper::setValue($table, 'treeRoot', $test['cache']);
         }
     }
     // I have to check the lft value, since the id could change throught test iteration (table deleted and not truncated)
     $return = $table->getRoot();
     $root = $return->lft;
     $this->assertEquals($check['result'], $root, 'TreeModel::getRoot returned the wrong root - Case: ' . $check['case']);
 }
Example #25
0
 /**
  * @covers          FOF30\Toolbar\Toolbar::isDataView
  * @dataProvider    ToolbarDataprovider::getTestIsDataView
  */
 public function testIsDataView($test, $check)
 {
     $msg = 'Toolbar::isDataView %s - Case: ' . $check['case'];
     $platform = static::$container->platform;
     $platform::$template = 'fake_test_template';
     $platform::$uriBase = 'www.example.com';
     $TestContainer = static::$container;
     $controller = $this->getMock('\\FOF30\\Tests\\Stubs\\Controller\\ControllerStub', array('getView'), array(static::$container));
     $controller->expects($this->any())->method('getView')->willReturnCallback(function () use($test, $TestContainer) {
         if (!is_null($test['mock']['getView'])) {
             return new $test['mock']['getView']($TestContainer);
         }
         return null;
     });
     $dispacher = $this->getMock('FOF30\\Dispatcher\\Dispatcher', array('getController'), array(static::$container));
     $dispacher->expects($this->any())->method('getController')->willReturn($test['mock']['getController'] ? $controller : null);
     $container = new TestContainer(array('dispatcher' => $dispacher));
     $toolbar = new ToolbarStub($container);
     ReflectionHelper::setValue($toolbar, 'isDataView', $test['mock']['cache']);
     $result = $toolbar->isDataView();
     $this->assertEquals($check['result'], $result, sprintf($msg, 'Returned the wrong result'));
 }
Example #26
0
 /**
  * @group           DataViewRaw
  * @covers          FOF30\View\DataView\Raw::getPageParams
  */
 public function testGetPageParams()
 {
     $platform = static::$container->platform;
     $platform::$uriBase = 'www.example.com';
     $platform::$template = 'fake_test_template';
     $view = new RawStub(static::$container);
     $value = (object) array('test' => 1, 'dummy' => 'test');
     ReflectionHelper::setValue($view, 'pageParams', $value);
     $this->assertSame($value, $view->getPageParams(), 'Raw::getPageParams Failed to return the internal item');
 }
Example #27
0
 /**
  * @group           DataModel
  * @group           DataModelGetTouches
  * @covers          FOF30\Model\DataModel::getTouches
  */
 public function testGetTouches()
 {
     $config = array('idFieldName' => 'foftest_bare_id', 'tableName' => '#__foftest_bares');
     $model = new DataModelStub(static::$container, $config);
     $touches = array('foo', 'bar');
     ReflectionHelper::setValue($model, 'touches', $touches);
     $obj = $model->getTouches();
     $this->assertSame($touches, $obj, 'DataModel::getTouches failed to return the internal array');
 }
Example #28
0
 /**
  * @dataProvider getTestBin2StrExceptions
  */
 public function testFromBinExceptions($crapData, $message)
 {
     $this->setExpectedException('\\Exception');
     ReflectionHelper::invoke($this->base32, 'fromBin', $crapData);
 }
Example #29
0
 public function testConstructor()
 {
     $dummy = new FirstObserver($this->dispatcher);
     $this->assertEquals($dummy, self::$attachArguments);
     $this->assertEquals($this->dispatcher, ReflectionHelper::getValue($dummy, 'subject'));
 }
Example #30
0
 /**
  * @group           BelongsToMany
  * @group           BelongsToManySaveAll
  * @covers          FOF30\Model\DataModel\Relation\BelongsToMany::saveAll
  */
 public function testSaveAll()
 {
     $platform = static::$container->platform;
     $platform::$user = (object) array('id' => 42);
     $model = new Groups(static::$container);
     $model->find(1);
     $relation = new BelongsToMany($model, 'Parts');
     $items = array();
     // Let's mix datamodels with integers
     $items[0] = new Parts(static::$container);
     $items[0]->find(1);
     $items[0]->description = 'Modified';
     for ($i = 1; $i <= 55; $i++) {
         $items[] = $i;
     }
     $data = new Collection($items);
     ReflectionHelper::setValue($relation, 'data', $data);
     $relation->saveAll();
     $db = \JFactory::getDbo();
     // First of all double check if the part was updated
     $query = $db->getQuery(true)->select($db->qn('description'))->from($db->qn('#__fakeapp_parts'))->where($db->qn('fakeapp_part_id') . ' = ' . $db->q(1));
     $descr = $db->setQuery($query)->loadResult();
     $this->assertEquals('Modified', $descr, 'BelongsToMany::saveAll Failed to save item in the relationship');
     // Then let's check if all the items were saved in the glue table
     $query = $db->getQuery(true)->select('COUNT(*)')->from($db->qn('#__fakeapp_parts_groups'))->where($db->qn('fakeapp_group_id') . ' = ' . $db->q(1));
     $count = $db->setQuery($query)->loadResult();
     $this->assertEquals(55, $count, 'BelongsToMany::saveAll Failed to save data inside the glue table');
 }