Ejemplo n.º 1
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'));
 }
Ejemplo n.º 2
0
 /**
  * @group           Behaviour
  * @group           OwnOnAfterBuildQuery
  * @covers          FOF30\Model\DataModel\Behaviour\Own::onAfterBuildQuery
  * @dataProvider    OwnDataprovider::getTestOnAfterBuildQuery
  */
 public function testOnAfterBuildQuery($test, $check)
 {
     $msg = 'Own::onAfterBuildQuery %s - Case: ' . $check['case'];
     $config = array('idFieldName' => $test['tableid'], 'tableName' => $test['table']);
     $platform = static::$container->platform;
     $platform::$user = (object) array('id' => 99);
     $model = new DataModelStub(static::$container, $config);
     $query = \JFactory::getDbo()->getQuery(true)->select('*')->from('test');
     $dispatcher = $model->getBehavioursDispatcher();
     $filter = new Own($dispatcher);
     $filter->onAfterBuildQuery($model, $query);
     $rawQuery = (string) $query;
     if ($check['contains']) {
         $this->assertNotFalse(stripos($rawQuery, $check['query']), sprintf($msg, 'Query should contain the query clause'));
     } else {
         $this->assertFalse(stripos($rawQuery, $check['query']), sprintf($msg, 'Query should not contain the query clause'));
     }
 }
Ejemplo n.º 3
0
 /**
  * @group           DataModel
  * @group           DataModelCanDelete
  * @covers          FOF30\Model\DataModel::canDelete
  * @dataProvider    DataModelCrudDataprovider::getTestCanDelete
  */
 public function testCanDelete($test, $check)
 {
     $config = array('idFieldName' => 'fakeapp_parent_id', 'tableName' => '#__fakeapp_parents');
     $model = new DataModelStub(static::$container, $config);
     if ($check['exception']) {
         $this->setExpectedException($check['exception'], $check['message']);
     }
     if ($test['load']) {
         $model->find($test['load']);
     }
     $model->canDelete($test['id'], $test['joins']);
     // Fake assertion to prevent PHPUnit from complaining
     $this->assertTrue(true);
 }
Ejemplo n.º 4
0
 /**
  * @group           DataModel
  * @group           DataModelHas
  * @covers          FOF30\Model\DataModel::has
  */
 public function testHasException()
 {
     $this->setExpectedException('FOF30\\Model\\DataModel\\Exception\\InvalidSearchMethod');
     $config = array('idFieldName' => 'foftest_bare_id', 'tableName' => '#__foftest_bares');
     $model = new DataModelStub(static::$container, $config);
     $model->has('posts', 'wrong', true);
 }
Ejemplo n.º 5
0
 /**
  * @group           DataModel
  * @group           DataModelUnpublish
  * @covers          FOF30\Model\DataModel::unpublish
  */
 public function testUnpublishException()
 {
     $config = array('idFieldName' => 'foftest_foobar_id', 'tableName' => '#__foftest_foobars');
     $this->setExpectedException('FOF30\\Model\\DataModel\\Exception\\RecordNotLoaded');
     $model = new DataModelStub(static::$container, $config);
     $model->unpublish();
 }
Ejemplo n.º 6
0
 /**
  * @group           DataModel
  * @group           DataModelSetBehaviorParam
  * @covers          FOF30\Model\DataModel::setBehaviorParam
  */
 public function testSetBehaviorParam()
 {
     $config = array('idFieldName' => 'foftest_bare_id', 'tableName' => '#__foftest_bares');
     $model = new DataModelStub(static::$container, $config);
     $result = $model->setBehaviorParam('foo', 'bar');
     $behaviors = ReflectionHelper::getValue($model, '_behaviorParams');
     $this->assertArrayHasKey('foo', $behaviors);
     $this->assertEquals('bar', $behaviors['foo']);
     $this->assertInstanceOf('FOF30\\Model\\DataModel', $result);
 }
Ejemplo n.º 7
0
 /**
  * @group           Behaviour
  * @group           AssetsOnBeforeDelete
  * @covers          FOF30\Model\DataModel\Behaviour\Assets::onBeforeDelete
  * @dataProvider    AssetsDataprovider::getTestOnBeforeDelete
  */
 public function testOnBeforeDelete($test, $check)
 {
     $msg = 'Own::onBeforeDelete %s - Case: ' . $check['case'];
     $db = \JFactory::getDbo();
     $config = array('idFieldName' => $test['tableid'], 'tableName' => $test['table']);
     $model = new DataModelStub(static::$container, $config);
     $dispatcher = $model->getBehavioursDispatcher();
     $behavior = new Assets($dispatcher);
     $model->setAssetsTracked($test['track']);
     if ($test['load']) {
         $model->find($test['load']);
     }
     if ($check['exception']) {
         $this->setExpectedException('FOF30\\Model\\DataModel\\Exception\\NoAssetKey');
     }
     $query = $db->getQuery(true)->select('COUNT(*)')->from('#__assets');
     $beforeTotal = $db->setQuery($query)->loadResult();
     $result = $behavior->onBeforeDelete($model, $test['id']);
     $this->assertTrue($result, sprintf($msg, 'Returned a wrong value'));
     $query = $db->getQuery(true)->select('COUNT(*)')->from('#__assets');
     $afterTotal = $db->setQuery($query)->loadResult();
     $this->assertEquals($check['count'], $beforeTotal - $afterTotal, sprintf($msg, 'Deleted a wrong number of assets'));
 }
Ejemplo n.º 8
0
 /**
  * @group           DataModel
  * @group           DataModelIsLocked
  * @covers          FOF30\Model\DataModel::isLocked
  * @dataProvider    SpecialColumnsDataprovider::getTestIsLocked
  */
 public function testIsLocked($test, $check)
 {
     $msg = 'DataModel::isLocked %s - Case: ' . $check['case'];
     $config = array('idFieldName' => $test['tableid'], 'tableName' => $test['table']);
     $model = new DataModelStub(static::$container, $config);
     if ($test['load']) {
         $model->find($test['load']);
     }
     $result = $model->isLocked($test['userid']);
     $this->assertEquals($check['result'], $result, sprintf($msg, 'Returned the wrong value'));
 }