Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
trasher committed Feb 11, 2024
1 parent 1899c16 commit 1649ee9
Show file tree
Hide file tree
Showing 2 changed files with 234 additions and 0 deletions.
117 changes: 117 additions & 0 deletions tests/GaletteAuto/tests/units/State.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

/**
* Copyright © 2003-2024 The Galette Team
*
* This file is part of Galette (https://galette.eu).
*
* Galette is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Galette 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

namespace GaletteAuto\tests\units;

use Galette\GaletteTestCase;

/**
* State tests
*
* @author Johan Cwiklinski <[email protected]>
*/
class State extends GaletteTestCase
{
protected int $seed = 20240130141727;

/**
* Test empty
*
* @return void
*/
public function testEmpty(): void
{
$state = new \GaletteAuto\State($this->zdb);
$this->assertSame('State', $state->getFieldLabel());

$this->assertCount(0, $state->getList());
$this->assertSame('0 state', $state->displayCount());
}

/**
* Test add and update
*
* @return void
*/
public function testCrud(): void
{
$state = new \GaletteAuto\State($this->zdb);
//ensure the table is empty
$this->assertCount(0, $state->getList());

//Add new state
$state->value = 'Good';
$this->assertTrue($state->store(true));
$first_id = $state->id;

$this->assertCount(1, $state->getList());
$listed_state = $state->getList()[0];
$this->assertInstanceOf(\ArrayObject::class, $listed_state);
$this->assertGreaterThan(0, $listed_state->id_state);
$this->assertSame('Good', $listed_state->state);
$this->assertSame('1 state', $state->displayCount());

//add another one
$state = new \GaletteAuto\State($this->zdb);
$state->value = 'Wrec';
$this->assertTrue($state->store(true));
$id = $state->id;

$this->assertCount(2, $state->getList());
$this->assertSame('2 states', $state->displayCount());

$state = new \GaletteAuto\State($this->zdb);
$this->assertTrue($state->load($id));
$state->value = 'Wreck';
$this->assertTrue($state->store());

$this->assertCount(2, $state->getList());
$this->assertSame('2 states', $state->displayCount());

$state = new \GaletteAuto\State($this->zdb);
$this->assertTrue($state->delete([$first_id]));
$list = $state->getList();
$this->assertCount(1, $list);
$last_state = $list[0];
$this->assertSame($id, $last_state->id_state);
}

/**
* Test load error
*
* @return void
*/
public function testLoadError(): void
{
$state = new \GaletteAuto\State($this->zdb);
$this->assertFalse($state->load(999));
}

/**
* Test getClassName
*
* @return void
*/
public function testGetClassName(): void
{
$this->assertSame('\\' . \GaletteAuto\State::class, \GaletteAuto\State::getClassForPropName('state'));
}
}
117 changes: 117 additions & 0 deletions tests/GaletteAuto/tests/units/Transmission.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<?php

/**
* Copyright © 2003-2024 The Galette Team
*
* This file is part of Galette (https://galette.eu).
*
* Galette is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Galette 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Galette. If not, see <http://www.gnu.org/licenses/>.
*/

namespace GaletteAuto\tests\units;

use Galette\GaletteTestCase;

/**
* Transmission tests
*
* @author Johan Cwiklinski <[email protected]>
*/
class Transmission extends GaletteTestCase
{
protected int $seed = 20240130141727;

/**
* Test empty
*
* @return void
*/
public function testEmpty(): void
{
$transmission = new \GaletteAuto\Transmission($this->zdb);
$this->assertSame('Transmission', $transmission->getFieldLabel());

$this->assertCount(0, $transmission->getList());
$this->assertSame('0 transmission', $transmission->displayCount());
}

/**
* Test add and update
*
* @return void
*/
public function testCrud(): void
{
$transmission = new \GaletteAuto\Transmission($this->zdb);
//ensure the table is empty
$this->assertCount(0, $transmission->getList());

//Add new transmission
$transmission->value = 'Manual';
$this->assertTrue($transmission->store(true));
$first_id = $transmission->id;

$this->assertCount(1, $transmission->getList());
$listed_transmission = $transmission->getList()[0];
$this->assertInstanceOf(\ArrayObject::class, $listed_transmission);
$this->assertGreaterThan(0, $listed_transmission->id_transmission);
$this->assertSame('Manual', $listed_transmission->transmission);
$this->assertSame('1 transmission', $transmission->displayCount());

//add another one
$transmission = new \GaletteAuto\Transmission($this->zdb);
$transmission->value = 'Auto';
$this->assertTrue($transmission->store(true));
$id = $transmission->id;

$this->assertCount(2, $transmission->getList());
$this->assertSame('2 transmissions', $transmission->displayCount());

$transmission = new \GaletteAuto\Transmission($this->zdb);
$this->assertTrue($transmission->load($id));
$transmission->value = 'Automatic';
$this->assertTrue($transmission->store());

$this->assertCount(2, $transmission->getList());
$this->assertSame('2 transmissions', $transmission->displayCount());

$transmission = new \GaletteAuto\Transmission($this->zdb);
$this->assertTrue($transmission->delete([$first_id]));
$list = $transmission->getList();
$this->assertCount(1, $list);
$last_transmission = $list[0];
$this->assertSame($id, $last_transmission->id_transmission);
}

/**
* Test load error
*
* @return void
*/
public function testLoadError(): void
{
$transmission = new \GaletteAuto\Transmission($this->zdb);
$this->assertFalse($transmission->load(999));
}

/**
* Test getClassName
*
* @return void
*/
public function testGetClassName(): void
{
$this->assertSame('\\' . \GaletteAuto\Transmission::class, \GaletteAuto\Transmission::getClassForPropName('transmission'));
}
}

0 comments on commit 1649ee9

Please sign in to comment.