Tuesday, 13 October 2015

Moodle: Change current session lang in your local plugins

Hi,

I'm creating some code in my moodle local plugins and webservices and I'd like to "force" use a specific language. The solution that I found is:

$SESSION->lang = 'ca';

Best regards,
Iban Cardona.

Saturday, 10 October 2015

Laravel & TDD: Only test 1 file or function

Hello,

I'm developing with Laravel 5.1 and creating some testing files... http://laravel.com/docs/5.1/testing

I can test all my code executing phpunit inside my project folder but how test only one file/function:

- 1 file: phpunit tests/Auth/UserTest.php
- 1 function: phpunit --filter testRegisterControllerUser tests/Auth/UserTest.php

Best regards,
Iban Cardona.

Friday, 2 October 2015

Using Testing Environment with PHPunit and Laravel

Hello,

Recently I've been using phpunit with Laravel and I found this problem: How to clean or reset my test environment on every test? I did this solution:

Laravel version : 5.1

I followed this tutorial: http://laravel.com/docs/5.1/testing

I created my .env.testing file:

APP_ENV=testing
APP_DEBUG=true
APP_KEY=app_key_testing

DB_CONNECTION=mysql_testing
DB_HOST=localhost
DB_DATABASE=test
DB_USERNAME=dbusernametest
DB_PASSWORD=dbpwdtest

I changed my TestCase.php file:

class TestCase extends Illuminate\Foundation\Testing\TestCase
{
    /**
     * The base URL to use while testing the application.
     *
     * @var string
     */
    protected $baseUrl = 'http://localhost';

    /**
     * Creates the application.
     *
     * @return \Illuminate\Foundation\Application
     */
    public function createApplication()
    {
        $app = require __DIR__.'/../bootstrap/app.php';

        $app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();

        return $app;
    }

    public function setUp()
    {
        exec('cp /opt/lampp/htdocs/mytestsite/.env.testing /opt/lampp/htdocs/mytestsite/.env');
        parent::setUp();
        Artisan::call('migrate');
    }

    public function tearDown()
    {
        Artisan::call('migrate:reset');
        parent::tearDown();
        exec('cp /opt/lampp/htdocs/mytestsite/.env.local /opt/lampp/htdocs/mytestsite/.env');
    }
}

I hope you find it useful.

Best regards!

Saturday, 19 September 2015

Install XAMPP + Laravel in Ubuntu

Hello,

Ubuntu version: 14.04.3 LTS
XAMPP version: 5.6.15
Laravel version: 5.2

Install XAMPP (as root)
  • chmod +x xampp-linux-x64-5.6.12-0-installer.run
  • ./xampp-linux-x64-5.6.8-0-installer.run
  • You will be asked to answer some questions, I sayed always Y.
  • To start lampp server: /opt/lampp/lampp start
Install Laravel (as root)
  • Install composer: curl -sS https://getcomposer.org/installer | /opt/lampp/bin/php -- --install-dir=/opt/lampp/bin --filename=composer
  • cd /opt/lampp/htdocs
  • export PATH="$PATH:$HOME/.composer/vendor/bin"
  • export PATH=$PATH:/opt/lampp/bin
  • composer global require "laravel/installer"
  • laravel new test
  • chmod 777 /opt/lampp/htdocs/test/bootstrap/cache
  • chmod -R 777 /opt/lampp/htdocs/test/storage/*
Config Virtual Hosts (as root)
  • vim /opt/lampp/etc/httpd.conf
  • #Include etc/extra/httpd-vhosts.conf --> Include etc/extra/httpd-vhosts.conf
  • Add in /opt/lampp/etc/extra/httpd-vhosts.conf
    •  <VirtualHost *:80>
          ServerAdmin webmaster@dummy-host.example.com
          DocumentRoot "/opt/lampp/htdocs/test/public"
          ServerName testlaravel.com
          ServerAlias www.testlaravel.com
          ErrorLog "logs/testlaravel-error_log"
          CustomLog "logs/testlaravel-access_log" common
      </VirtualHost>
  • /opt/lampp/lampp restart
  • Add in  /etc/hosts
    • 127.0.0.1       testlaravel.com
    • 127.0.0.1       www.testlaravel.com
Done! Go to your browser and write: testlaravel.com...

Tuesday, 30 June 2015

Postgres: could not open file "/etc/ssl/certs/ssl-cert-snakeoil.pem"

Hello,

Today I had a problem starting PostgreSQL server. I saw this error:

* The PostgreSQL server failed to start. Please check the log output:
CEST FATAL:  could not open file "/etc/ssl/certs/ssl-cert-snakeoil.pem"


To solve it I did these actions:

cd /etc/ssl/certs/
chown postgres ssl-cert-snakeoil.pem
chmod 777 ssl-cert-snakeoil.pem

cd /etc/ssl/private
chown postgres ssl-cert-snakeoil.key
chmod 700 ssl-cert-snakeoil.key

Best regards!!!

Wednesday, 17 June 2015

Essential: List of categories as a tree

Essential is a fancy moodle theme that has a lot of settings... One of them is use icons in categories or not. If you select in Category Icons -> Enable category icons : Yes, you will see categories as folders:

If you select "No", you will see categories as a tree:

Best regards,
Iban Cardona.

Monday, 8 June 2015

Using fputcsv without enclosure

Hi,

If you want to use the PHP function fputcsv in order to create a CSV file using no character as enclosure, you can write:

$list = array (
    array('aaa', 'bbb', 'ccc', 'dddd')
);

$fp = fopen('file.csv', 'w');

foreach ($list as $fields) {
    fputcsv($fp, $fields, ';', '');
}

But a warning will appear:

PHP Warning:  fputcsv(): enclosure must be a character

To avoid it, you need to write:

$list = array (
    array('aaa', 'bbb', 'ccc', 'dddd')
);

$fp = fopen('file.csv', 'w');

foreach ($list as $fields) {
    fputcsv($fp, $fields, ';', chr(0));
}

Best regards,
Iban Cardona.