<commit_before><?php

/* Copyright (C) 2015 <NAME>
 *
 * This file is part of Dembelo.
 *
 * Dembelo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Dembelo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License 3 for more details.
 *
 * You should have received a copy of the GNU Affero General Public License 3
 * along with Dembelo. If not, see <http://www.gnu.org/licenses/>.
 */


/**
 * @package AdminBundle
 */

namespace AdminBundle\Tests\Controller;

use DembeloMain\Document\User;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use AdminBundle\Controller\DefaultController;

/**
 * Class DefaultControllerTest
 */
class DefaultControllerTest extends WebTestCase
{
    private $container;
    private $repository;
    private $service;

    /**
     * tests the index action
     */
    public function testIndexAction()
    {
        $client = static::createClient();
        $crawler = $client->request('GET', '/admin/');

        $this->assertEquals(302, $client->getResponse()->getStatusCode());
        $this->assertTrue($crawler->filter('html:contains("login")')->count() > 0);
    }

    /**
     * tests controller's userAction with no users in db
     */
    public function testUserAction()
    {
        $request = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock();
        $postMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\ParameterBag")->disableOriginalConstructor()->getMock();
        $queryMock = $this->getMock('foobar', array('execute', 'getQuery'));
        $postArray = array();
        $postMock->expects($this->once())
            ->method("get")
            ->will($this->returnValue($postArray));
        $request->query = $postMock;

        $queryMock->expects($this->once())
            ->method("getQuery")
            ->will($this->returnSelf());

        $queryMock->expects($this->once())
            ->method("execute")
            ->will($this->returnValue(array()));

        $this->loadMongoContainer();
        $this->repository->expects($this->once())
            ->method("createQueryBuilder")
            ->will($this->returnValue($queryMock));

        $controller = new DefaultController();
        $controller->setContainer($this->container);

        /* @var $response \Symfony\Component\HttpFoundation\Response */
        $response = $controller->usersAction($request);
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
        $this->assertJsonStringEqualsJsonString('[]', $response->getContent());
        $this->assertEquals('200', $response->getStatusCode());
    }

    /**
     * tests controller's userAction with two users in db
     */
    public function testUserActionWithUsers()
    {
        $request = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock();
        $postMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\ParameterBag")->disableOriginalConstructor()->getMock();
        $queryMock = $this->getMock('foobar', array('execute', 'getQuery'));
        $postArray = array();
        $postMock->expects($this->once())
            ->method("get")
            ->will($this->returnValue($postArray));
        $request->query = $postMock;

        $queryMock->expects($this->once())
            ->method("getQuery")
            ->will($this->returnSelf());

        $this->loadMongoContainer();

        $this->repository->expects($this->once())
            ->method("createQueryBuilder")
            ->will($this->returnValue($queryMock));

        $user1 = new User();
        $user1->setEmail('email1');
        $user1->setId('id1');
        $user1->setRoles('ROLE_ADMIN');
        $user1->setLicenseeId('lic1');
        $user2 = new User();
        $user2->setEmail('email2');
        $user2->setId('id2');
        $user2->setRoles('ROLE_USER');
        $user2->setLicenseeId('lic2');

        $userArray = array(
            $user1,
            $user2,
        );

        $queryMock->expects($this->once())
            ->method("execute")
            ->will($this->returnValue($userArray));

        $controller = new DefaultController();
        $controller->setContainer($this->container);

        /* @var $response \Symfony\Component\HttpFoundation\Response */
        $response = $controller->usersAction($request);
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
        $this->assertJsonStringEqualsJsonString('[{"id":"id1","gender":null,"email":"email1","roles":"ROLE_ADMIN","licenseeId":"lic1","status":"aktiv","source":null,"reason":null,"created":"1970-01-01 01:00:00","updated":"1970-01-01 01:00:00"},{"id":"id2","email":"email2","roles":"ROLE_USER","licenseeId":"lic2","status":"aktiv","source":null,"reason":null,"gender":null,"created":"1970-01-01 01:00:00","updated":"1970-01-01 01:00:00"}]', $response->getContent());
        $this->assertEquals('200', $response->getStatusCode());
    }

    /**
     * tear down method
     */
    public function tearDown()<commit_msg>issue #122, fix for travis timezone<commit_after><?php

/* Copyright (C) 2015 <NAME>
 *
 * This file is part of Dembelo.
 *
 * Dembelo is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Dembelo is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License 3 for more details.
 *
 * You should have received a copy of the GNU Affero General Public License 3
 * along with Dembelo. If not, see <http://www.gnu.org/licenses/>.
 */


/**
 * @package AdminBundle
 */

namespace AdminBundle\Tests\Controller;

use DembeloMain\Document\User;
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
use AdminBundle\Controller\DefaultController;

/**
 * Class DefaultControllerTest
 */
class DefaultControllerTest extends WebTestCase
{
    private $container;
    private $repository;
    private $service;

    /**
     * tests the index action
     */
    public function testIndexAction()
    {
        $client = static::createClient();
        $crawler = $client->request('GET', '/admin/');

        $this->assertEquals(302, $client->getResponse()->getStatusCode());
        $this->assertTrue($crawler->filter('html:contains("login")')->count() > 0);
    }

    /**
     * tests controller's userAction with no users in db
     */
    public function testUserAction()
    {
        $request = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock();
        $postMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\ParameterBag")->disableOriginalConstructor()->getMock();
        $queryMock = $this->getMock('foobar', array('execute', 'getQuery'));
        $postArray = array();
        $postMock->expects($this->once())
            ->method("get")
            ->will($this->returnValue($postArray));
        $request->query = $postMock;

        $queryMock->expects($this->once())
            ->method("getQuery")
            ->will($this->returnSelf());

        $queryMock->expects($this->once())
            ->method("execute")
            ->will($this->returnValue(array()));

        $this->loadMongoContainer();
        $this->repository->expects($this->once())
            ->method("createQueryBuilder")
            ->will($this->returnValue($queryMock));

        $controller = new DefaultController();
        $controller->setContainer($this->container);

        /* @var $response \Symfony\Component\HttpFoundation\Response */
        $response = $controller->usersAction($request);
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
        $this->assertJsonStringEqualsJsonString('[]', $response->getContent());
        $this->assertEquals('200', $response->getStatusCode());
    }

    /**
     * tests controller's userAction with two users in db
     */
    public function testUserActionWithUsers()
    {
        $request = $this->getMockBuilder("Symfony\Component\HttpFoundation\Request")->disableOriginalConstructor()->getMock();
        $postMock = $this->getMockBuilder("Symfony\Component\HttpFoundation\ParameterBag")->disableOriginalConstructor()->getMock();
        $queryMock = $this->getMock('foobar', array('execute', 'getQuery'));
        $postArray = array();
        $postMock->expects($this->once())
            ->method("get")
            ->will($this->returnValue($postArray));
        $request->query = $postMock;

        $queryMock->expects($this->once())
            ->method("getQuery")
            ->will($this->returnSelf());

        $this->loadMongoContainer();

        $this->repository->expects($this->once())
            ->method("createQueryBuilder")
            ->will($this->returnValue($queryMock));

        $user1 = new User();
        $user1->setEmail('email1');
        $user1->setId('id1');
        $user1->setRoles('ROLE_ADMIN');
        $user1->setLicenseeId('lic1');
        $user2 = new User();
        $user2->setEmail('email2');
        $user2->setId('id2');
        $user2->setRoles('ROLE_USER');
        $user2->setLicenseeId('lic2');

        $userArray = array(
            $user1,
            $user2,
        );

        $queryMock->expects($this->once())
            ->method("execute")
            ->will($this->returnValue($userArray));

        $controller = new DefaultController();
        $controller->setContainer($this->container);

        /* @var $response \Symfony\Component\HttpFoundation\Response */
        $response = $controller->usersAction($request);
        $this->assertInstanceOf('Symfony\Component\HttpFoundation\Response', $response);
        $this->assertJsonStringEqualsJsonString('[{"id":"id1","gender":null,"email":"email1","roles":"ROLE_ADMIN","licenseeId":"lic1","status":"aktiv","source":null,"reason":null,"created":"' . date('Y-m-d H:i:s', 0) . '","updated":"' . date('Y-m-d H:i:s', 0) . '"},{"id":"id2","email":"email2","roles":"ROLE_USER","licenseeId":"lic2","status":"aktiv","source":null,"reason":null,"gender":null,"created":"' . date('Y-m-d H:i:s', 0) . '","updated":"' . date('Y-m-d H:i:s', 0) . '"}]', $response->getContent());
        $this->assertEquals('200', $response->getStatusCode());
    }

    /**
     * tear down method
     */
    public function tearDown()
{'fraction_non_alphanumeric': 0.17143377664419748, 'fraction_numerical': 0.013208234651120422, 'mean_word_length': 3.2259430331023866, 'pattern_counts': {'":': 40, '<': 9, '<?xml version=': 0, '>': 191, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4247713', 'n_tokens_mistral': 3115, 'n_tokens_neox': 3007, 'n_words': 575}