Ejemplo n.º 1
0
 public function testGetIncludedColumn()
 {
     $model = m::mock(array('getTable' => 'table', 'method' => m::mock(array('getRelated' => m::mock(array('getKeyName' => 'fk'))))));
     $this->config->shouldReceive('getDataModel')->once()->andReturn($model);
     $this->column->shouldReceive('getOption')->once()->andReturn('method');
     $this->assertEquals($this->column->getIncludedColumn(), array('fk' => 'table.fk'));
 }
Ejemplo n.º 2
0
	public function testOverrideSetsDataRulesAndMessages()
	{
		$this->validator->shouldReceive('setData')->once()
						->shouldReceive('setRules')->once()
						->shouldReceive('setCustomMessages')->once();
		$this->validator->override(array(), array());
	}
Ejemplo n.º 3
0
 public function testShowFolderTreeWithContent()
 {
     $res = $this->prepareShowFolderTree($parentFolderId = 'foo');
     $this->dbManager->shouldReceive('fetchArray')->with($res)->andReturn($rowTop = array('folder_pk' => 1, 'folder_name' => 'Top', 'folder_desc' => '', 'depth' => 0), $rowA = array('folder_pk' => 2, 'folder_name' => 'B', 'folder_desc' => '/A', 'depth' => 1), $rowB = array('folder_pk' => 3, 'folder_name' => 'B', 'folder_desc' => '/A/B', 'depth' => 2), $rowC = array('folder_pk' => 4, 'folder_name' => 'C', 'folder_desc' => '/C', 'depth' => 1), false);
     $out = $this->folderNav->showFolderTree($parentFolderId);
     assertThat(str_replace("\n", '', $out), equalTo('<ul id="tree"><li>' . $this->getFormattedItem($rowTop) . '<ul><li>' . $this->getFormattedItem($rowA) . '<ul><li>' . $this->getFormattedItem($rowB) . '</li></ul></li><li>' . $this->getFormattedItem($rowC) . '</li></ul></li></ul>'));
 }
Ejemplo n.º 4
0
 public function testConstrainQuery()
 {
     $query = m::mock('Illuminate\\Database\\Eloquent\\Builder');
     $query->shouldReceive('where')->once();
     $this->field->shouldReceive('getOption')->once();
     $this->field->constrainQuery($query, m::mock(array()), 'foo');
 }
Ejemplo n.º 5
0
 public function testBuild()
 {
     $url = m::mock('Illuminate\\Routing\\UrlGenerator');
     $url->shouldReceive('route')->once();
     $this->validator->shouldReceive('arrayGet')->times(3)->shouldReceive('getUrlInstance')->once()->andReturn($url);
     $this->config->shouldReceive('getType')->once()->shouldReceive('getOption')->once();
     $this->field->build();
 }
Ejemplo n.º 6
0
 public function testFilterQueryWithoutValue()
 {
     $query = m::mock('Illuminate\\Database\\Query\\Builder');
     $query->shouldReceive('where')->never();
     $this->config->shouldReceive('getDataModel')->once()->andReturn(m::mock(array('getTable' => 'table')));
     $this->field->shouldReceive('getOption')->twice()->andReturn(false);
     $this->field->filterQuery($query);
 }
 /**
  * Tests if the service get admin
  * method interacts correctly.
  */
 public function testServiceGetLogged()
 {
     $fakeUser = m::mock('App\\Models\\User');
     $fakeAdmin = m::mock('App\\Mdodels\\Administrator');
     \Auth::shouldReceive('user')->once()->andReturn($fakeUser);
     $this->fakeAdministratorsRepo->shouldReceive('getAdministrator')->withArgs([m::type('App\\Models\\User')])->once()->andReturn($fakeAdmin);
     $admin = $this->service->getLogged();
     $this->assertEquals($fakeAdmin, $admin);
 }
 public function testFilterQuery()
 {
     $relationship = m::mock(array('getPlainForeignKey' => '', 'getRelated' => m::mock(array('getTable' => 'table'))));
     $model = m::mock(array('getTable' => 'table', 'getKeyName' => '', 'method' => $relationship));
     $grammar = m::mock('Illuminate\\Database\\Query\\Grammars');
     $grammar->shouldReceive('wrap')->once()->andReturn('');
     $this->config->shouldReceive('getDataModel')->once()->andReturn($model);
     $this->column->shouldReceive('getOption')->times(3)->andReturn('column_name', 'method', 'select')->shouldReceive('getRelationshipWheres')->once()->andReturn('');
     $this->db->shouldReceive('raw')->once()->andReturn('foo')->shouldReceive('getQueryGrammar')->once()->andReturn($grammar);
     $selects = array();
     $this->column->filterQuery($selects);
     $this->assertEquals($selects, array('foo'));
 }
 public function testFilterQueryNoValue()
 {
     $query = m::mock('Illuminate\\Database\\Query\\Builder');
     $query->shouldReceive('where')->never();
     $this->field->shouldReceive('getOption')->once()->andReturn('');
     $this->field->filterQuery($query);
 }
 public function testGetIncludedColumn()
 {
     $this->config->shouldReceive('getDataModel')->once()->andReturn(m::mock(array('getTable' => 'table')));
     $nested = array('pieces' => array('foo'), 'models' => array(m::mock(array('foo' => m::mock(array('getForeignKey' => 'fk'))))));
     $this->column->shouldReceive('getOption')->once()->andReturn($nested);
     $this->assertEquals($this->column->getIncludedColumn(), array('fk' => 'table.fk'));
 }
Ejemplo n.º 11
0
 public function testGetMenuDeepNestedWithoutPermission()
 {
     $this->config->shouldReceive('get')->once()->andReturn(array('Header' => array('Header2' => array('test_name'))));
     $itemconfig = m::mock('Frozennode\\Administrator\\Config\\Config');
     $itemconfig->shouldReceive('getOption')->once()->andReturn(false);
     $this->configFactory->shouldReceive('make')->once()->andReturn($itemconfig);
     $this->assertEquals($this->menu->getMenu(), array());
 }
Ejemplo n.º 12
0
 public function testSetRowsPerPageDefaultsToUserChoice()
 {
     $session = m::mock('Illuminate\\Session\\Store');
     $session->shouldReceive('get')->once()->andReturn(23);
     $this->config->shouldReceive('getOption')->once();
     $this->dataTable->setRowsPerPage($session, 54);
     $this->assertEquals($this->dataTable->getRowsPerPage(), 23);
 }
 public function testGetRelationshipWheres()
 {
     $connection = m::mock('Illuminate\\Database\\Connection');
     $connection->shouldReceive('prepareBindings')->once()->andReturn(array());
     $query = m::mock('Illuminate\\Database\\Query\\Builder');
     $query->shouldReceive('getConnection')->once()->andReturn($connection)->shouldReceive('getBindings')->once()->andReturn(array())->shouldReceive('toSql')->once()->andReturn('');
     $query->wheres = array(array(), array('column' => 'bar'));
     $eloquentQuery = m::mock('Illuminate\\Database\\Eloquent\\Builder');
     $eloquentQuery->shouldReceive('getQuery')->once()->andReturn($query);
     $relatedModel = m::mock('Illuminate\\Database\\Eloquent\\Model');
     $relatedModel->shouldReceive('isSoftDeleting')->once();
     $relationship = m::mock('Illuminate\\Database\\Eloquent\\Relations\\Relation');
     $relationship->shouldReceive('getQuery')->once()->andReturn($eloquentQuery)->shouldReceive('getRelated')->once()->andReturn($relatedModel);
     $this->column->shouldReceive('interpolateQuery')->once()->andReturn('foo where test')->shouldReceive('aliasRelationshipWhere')->once()->andReturn('foo');
     $result = $this->column->getRelationshipWheres($relationship, 'fooalias');
     $this->assertEquals($result, 'test');
 }
 public function testConstrainQueryAlreadyJoined()
 {
     $query = m::mock('Illuminate\\Database\\Eloquent\\Builder');
     $query->shouldReceive('join')->never()->shouldReceive('where')->once();
     $this->validator->shouldReceive('isJoined')->once()->andReturn(true);
     $model = m::mock(array('getTable' => 'table', 'getKeyName' => 'id'));
     $this->field->shouldReceive('getOption')->twice();
     $this->field->constrainQuery($query, $model, 'foo');
 }
 /**
  * Tests if the delete match method
  * Interacts and works as expected.
  */
 public function testServiceRemoveMatchInteractsCorrectly()
 {
     $matchID = 1;
     $fakeAdmin = m::mock('App\\Models\\Administrator');
     \Admin::shouldReceive('getLogged')->once()->andReturn($fakeAdmin);
     $this->fakeMatchesRepo->shouldReceive('removeMatch')->withArgs([m::type('App\\Models\\Administrator'), $matchID])->once()->andReturn(true);
     $result = $this->service->removeMatch($matchID);
     $this->assertTrue($result);
 }
Ejemplo n.º 16
0
 public function testGetComputedColumns()
 {
     $columnRelated = m::mock('Frozennode\\Administrator\\DataTable\\Columns\\Column');
     $columnRelated->shouldReceive('getOption')->once()->andReturn(true);
     $columnComputed = m::mock('Frozennode\\Administrator\\DataTable\\Columns\\Column');
     $columnComputed->shouldReceive('getOption')->times(4)->andReturn(false, true, 'computed');
     $this->factory->shouldReceive('getColumns')->once()->andReturn(array($columnRelated, $columnComputed));
     $this->assertEquals($this->factory->getComputedColumns(), array('computed' => 'computed'));
 }
 public function testRunQueryFilterWithFilter()
 {
     $filter = function ($query) {
         $query->where('test', '=', 'herp');
     };
     $query = m::mock('Illuminate\\Database\\Query\\Builder');
     $query->shouldReceive('where')->once();
     $this->config->shouldReceive('getOption')->once()->andReturn($filter);
     $this->config->runQueryFilter($query);
 }
 /**
  * Tests if the getPlayers method
  * has the expected interactions.
  */
 public function testServiceGetPlayersWithExpectedFlow()
 {
     $tournamentID = 1;
     $fakeTournament = m::mock('App\\Models\\Tournament');
     $fakePlayers = [m::mock('App\\Models\\Player')];
     $this->fakeTournamentsRepo->shouldReceive('getTournament')->withArgs([$tournamentID])->once()->andReturn($fakeTournament);
     $this->fakePlayersRepo->shouldReceive('getAllPlayers')->withArgs([m::type('App\\Models\\Tournament')])->once()->andReturn($fakePlayers);
     $players = $this->service->getPlayers($tournamentID);
     $this->assertEquals($players, $fakePlayers);
 }
 /**
  * Tests if the pairings method generates
  * a bye match when an odd number of
  * players is provided.
  */
 public function testServicePairingsWithByeRegistered()
 {
     $tournamentID = 1;
     $numberOfPlayers = 11;
     $numberOfMatches = intval(floor($numberOfPlayers / 2) + $numberOfPlayers % 2);
     $fakeStaticMatch = m::mock('App\\Models\\Match');
     $fakePairings = getFakePairings($numberOfMatches, true);
     $this->fakePlayersService->shouldReceive('getRankedPlayers')->andReturn([]);
     \Pairings::shouldReceive('ranked')->withArgs([[], $tournamentID])->once()->andReturn($fakePairings);
     $this->fakeMatchesService->shouldReceive('addMatch')->times($numberOfMatches)->andReturn($fakeStaticMatch);
     $this->service->pairings($tournamentID);
 }
 public function testLoadRelationshipOptionsSkipLoad()
 {
     $relatedModel = m::mock('Illuminate\\Database\\Eloquent\\Model');
     $relatedModel->shouldReceive('getKeyName')->once()->andReturn('id');
     $relationship = m::mock(array('getRelated' => $relatedModel, 'get' => array()));
     $model = m::mock(array('field' => $relationship));
     $this->config->shouldReceive('getDataModel')->once()->andReturn($model);
     $this->validator->shouldReceive('arrayGet')->twice()->andReturn(false);
     $options = array('field_name' => 'field');
     $this->field->shouldReceive('mapRelationshipOptions')->once()->andReturn(array('funky'));
     $this->field->loadRelationshipOptions($options);
     $this->assertEquals($options['options'], array('funky'));
 }
 public function testApplyConstraints()
 {
     $relatedModel = m::mock(array('getRelated' => null));
     $otherModel = m::mock(array('getRelated' => null));
     $model = m::mock(array('this_relationship' => $relatedModel, 'key' => $otherModel));
     $field = m::mock('Frozennode\\Administrator\\Fields\\Field');
     $field->shouldReceive('getOption')->twice()->andReturn(array('key' => 'other_relationship'), 'this_relationship');
     $otherField = m::mock('Frozennode\\Administrator\\Fields\\Field');
     $otherField->shouldReceive('constrainQuery')->once();
     $this->config->shouldReceive('setDataModel')->twice()->shouldReceive('getDataModel')->once()->andReturn($model);
     $query = m::mock('Illuminate\\Database\\Eloquent\\Builder');
     $this->factory->shouldReceive('make')->once()->andReturn($otherField);
     $this->factory->applyConstraints(array('key' => array(1, 2)), $query, $field);
 }
Ejemplo n.º 22
0
	public function testFormatSelectOptions()
	{
		$model = m::mock(array('getKeyName' => 'id'));
		$field = m::mock('Frozennode\Administrator\Fields\Field');
		$field->shouldReceive('getOption')->twice()->andReturn('name_field');
		$firstResult = new \stdClass();
		$firstResult->id = 1;
		$firstResult->name_field = 'first';
		$secondResult = new \stdClass();
		$secondResult->id = 2;
		$secondResult->name_field = 'second';
		$results = array($firstResult, $secondResult);
		$this->config->shouldReceive('getDataModel')->andReturn($model);
		$output = array(array('id' => 1, 'text' => 'first'), array('id' => 2, 'text' => 'second'));
		$this->assertEquals($this->factory->formatSelectOptions($model, $field, $results), $output);
	}
Ejemplo n.º 23
0
 /**
  * @expectedException InvalidArgumentException
  */
 public function testGetOptionFails()
 {
     $this->field->shouldReceive('getOptions')->once()->andReturn(array('field_name' => 'bar'));
     $this->field->getOption('foo');
 }
Ejemplo n.º 24
0
 public function testParseNumber()
 {
     $this->field->shouldReceive('getOption')->times(2)->andReturn('[', ']');
     $this->assertEquals($this->field->parseNumber('1]454]432[23'), '1454432.23');
 }
 /**
  * @expectedException InvalidArgumentException
  */
 public function testPutToJsonNotWritableError()
 {
     $path = __DIR__ . '/bar/';
     $this->config->shouldReceive('getStoragePath')->once()->andReturn($path)->shouldReceive('getOption')->once()->andReturn('foo');
     $this->config->putToJson(array('foo'));
 }
 public function testValidateDataReturnsStringError()
 {
     $this->validator->shouldReceive('override')->once()->shouldReceive('fails')->once()->andReturn(true)->shouldReceive('messages')->once()->andReturn(m::mock(array('all' => array())));
     $this->assertEquals($this->config->validateData(array(), array(1)), '');
 }
 /**
  * @expectedException InvalidArgumentException
  */
 public function testValidationErrorThrowsException()
 {
     $this->validator->shouldReceive('fails')->once()->andReturn(true)->shouldReceive('messages')->once()->andReturn(m::mock(array('all' => array())));
     $factory = new Factory($this->validator, $this->validator, array());
 }
Ejemplo n.º 28
0
 public function testGetActionPermissionsBool()
 {
     $this->config->shouldReceive('getDataModel')->once()->shouldReceive('getOption')->once()->andReturn(array('foo' => false));
     $output = array('create' => true, 'view' => true, 'delete' => true, 'update' => true, 'foo' => false);
     $this->assertEquals($this->factory->getActionPermissions(), $output);
 }
Ejemplo n.º 29
0
 public function testGetDateStringParsesTime()
 {
     $this->field->shouldReceive('getOption')->twice()->andReturn('time');
     $this->assertEquals($this->field->getDateString(strtotime('4:45pm')), '16:45:00');
 }
Ejemplo n.º 30
0
 public function testGetDateStringParsesVeryOldDate()
 {
     $this->field->shouldReceive('getOption')->once()->andReturn('date');
     $this->assertEquals($this->field->getDateString(new \DateTime('6/20/1700')), '1700-06-20');
 }