diff --git a/~dev_rating/application/tests/classes/Model_Discipline_Test.php b/~dev_rating/application/tests/classes/Model_Discipline_Test.php index 33949f01716e153f00c67bd2ed76b1912594c664..41045157895bbdf6b60bbb89d9e0438f8673174d 100644 --- a/~dev_rating/application/tests/classes/Model_Discipline_Test.php +++ b/~dev_rating/application/tests/classes/Model_Discipline_Test.php @@ -2,5 +2,105 @@ class Model_Discipline_Test extends PHPUnit_Framework_TestCase { + /** + * @test + * @dataProvider incorrectArgumentsProvider + * @expectedException InvalidArgumentException + */ + public function createWithIncorrectArguments($name, $value) { + Model_Discipline::make()->fromSet([$name => $value]); + echo "createWithIncorrectArguments($name, $value)\n"; + } + public function incorrectArgumentsProvider() { + return [ + # 0 + ['author', 0], + ['author', -1], + ['faculty', 0], + ['faculty', -1], + ['grade', 0], + # 5 + ['grade', -1], + ['labs', -1], + ['practice', -1], + ['lectures', -1], + ['semester', 0], + # 10 + ['semester', -1], + ['type', 'i love php'], + ['type', ''], + ['type', 0], + ['type', -1], + # 15 + ['type', null], + ['subject', 0], + ['subject', -1], + ]; + } + + + /** + * @test + * @expectedException InvalidArgumentException + * @dataProvider notCompleteDataProvider + */ + public function passNotAllArgumentsToCreateDiscipline($data) { + Model_Discipline::make()->fromSet($data)->create()->delete(); + printf("%s(%s)\n", __METHOD__, json_encode($data, JSON_PRETTY_PRINT)); + } + + public function notCompleteDataProvider() { + $data = $this->correctRawDataProvider(); + foreach ($data as $arguments) { + foreach ($arguments as $raw) { + foreach ($raw as $name => $value) { + // removes one of the required fields + $copy = $data; + unset($copy[$name]); + yield $copy; + } + } + } + } + + public function correctRawDataProvider() { + return [ + # one function call + [ + # one argument + [ + 'author' => 1, + 'faculty' => 1, + 'grade' => 1, + 'lectures' => 0, + 'labs' => 0, + 'practice' => 0, + 'semester' => 1, + 'type' => Model_Discipline::CREDIT, + 'subject' => 1, + ] + ] + ]; + } + + + /** @test */ + public function checkNonExistingDiscipline() { + $this->assertFalse(Model_Discipline::load(PHP_INT_MAX)->exists()); + } + + /** + * @test + * @dataProvider correctRawDataProvider + */ + public function createDisciplineAndCheckExistence($data) { + $builder = Model_Discipline::make()->fromSet($data); + + $discipline = $builder->create(); + + $this->assertTrue($discipline->exists()); + + $discipline->delete(); + } }