diff --git a/composer.json b/composer.json index 05c6c23..c41c76d 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "watoki/stepper": "*" }, "require-dev": { - "rtens/mockster": "1.1.*", + "rtens/mockster": "*", "watoki/scrut": "*", "phpunit/phpunit": "3.7.*" }, diff --git a/composer.lock b/composer.lock index 0c0f375..25105d5 100644 --- a/composer.lock +++ b/composer.lock @@ -3,7 +3,7 @@ "This file locks the dependencies of your project to a known state", "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file" ], - "hash": "8c31bce8260d1bab678230f9d961435c", + "hash": "26c14bcf4b9a1d57058c16d136f10e70", "packages": [ { "name": "symfony/console", @@ -12,12 +12,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Console.git", - "reference": "b9ed9d61ff84296c9ace5ac333c15e6f35062eeb" + "reference": "bcad0c271065f6deb00014893dba80c849880b7b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Console/zipball/b9ed9d61ff84296c9ace5ac333c15e6f35062eeb", - "reference": "b9ed9d61ff84296c9ace5ac333c15e6f35062eeb", + "url": "https://api.github.com/repos/symfony/Console/zipball/bcad0c271065f6deb00014893dba80c849880b7b", + "reference": "bcad0c271065f6deb00014893dba80c849880b7b", "shasum": "" }, "require": { @@ -50,7 +50,7 @@ ], "description": "Symfony Console Component", "homepage": "http://symfony.com", - "time": "2013-08-17 16:29:09" + "time": "2013-09-05 13:35:47" }, { "name": "watoki/collections", @@ -418,18 +418,62 @@ } ], "packages-dev": [ + { + "name": "nikic/php-parser", + "version": "v0.9.4", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "1e5e280ae88a27effa2ae4aa2bd088494ed8594f" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/1e5e280ae88a27effa2ae4aa2bd088494ed8594f", + "reference": "1e5e280ae88a27effa2ae4aa2bd088494ed8594f", + "shasum": "" + }, + "require": { + "php": ">=5.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.9-dev" + } + }, + "autoload": { + "psr-0": { + "PHPParser": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "time": "2013-08-25 17:11:40" + }, { "name": "phpunit/php-code-coverage", "version": "1.2.x-dev", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/php-code-coverage.git", - "reference": "906a767726f5bd451fbbe1d300ed46600d6c0934" + "reference": "466e7cd2554b4e264c9e3f31216d25ac0e5f3d94" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/906a767726f5bd451fbbe1d300ed46600d6c0934", - "reference": "906a767726f5bd451fbbe1d300ed46600d6c0934", + "url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/466e7cd2554b4e264c9e3f31216d25ac0e5f3d94", + "reference": "466e7cd2554b4e264c9e3f31216d25ac0e5f3d94", "shasum": "" }, "require": { @@ -477,7 +521,7 @@ "testing", "xunit" ], - "time": "2013-08-13 01:20:13" + "time": "2013-09-10 08:14:32" }, { "name": "phpunit/php-file-iterator", @@ -668,12 +712,12 @@ "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "780cdb1d5f693e2c8a9b7ce30b790ecb3e8194e1" + "reference": "162da5b9efbf2d483d4ee93dc54b7266d30beae2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/780cdb1d5f693e2c8a9b7ce30b790ecb3e8194e1", - "reference": "780cdb1d5f693e2c8a9b7ce30b790ecb3e8194e1", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/162da5b9efbf2d483d4ee93dc54b7266d30beae2", + "reference": "162da5b9efbf2d483d4ee93dc54b7266d30beae2", "shasum": "" }, "require": { @@ -734,7 +778,7 @@ "testing", "xunit" ], - "time": "2013-08-26 13:31:34" + "time": "2013-09-10 08:23:58" }, { "name": "phpunit/phpunit-mock-objects", @@ -796,19 +840,20 @@ }, { "name": "rtens/mockster", - "version": "1.1.4", + "version": "dev-master", "source": { "type": "git", "url": "https://github.com/rtens/mockster.git", - "reference": "1303167621ac7225de33e478271681b3d445526a" + "reference": "8540fdd101cfed59d444ea150a507e21d3c03dfc" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rtens/mockster/zipball/1303167621ac7225de33e478271681b3d445526a", - "reference": "1303167621ac7225de33e478271681b3d445526a", + "url": "https://api.github.com/repos/rtens/mockster/zipball/8540fdd101cfed59d444ea150a507e21d3c03dfc", + "reference": "8540fdd101cfed59d444ea150a507e21d3c03dfc", "shasum": "" }, "require": { + "nikic/php-parser": "0.9.4", "php": ">=5.3.2" }, "type": "library", @@ -837,7 +882,7 @@ "mocking", "unit testing" ], - "time": "2013-06-04 12:52:52" + "time": "2013-09-12 14:16:05" }, { "name": "symfony/yaml", @@ -846,12 +891,12 @@ "source": { "type": "git", "url": "https://github.com/symfony/Yaml.git", - "reference": "d717edb3fedd370baa5e2237641680d611d1c6a9" + "reference": "6286e95889e326311ff90ae4f96ddc15d6db2c39" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/Yaml/zipball/d717edb3fedd370baa5e2237641680d611d1c6a9", - "reference": "d717edb3fedd370baa5e2237641680d611d1c6a9", + "url": "https://api.github.com/repos/symfony/Yaml/zipball/6286e95889e326311ff90ae4f96ddc15d6db2c39", + "reference": "6286e95889e326311ff90ae4f96ddc15d6db2c39", "shasum": "" }, "require": { @@ -884,7 +929,7 @@ ], "description": "Symfony Yaml Component", "homepage": "http://symfony.com", - "time": "2013-08-23 15:14:52" + "time": "2013-08-29 06:54:01" }, { "name": "watoki/scrut", @@ -892,24 +937,22 @@ "source": { "type": "git", "url": "https://github.com/watoki/scrut.git", - "reference": "055dac5b6df51316b9cf005ecc6df6dfcd5e54e7" + "reference": "3b6c2572281a17d6dd26c15abe9e582e9dd370b3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/watoki/scrut/zipball/055dac5b6df51316b9cf005ecc6df6dfcd5e54e7", - "reference": "055dac5b6df51316b9cf005ecc6df6dfcd5e54e7", + "url": "https://api.github.com/repos/watoki/scrut/zipball/3b6c2572281a17d6dd26c15abe9e582e9dd370b3", + "reference": "3b6c2572281a17d6dd26c15abe9e582e9dd370b3", "shasum": "" }, "require": { "php": ">=5.3.8", + "phpunit/phpunit": "3.7.*", + "rtens/mockster": "*", "watoki/curir": "*", "watoki/factory": "*", "watoki/stache": "*" }, - "require-dev": { - "phpunit/phpunit": "3.7.*", - "rtens/mockster": "1.*" - }, "type": "library", "autoload": { "psr-0": { @@ -928,13 +971,15 @@ "homepage": "http://rtens.org" } ], - "description": "Testing framework based on curir.", + "description": "Live documentation web application for PHP.", "homepage": "http://github.com/watoki/scrut", "keywords": [ + "SbE", + "living documentation", "test", "watoki" ], - "time": "2013-07-24 07:44:28" + "time": "2013-09-12 17:37:32" } ], "aliases": [ diff --git a/phpunit.xml.dist b/phpunit.xml.dist old mode 100644 new mode 100755 diff --git a/spec/rtens/lacarte/Test.php b/spec/rtens/lacarte/Test.php deleted file mode 100644 index 83ed0a8..0000000 --- a/spec/rtens/lacarte/Test.php +++ /dev/null @@ -1,155 +0,0 @@ -stateFile = __DIR__ . '/migration' . uniqid(); - - $this->mf = new MockFactory(); - - $this->userFilesDir = __DIR__ . '/__userfiles'; - $this->cleanUp($this->userFilesDir); - mkdir($this->userFilesDir); - - $this->config = $this->mf->createMock(Configuration::Configuration); - $this->config->__mock()->method('getPdoDataSourceName')->willReturn('sqlite::memory:'); - $this->config->__mock()->method('getHost')->willReturn('http://lacarte'); - $this->config->__mock()->method('getUserFilesDirectory')->willReturn($this->userFilesDir); - - $this->factory = new Factory(); - $this->factory->setSingleton(Configuration::Configuration, $this->config); - - if (file_exists($this->stateFile)) unlink($this->stateFile); - $this->migrate(); - - $this->createSteps(); - } - - public function tearDown() { - unlink($this->stateFile); - - $this->cleanUp($this->userFilesDir); - - parent::tearDown(); - } - - private function migrate() { - $migrater = new Migrater($this->factory, 'rtens\lacarte\model\migration', $this->stateFile); - $migrater->migrate(); - } - - private function createSteps() { - foreach (array('given', 'when', 'then') as $steps) { - $class = get_class($this); - while ($class) { - $stepClass = $class . '_' . ucfirst($steps); - if (class_exists($stepClass)) { - $this->$steps = $this->factory->getInstance($stepClass, array('test' => $this)); - break; - } - $refl = new \ReflectionClass($class); - $class = $refl->getParentClass()->getName(); - } - } - } - - private function cleanUp($dir) { - foreach (glob($dir . '/*') as $file) { - if (is_dir($file)) { - $this->cleanUp($file); - } else { - @unlink($file); - } - } - @rmdir($dir); - } - -} - -/** - * @property Test test - */ -class Test_Given { - - function __construct(Test $test) { - $this->test = $test; - } - -} - -/** - * @property Test test - */ -class Test_When { - - /** - * @var null|\Exception - */ - public $caught; - - function __construct(Test $test) { - $this->test = $test; - } - -} - -/** - * @property Test test - */ -class Test_Then { - - function __construct(Test $test) { - $this->test = $test; - } - - protected function getFieldIn($string, $field) { - foreach (explode('/', $string) as $key) { - if (!array_key_exists($key, $field)) { - throw new \Exception("Could not find '$key' in " . json_encode($field)); - } - $field = $field[$key]; - } - return $field; - } - - public function anExceptionShouldBeThrownContaining($msg) { - $this->test->assertNotNull($this->test->when->caught, 'No exception was thrown'); - $this->test->assertContains($msg, $this->test->when->caught->getMessage()); - } - -} diff --git a/spec/rtens/lacarte/TestCase.php b/spec/rtens/lacarte/TestCase.php new file mode 100644 index 0000000..a7d5345 --- /dev/null +++ b/spec/rtens/lacarte/TestCase.php @@ -0,0 +1,65 @@ +mockFactory = new MockFactory(); + parent::setUp(); + } + + protected function loadDependencies() { + + $userFilesDir = __DIR__ . '/__userfiles'; + $this->cleanUp($userFilesDir); + @mkdir($userFilesDir); + + $stateFile = $userFilesDir . '/migration' . uniqid(); + + $config = $this->mockFactory->createMock(Configuration::Configuration); + $config->__mock()->method('getPdoDataSourceName')->willReturn('sqlite::memory:'); + $config->__mock()->method('getHost')->willReturn('http://lacarte'); + $config->__mock()->method('getUserFilesDirectory')->willReturn($userFilesDir); + $this->factory->setSingleton(Configuration::Configuration, $config); + + if (file_exists($stateFile)) + unlink($stateFile); + + $that = $this; + $this->undos[] = function () use ($that, $stateFile, $userFilesDir) { + unlink($stateFile); + $that->cleanUp($userFilesDir); + }; + + $this->migrate($stateFile); + + parent::loadDependencies(); + } + + private function migrate($stateFile) { + $migrater = new Migrater($this->factory, 'rtens\lacarte\model\migration', $stateFile); + $migrater->migrate(); + } + + public function cleanUp($dir) { + foreach (glob($dir . '/*') as $file) { + if (is_dir($file)) { + $this->cleanUp($file); + } else { + @unlink($file); + } + } + @rmdir($dir); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/features/order/CreateOrderTest.php b/spec/rtens/lacarte/features/order/CreateOrderTest.php deleted file mode 100644 index ff13ebe..0000000 --- a/spec/rtens/lacarte/features/order/CreateOrderTest.php +++ /dev/null @@ -1,119 +0,0 @@ -when->iCreateAnOrderBetween_And_WithDeadline('2013-04-08', '2013-04-12', '2013-04-04 18:00'); - - $this->then->thereShouldBeAnOrder(); - $this->then->theNameShouldBe('08.04.2013 - 12.04.2013'); - $this->then->theDeadlineShouldBe('2013-04-04 18:00'); - $this->then->theOrderShouldHave_Menus(5); - $this->then->theDateOfMenu_ShouldBe(0, '2013-04-08'); - $this->then->theDateOfMenu_ShouldBe(4, '2013-04-12'); - $this->then->eachMenuShouldHave_Dishes(3); - } - - function testOverTheWeekend() { - $this->when->iCreateAnOrderBetween_And_WithDeadline('2013-04-03', '2013-04-13', '2013-04-01 18:00'); - - $this->then->thereShouldBeAnOrder(); - $this->then->theOrderShouldHave_Menus(8); - $this->then->theDateOfMenu_ShouldBe(0, '2013-04-03'); - $this->then->theDateOfMenu_ShouldBe(7, '2013-04-12'); - } - - function testEndBeforeStart() { - $this->when->iTryToCreateAnOrderBetween_And_WithDeadline('2013-04-13', '2013-04-03', '2013-04-01 18:00'); - $this->then->anExceptionShouldBeThrownContaining('before'); - } - - function testDeadlineAfterStart() { - $this->when->iTryToCreateAnOrderBetween_And_WithDeadline('2013-04-03', '2013-04-13', '2013-04-04 18:00'); - $this->then->anExceptionShouldBeThrownContaining('before'); - } - -} - -/** - * @property CreateOrderTest test - */ -class CreateOrderTest_When extends Test_When { - - /** @var Order */ - public $order; - - /** @var OrderInteractor */ - public $orderInteractor; - - function __construct(Test $test) { - parent::__construct($test); - - $this->orderInteractor = $this->test->factory->getInstance(OrderInteractor::$CLASS); - } - - public function iCreateAnOrderBetween_And_WithDeadline($start, $end, $deadline) { - $groupId = 1; - $this->order = $this->orderInteractor->createOrder( - $groupId, new \DateTime($start), new \DateTime($end), new \DateTime($deadline)); - } - - public function iTryToCreateAnOrderBetween_And_WithDeadline($start, $end, $deadline) { - try { - $this->iCreateAnOrderBetween_And_WithDeadline($start, $end, $deadline); - } catch (\Exception $e) { - $this->caught = $e; - } - } -} - -/** - * @property CreateOrderTest test - */ -class CreateOrderTest_Then extends Test_Then { - - public function thereShouldBeAnOrder() { - $this->test->assertFalse($this->test->when->orderInteractor->readAll()->isEmpty()); - } - - public function theOrderShouldHave_Menus($int) { - $this->test->assertEquals($int, $this->test->when->orderInteractor->readMenusByOrderId( - $this->test->when->order->id)->count()); - } - - public function eachMenuShouldHave_Dishes($int) { - foreach ($this->getMenus() as $menu) { - $this->test->assertEquals($int, $this->test->when->orderInteractor->readDishesByMenuId($menu->id)->count()); - } - } - - public function theNameShouldBe($string) { - $this->test->assertEquals($string, $this->test->when->order->getName()); - } - - public function theDeadlineShouldBe($date) { - $this->test->assertEquals(new \DateTime($date), $this->test->when->order->getDeadline()); - } - - public function theDateOfMenu_ShouldBe($int, $date) { - $this->test->assertEquals(new \DateTime($date), $this->getMenus()->get($int)->getDate()); - } - - /** - * @return \rtens\lacarte\model\Menu[]|\watoki\collections\Liste - */ - private function getMenus() { - return $this->test->when->orderInteractor->readMenusByOrderId($this->test->when->order->id); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/features/order/ReadAllTest.php b/spec/rtens/lacarte/features/order/ReadAllTest.php deleted file mode 100644 index f54163b..0000000 --- a/spec/rtens/lacarte/features/order/ReadAllTest.php +++ /dev/null @@ -1,69 +0,0 @@ -given->theOrder_WithDeadline('test1', '2013-04-01'); - $this->given->theOrder_WithDeadline('test3', '2013-04-03'); - $this->given->theOrder_WithDeadline('test2', '2013-04-02'); - - $this->when->iReadAllOrders(); - - $this->then->order_ShouldBe(1, 'test3'); - $this->then->order_ShouldBe(2, 'test2'); - $this->then->order_ShouldBe(3, 'test1'); - } - -} - -class ReadAllTest_Given extends Test_Given { - - function __construct(Test $test, OrderStore $store) { - parent::__construct($test); - $this->store = $store; - } - - public function theOrder_WithDeadline($name, $date) { - $this->store->create(new Order(42, $name, new \DateTime($date))); - } -} - -class ReadAllTest_When extends Test_When { - - /** @var Order[] */ - public $orders; - - function __construct(Test $test, OrderInteractor $interactor) { - parent::__construct($test); - $this->interactor = $interactor; - } - - public function iReadAllOrders() { - $this->orders = $this->interactor->readAll(); - } -} - -/** - * @property ReadAllTest test - * @property ReadAllTest test - */ -class ReadAllTest_Then extends Test_Then { - - public function order_ShouldBe($index, $name) { - $this->test->assertEquals($name, $this->test->when->orders[$index - 1]->getName()); - } -} diff --git a/spec/rtens/lacarte/features/order/SaveOrderTest.php b/spec/rtens/lacarte/features/order/SaveOrderTest.php deleted file mode 100644 index c8e0f90..0000000 --- a/spec/rtens/lacarte/features/order/SaveOrderTest.php +++ /dev/null @@ -1,150 +0,0 @@ -given->anOrderWith_MenusAnd_DishesEach(2, 2); - $this->given->dish_OfMenu_Is(1, 1, 'A'); - $this->given->dish_OfMenu_Is(2, 1, 'B'); - $this->given->dish_OfMenu_Is(1, 2, 'C'); - $this->given->dish_OfMenu_Is(2, 2, 'D'); - - $this->when->iSaveTheOrder(); - - $this->then->thereShouldBe_Dishes(4); - $this->then->dish_ShouldBe(1, 'A'); - $this->then->dish_ShouldBe(2, 'B'); - $this->then->dish_ShouldBe(3, 'C'); - $this->then->dish_ShouldBe(4, 'D'); - } - - function testEmptyDishes() { - $this->given->anOrderWith_MenusAnd_DishesEach(2, 2); - $this->given->dish_OfMenu_Is(1, 1, 'A'); - $this->given->dish_OfMenu_Is(2, 1, ''); - $this->given->dish_OfMenu_Is(1, 2, ''); - $this->given->dish_OfMenu_Is(2, 2, 'D'); - - $this->when->iSaveTheOrder(); - - $this->then->thereShouldBe_Dishes(2); - $this->then->dish_ShouldBe(1, 'A'); - $this->then->dish_ShouldBe(4, 'D'); - } - - function testEmptyMenu() { - $this->given->anOrderWith_MenusAnd_DishesEach(2, 2); - $this->given->dish_OfMenu_Is(1, 1, 'A'); - $this->given->dish_OfMenu_Is(2, 1, 'B'); - $this->given->dish_OfMenu_Is(1, 2, ''); - $this->given->dish_OfMenu_Is(2, 2, ''); - - $this->when->iSaveTheOrder(); - - $this->then->thereShouldBe_Dishes(2); - $this->then->thereShouldBe_Menus(1); - } - -} - -class SaveOrderTest_Given extends Test_Given { - - /** @var array|array[]|Dish[][] */ - public $dishes; - - /** @var Order|null */ - public $order; - - function __construct(Test $test, OrderStore $orderStore, MenuStore $menuStore, DishStore $dishStore) { - parent::__construct($test); - $this->orderStore = $orderStore; - $this->menuStore = $menuStore; - $this->dishStore = $dishStore; - } - - public function anOrderWith_MenusAnd_DishesEach($numMenus, $numDishes) { - $this->order = new Order(1, 'test', new \DateTime('2000-01-01')); - $this->orderStore->create($this->order); - - $this->dishes = array(); - for ($m = 0; $m < $numMenus; $m++) { - $menu = new Menu($this->order->id, new \DateTime('2000-01-' . $m)); - $this->menuStore->create($menu); - - $dishes = array(); - for ($d = 0; $d < $numDishes; $d++) { - $dish = new Dish($menu->id, ''); - $this->dishStore->create($dish); - $dishes[] = $dish; - } - $this->dishes[] = $dishes; - } - } - - public function dish_OfMenu_Is($numDish, $numMenu, $text) { - /** @var Dish $dish */ - $dish = $this->dishes[$numMenu - 1][$numDish - 1]; - $dish->setText($text); - } -} - -/** - * @property SaveOrderTest test - */ -class SaveOrderTest_When extends Test_When { - - function __construct(Test $test, OrderInteractor $interactor) { - parent::__construct($test); - $this->interactor = $interactor; - } - - public function iSaveTheOrder() { - $dishes = new Set(); - foreach ($this->test->given->dishes as $menu) { - foreach ($menu as $dish) { - $dishes[] = $dish; - } - } - $this->interactor->updateDishes($dishes); - } -} - -class SaveOrderTest_Then extends Test_Then { - - function __construct(Test $test, DishStore $dishStore, MenuStore $menuStore) { - parent::__construct($test); - $this->dishStore = $dishStore; - $this->menuStore = $menuStore; - } - - public function thereShouldBe_Dishes($count) { - $this->test->assertEquals($count, $this->dishStore->readAll()->count()); - } - - public function dish_ShouldBe($id, $text) { - $this->test->assertEquals($text, $this->dishStore->readById($id)->getText()); - } - - public function thereShouldBe_Menus($int) { - $this->test->assertEquals($int, $this->menuStore->readAll()->count()); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/features/order/SaveSelectionTest.php b/spec/rtens/lacarte/features/order/SaveSelectionTest.php deleted file mode 100644 index b553a04..0000000 --- a/spec/rtens/lacarte/features/order/SaveSelectionTest.php +++ /dev/null @@ -1,124 +0,0 @@ -given->aNewSelection(); - $this->given->anExistingSelection(); - - $this->when->iSaveTheSelections(); - - $this->then->thereShouldBe_Selections(2); - } - - function testReadSelection() { - $this->given->theSelectionOfMenu_AndUser(54, 12); - $this->given->theSelectionOfMenu_AndUser(54, 13); - $this->given->theSelectionOfMenu_AndUser(52, 12); - - $this->when->iReadTheSelectionForMenu_AndUser(54, 12); - - $this->then->iShouldFindASelection(); - } - - function testNoSelection() { - $this->given->theSelectionOfMenu_AndUser(54, 13); - $this->given->theSelectionOfMenu_AndUser(52, 12); - - $this->when->iTryToReadTheSelectionForMenu_AndUser(54, 12); - - $this->then->anExceptionShouldBeThrownContaining('Empty result'); - } - -} - -/** - * @property SaveSelectionTest test - */ -class SaveSelectionTest_Given extends Test_Given { - - /** @var Set */ - public $selections; - - function __construct(Test $test, SelectionStore $store) { - parent::__construct($test); - $this->selections = new Set(); - $this->store = $store; - } - - public function aNewSelection() { - $this->selections->put(new Selection(211, count($this->selections) + 1, 3333)); - } - - public function anExistingSelection() { - $selection = new Selection(121, count($this->selections) + 1, 4444); - $this->store->create($selection); - $this->selections->put($selection); - } - - public function theSelectionOfMenu_AndUser($menuId, $userId) { - $selection = new Selection($userId, $menuId, 4123); - $this->store->create($selection); - } - -} - -/** - * @property SaveSelectionTest test - */ -class SaveSelectionTest_When extends Test_When { - - /** @var Selection */ - public $selection; - - function __construct(Test $test, OrderInteractor $interactor) { - parent::__construct($test); - $this->interactor = $interactor; - } - - public function iSaveTheSelections() { - $this->interactor->saveSelections($this->test->given->selections); - } - - public function iReadTheSelectionForMenu_AndUser($menuId, $userId) { - $this->selection = $this->interactor->readSelectionByMenuIdAndUserId($menuId, $userId); - } - - public function iTryToReadTheSelectionForMenu_AndUser($menuId, $userId) { - try { - $this->iReadTheSelectionForMenu_AndUser($menuId, $userId); - } catch (\Exception $e) { - $this->caught = $e; - } - } - -} - -/** - * @property SaveSelectionTest test - */ -class SaveSelectionTest_Then extends Test_Then { - - public function thereShouldBe_Selections($count) { - $this->test->assertEquals($count, $this->test->given->store->readAll()->count()); - } - - public function iShouldFindASelection() { - $this->test->assertNotNull($this->test->when->selection); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/features/order/SendEmailTest.php b/spec/rtens/lacarte/features/order/SendEmailTest.php deleted file mode 100644 index 6f5f0af..0000000 --- a/spec/rtens/lacarte/features/order/SendEmailTest.php +++ /dev/null @@ -1,163 +0,0 @@ -setUpGroupAndUsers(); - - $this->when->iSendAnEmailToAllForOrder('Test'); - - $this->then->_EmailsShouldBeSent(2); - $this->then->anEmailShouldBeSentTo_From_WithTheSubject_AndTheBody('max@example.de', 'test@group.de', - 'Choose, Max', 'Max: http://lacarte/order/select.html?order=42&key=max123'); - $this->then->anEmailShouldBeSentTo_From_WithTheSubject_AndTheBody('karl@example.de', 'test@group.de', - 'Choose, Karl', 'Karl: http://lacarte/order/select.html?order=42&key=oi321'); - } - - function testSendOnlyToOnesWithoutSelection() { - $this->setUpGroupAndUsers(); - - $this->given->_HasASelectionForOrder('Karl Marx', 'Test'); - - $this->when->iSendAnEmailToUsersWithoutSelectionForOrder('Test'); - - $this->then->_EmailsShouldBeSent(1); - $this->then->anEmailShouldBeSentTo_From_WithTheSubject_AndTheBody('max@example.de', 'test@group.de', - 'Choose, Max', 'Max: http://lacarte/order/select.html?order=42&key=max123'); - } - - private function setUpGroupAndUsers() { - $this->given->theGroup_WithTheAdminEmail('Test Group', 'test@group.de'); - $this->given->theOrder_WithId('Test', 42); - $this->given->theUser_WithTheEmail_AndTheKey('Max', 'max@example.de', 'max123'); - $this->given->theUser_WithTheEmail_AndTheKey('Karl Marx', 'karl@example.de', 'oi321'); - - $this->given->theSubjectIs('Choose, {name}'); - $this->given->theBodyIs('{name}: {url}'); - } -} - -class SendEmailTest_Given extends Test_Given { - - /** @var Order[] */ - public $orders = array(); - public $subject; - public $body; - - /** @var Group */ - public $group; - - /** @var User[] */ - public $users = array(); - - function __construct(Test $test, UserStore $userStore, GroupStore $groupStore, - SelectionStore $selectionStore, MenuStore $menuStore) { - parent::__construct($test); - $this->userStore = $userStore; - $this->groupStore = $groupStore; - $this->selectionStore = $selectionStore; - $this->menuStore = $menuStore; - } - - public function theGroup_WithTheAdminEmail($name, $email) { - $this->group = new Group($name, $email, ''); - $this->groupStore->create($this->group); - } - - public function theUser_WithTheEmail_AndTheKey($name, $email, $key) { - $this->users[$name] = new User($this->group->id, $name, $email, $key); - $this->userStore->create($this->users[$name]); - } - - public function theSubjectIs($string) { - $this->subject = $string; - } - - public function theBodyIs($string) { - $this->body = $string; - } - - public function theOrder_WithId($name, $id) { - $this->orders[$name] = new Order($this->group->id, $name, new \DateTime()); - $this->orders[$name]->id = $id; - } - - public function _HasASelectionForOrder($user, $order) { - $menu = new Menu($this->orders[$order]->id, new \DateTime()); - $this->menuStore->create($menu); - $this->selectionStore->create(new Selection($this->users[$user]->id, $menu->id, 0)); - } -} - -/** - * @property SendEmailTest test - * @property OrderInteractor orderInteractor - */ -class SendEmailTest_When extends Test_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->mailService = $test->mf->createMock(MailService::$CLASS); - $this->orderInteractor = $test->factory->getInstance(OrderInteractor::$CLASS, array( - 'mailService' => $this->mailService - )); - } - - public function iSendAnEmailToAllForOrder($name) { - $g = $this->test->given; - $this->orderInteractor->sendMail($g->orders[$name], $g->subject, $g->body); - } - - public function iSendAnEmailToUsersWithoutSelectionForOrder($name) { - $g = $this->test->given; - $this->orderInteractor->sendMail($g->orders[$name], $g->subject, $g->body, true); - } -} - -/** - * @property SendEmailTest test - */ -class SendEmailTest_Then extends Test_Then { - - public function _EmailsShouldBeSent($int) { - $this->test->assertEquals($int, $this->getSendMethod()->getCalledCount()); - } - - public function anEmailShouldBeSentTo_From_WithTheSubject_AndTheBody($email, $from, $subject, $body) { - foreach ($this->getSendMethod()->getCalledArguments() as $arguments) { - if (in_array($email, $arguments)) { - $this->test->assertEquals($from, $arguments['from']); - $this->test->assertEquals($subject, $arguments['subject']); - $this->test->assertEquals($body, $arguments['body']); - return; - } - } - $this->test->fail('No email sent to ' . $email); - } - - private function getSendMethod() { - return $this->test->when->mailService->__mock()->method('send'); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/features/user/AuthenticateUserTest.php b/spec/rtens/lacarte/features/user/AuthenticateUserTest.php deleted file mode 100644 index de59414..0000000 --- a/spec/rtens/lacarte/features/user/AuthenticateUserTest.php +++ /dev/null @@ -1,109 +0,0 @@ -given->theGroup('test'); - $this->given->theUser_WithTheKey('John', 'someKey'); - - $this->when->iAuthenticateWithTheKey('someKey'); - - $this->then->iShouldBeLoggedInAs('John'); - } - - function testIncorrectKey() { - $this->given->theGroup('test'); - $this->given->theUser_WithTheKey('John', 'someKey'); - - $this->when->iAuthenticateWithTheKey('wrongKey'); - - $this->then->iShouldNotBeLoggedIn(); - } - -} - -/** - * @property AuthenticateUserTest test - */ -class AuthenticateUserTest_Given extends Test_Given { - - /** @var Group */ - public $group; - - /** @var GroupStore */ - private $groupStore; - - /** @var UserStore */ - private $userStore; - - function __construct(Test $test) { - parent::__construct($test); - $this->groupStore = $test->factory->getInstance(GroupStore::$CLASS); - $this->userStore = $test->factory->getInstance(UserStore::$CLASS); - } - - public function theGroup($name) { - $this->group = new Group($name, '', ''); - $this->groupStore->create($this->group); - } - - public function theUser_WithTheKey($name, $key) { - $this->userStore->create(new User($this->group->id, $name, $name . '@example.com', $key)); - } -} - -/** - * @property AuthenticateUserTest test - */ -class AuthenticateUserTest_When extends Test_When { - - /** - * @var null|User - */ - public $user; - - /** - * @var UserInteractor - */ - private $userInteractor; - - function __construct(Test $test) { - parent::__construct($test); - $this->userInteractor = $test->factory->getInstance(UserInteractor::$CLASS); - } - - public function iAuthenticateWithTheKey($key) { - $this->user = $this->userInteractor->authorizeUser($key); - } -} - -/** - * @property AuthenticateUserTest test - */ -class AuthenticateUserTest_Then extends Test_Then { - - public function iShouldBeLoggedInAs($userName) { - $this->test->assertNotNull($this->test->when->user, 'Not logged-in'); - $this->test->assertEquals($userName, $this->test->when->user->getName()); - } - - public function iShouldNotBeLoggedIn() { - $this->test->assertNull($this->test->when->user); - } -} diff --git a/spec/rtens/lacarte/features/user/AuthorizeAdminTest.php b/spec/rtens/lacarte/features/user/AuthorizeAdminTest.php deleted file mode 100644 index b8d383a..0000000 --- a/spec/rtens/lacarte/features/user/AuthorizeAdminTest.php +++ /dev/null @@ -1,94 +0,0 @@ -given->theGroup_WithAdminEmail_AndPassword('TestGroup', 'john', 'asd'); - - $this->when->iTryToLogInWith('john', 'asd'); - - $this->then->iShouldBeAuthorizedForTheGroup('TestGroup'); - } - - function testIncorrectCredentials() { - $this->given->theGroup_WithAdminEmail_AndPassword('TestGroup', 'john', 'asd'); - - $this->when->iTryToLogInWith('john', 'bla'); - - $this->then->iShouldNotBeAuthorized(); - } - -} - -/** - * @property AuthorizeAdminTest test - */ -class AuthorizeAdminTest_Given extends Test_Given { - - /** - * @var GroupStore - */ - private $groupStore; - - function __construct(Test $test) { - $this->groupStore = $test->factory->getInstance(GroupStore::$CLASS); - } - - public function theGroup_WithAdminEmail_AndPassword($groupName, $email, $password) { - $group = new Group($groupName, $email, $password); - $this->groupStore->create($group); - } -} - -/** - * @property AuthorizeAdminTest test - */ -class AuthorizeAdminTest_When extends Test_When { - - /** - * @var Group - */ - public $authorizedGroup; - - /** - * @var UserInteractor - */ - private $userInteractor; - - function __construct(Test $test) { - parent::__construct($test); - $this->userInteractor = $test->factory->getInstance(UserInteractor::$CLASS); - } - - public function iTryToLogInWith($email, $password) { - $this->authorizedGroup = $this->userInteractor->authorizeAdmin($email, $password); - } -} - -/** - * @property AuthorizeAdminTest test - */ -class AuthorizeAdminTest_Then extends Test_Then { - - public function iShouldBeAuthorizedForTheGroup($groupName) { - $this->test->assertNotNull($this->test->when->authorizedGroup); - $this->test->assertEquals($groupName, $this->test->when->authorizedGroup->getName()); - } - - public function iShouldNotBeAuthorized() { - $this->test->assertNull($this->test->when->authorizedGroup); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/features/user/CreateUserTest.php b/spec/rtens/lacarte/features/user/CreateUserTest.php deleted file mode 100644 index 35ae2d9..0000000 --- a/spec/rtens/lacarte/features/user/CreateUserTest.php +++ /dev/null @@ -1,195 +0,0 @@ -given->theGroup('test'); - $this->given->theNextGeneratedKeyIs('myKey'); - } - - function testSuccess() { - $this->given->theName('Marina'); - $this->given->theEmail('M@gnz.es'); - - $this->when->iCreateANewUserForTheGroup(); - - $this->then->theUserShouldBeCreated(); - $this->then->thereShouldBeAUser('Marina', 'm@gnz.es'); - $this->then->theUserShouldHaveAKey(); - } - - function testEmptyName() { - $this->given->theEmail('some@mail.com'); - - $this->when->iTryToCreateANewUserForTheGroup(); - - $this->then->anExceptionShouldBeThrownContaining('name'); - } - - function testEmptyEmail() { - $this->given->theName('John'); - - $this->when->iTryToCreateANewUserForTheGroup(); - - $this->then->anExceptionShouldBeThrownContaining('name'); - } - - function testAlreadyExistingEmail() { - $this->given->theExistingUser('Peter', 'peter@parker.com', 'noKey'); - $this->given->theName('Spider Man'); - $this->given->theEmail('peter@parker.com'); - - $this->when->iTryToCreateANewUserForTheGroup(); - - $this->then->anExceptionShouldBeThrownContaining('exist'); - } - - function testAlreadyExistingEmailWithDifferentCasing() { - $this->given->theExistingUser('Peter', 'peter@parker.com', 'noKey'); - $this->given->theName('Spider Man'); - $this->given->theEmail('Peter@Parker.com'); - - $this->when->iTryToCreateANewUserForTheGroup(); - - $this->then->anExceptionShouldBeThrownContaining('exist'); - } - - function testAlreadyExistingKey() { - $this->given->theExistingUser('Peter', 'peter@parker.com', 'myKey'); - $this->given->theName('John'); - $this->given->theEmail('john@wayne.com'); - - $this->given->theNextGeneratedKeyIs('yourKey'); - $this->given->theNextGeneratedKeyIs('myKey'); - - $this->when->iCreateANewUserForTheGroup(); - - $this->then->theUserShouldBeCreated(); - $this->then->thereShouldBeAUser_WithKey('John', 'john@wayne.com', 'yourKey'); - } - -} - -/** - * @property CreateUserTest test - */ -class CreateUserTest_Given extends ComponentTest_Given { - - public $name; - - public $email; - - /** @var Group */ - public $group; - - /** @var GroupStore */ - public $groupStore; - - /** @var UserStore */ - public $userStore; - - function __construct(Test $test) { - parent::__construct($test); - $this->groupStore = $this->test->factory->getInstance(GroupStore::$CLASS); - $this->userStore = $this->test->factory->getInstance(UserStore::$CLASS); - - $this->keyGenerator = $this->test->mf->createMock(KeyGenerator::$CLASS); - $this->test->factory->setSingleton(KeyGenerator::$CLASS, $this->keyGenerator); - } - - public function theName($name) { - $this->name = $name; - } - - public function theEmail($email) { - $this->email = $email; - } - - public function theGroup($name) { - $this->group = new Group($name, '', ''); - $this->groupStore->create($this->group); - } - - public function theExistingUser($name, $email, $key) { - $this->userStore->create(new User($this->group->id, $name, $email, $key)); - } - - public function theNextGeneratedKeyIs($key) { - $this->keyGenerator->__mock()->method('generateUnique')->willReturn($key)->once(); - } -} - -/** - * @property CreateUserTest test - */ -class CreateUserTest_When extends Test_When { - - /** - * @var User - */ - public $user; - - public function iCreateANewUserForTheGroup() { - /** @var UserInteractor $interactor */ - $interactor = $this->test->factory->getInstance(UserInteractor::$CLASS); - $this->user = $interactor->createUser($this->test->given->group->id, - $this->test->given->name, $this->test->given->email); - } - - public function iTryToCreateANewUserForTheGroup() { - try { - $this->iCreateANewUserForTheGroup(); - } catch (\Exception $e) { - $this->caught = $e; - } - } -} - -/** - * @property CreateUserTest test - */ -class CreateUserTest_Then extends Test_Then { - - public function thereShouldBeAUser($name, $email) { - /** @var UserStore $store */ - $store = $this->test->factory->getInstance(UserStore::$CLASS); - $user = $store->readByEmail($email); - $this->test->assertEquals($name, $user->getName()); - return $user; - } - - public function thereShouldBeAUser_WithKey($name, $email, $key) { - $user = $this->thereShouldBeAUser($name, $email); - $this->test->assertEquals($key, $user->getKey()); - } - - public function theUserShouldBeCreated() { - $this->test->assertNotNull($this->test->when->user); - } - - public function theUserShouldHaveAKey() { - $this->test->assertNotNull($this->test->when->user->getKey()); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/features/user/DeleteUserTest.php b/spec/rtens/lacarte/features/user/DeleteUserTest.php deleted file mode 100644 index 13fe08b..0000000 --- a/spec/rtens/lacarte/features/user/DeleteUserTest.php +++ /dev/null @@ -1,69 +0,0 @@ -given->theUser('Test'); - $this->given->theUser('Mo'); - - $this->when->iDeleteTheUser('Test'); - - $this->then->thereShouldBe_User(1); - } - -} - -class DeleteUserTest_Given extends Test_Given { - - /** @var array|User[] */ - public $users = array(); - - function __construct(Test $test, UserStore $store) { - parent::__construct($test); - $this->store = $store; - } - - public function theUser($name) { - $this->users[$name] = new User(1, $name, "$name@test", "123$name"); - $this->store->create($this->users[$name]); - } -} - -/** - * @property DeleteUserTest test - */ -class DeleteUserTest_When extends Test_When { - - function __construct(Test $test, UserInteractor $interactor) { - parent::__construct($test); - $this->interactor = $interactor; - } - - public function iDeleteTheUser($name) { - $this->interactor->delete($this->test->given->users[$name]); - } -} - -/** - * @property DeleteUserTest test - */ -class DeleteUserTest_Then extends Test_Then { - - public function thereShouldBe_User($count) { - $this->test->assertEquals($count, $this->test->given->store->readAll()->count()); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/component/ComponentFixture.php b/spec/rtens/lacarte/fixtures/component/ComponentFixture.php new file mode 100644 index 0000000..683ffe5 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/component/ComponentFixture.php @@ -0,0 +1,55 @@ +user = $test->useFixture(UserFixture::$CLASS); + $test->useFixture(SessionFixture::$CLASS); + + $this->component = $factory->getInstance($this->getComponentClass(), array( + 'parent' => $root + )); + } + + public function thenIShouldBeRedirectedTo($url) { + $this->test->assertNull($this->model); + $this->test->assertEquals($url, + $this->component->getResponse()->getHeaders()->get(Response::HEADER_LOCATION)); + } + + protected function getFieldIn($string, $field) { + $this->test->assertTrue(is_array($field), $string . ' is not an array'); + + foreach (explode('/', $string) as $key) { + if (!array_key_exists($key, $field)) { + throw new \Exception("Could not find '$key' in " . json_encode($field)); + } + $field = $field[$key]; + } + return $field; + } + + protected function getField($string) { + return $this->getFieldIn($string, $this->model); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/component/export/DishesComponentFixture.php b/spec/rtens/lacarte/fixtures/component/export/DishesComponentFixture.php new file mode 100644 index 0000000..48e5fb6 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/component/export/DishesComponentFixture.php @@ -0,0 +1,60 @@ +order = $test->useFixture(OrderFixture::$CLASS); + } + + public function whenIExportTheOrder($string) { + $this->model = $this->component->doGet($this->order->getOrder($string)->id); + } + + public function thenThereShouldBe_Rows($int) { + $this->test->assertCount($int, $this->getField('content')); + } + + public function thenTheDateOfRow_ShouldBe($int, $string) { + $this->test->assertEquals($string, $this->getRowField($int, 'date')); + } + + public function thenTheDishOfRow_ShouldBe($int, $string) { + $this->test->assertEquals($string, $this->getRowField($int, 'dish')); + } + + public function thenTheSumOfRow_ShouldBe($int, $sum) { + $this->test->assertEquals($sum, $this->getRowField($int, 'sum')); + } + + public function thenTheChoosersOfRow_ShouldBe($int, $string) { + $this->test->assertEquals($string, $this->getRowField($int, 'by')); + } + + protected function getComponentClass() { + return DishesComponent::$CLASS; + } + + private function getRowField($int, $field) { + $int--; + return $this->getField("content/$int/$field"); + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/component/export/SelectionsComponentFixture.php b/spec/rtens/lacarte/fixtures/component/export/SelectionsComponentFixture.php new file mode 100644 index 0000000..68d563c --- /dev/null +++ b/spec/rtens/lacarte/fixtures/component/export/SelectionsComponentFixture.php @@ -0,0 +1,78 @@ +order = $test->useFixture(OrderFixture::$CLASS); + } + + public function whenIOpenTheSelectionsOf_WithToken($date, $token) { + $this->model = $this->component->doGet($token, $date); + } + + public function whenIOpenTheSelectionsWithToke($token) { + $this->model = $this->component->doGet($token); + } + + public function thenTheMenuShouldBeEmpty() { + $this->test->assertCount(0, $this->getField('menu')); + } + + public function thenThereShouldBe_Selections($int) { + $this->test->assertCount($int, $this->getField('selections')); + } + + public function thenTheErrorMessageShouldBe($string) { + $this->test->assertEquals($string, $this->getField('error')); + } + + public function thenTheDateShouldBe($string) { + $this->test->assertEquals($string, $this->getField('menu/date')); + } + + public function thenThereShouldBe_Dishes($int) { + $this->test->assertCount($int, $this->getField('menu/dishes')); + } + + public function thenDish_ShouldBe_InEnglish($int, $string) { + $this->test->assertEquals($string, $this->getField("menu/dishes/$int/en")); + } + + public function thenDish_ShouldBe_InGerman($int, $string) { + $this->test->assertEquals($string, $this->getField("menu/dishes/$int/de")); + } + + public function thenSelection_ShouldBeOfUser_ForDish($int, $userName, $dishText) { + $base = "selections/$int"; + $this->test->assertEquals($this->user->getUser($userName)->id, $this->getField("$base/user/id")); + $this->test->assertEquals($userName, $this->getField("$base/user/name")); + $this->test->assertEquals($this->order->getDish($dishText)->id, $this->getField("$base/dish")); + } + + public function thenTheAvatarOfTheUserOfSelection_ShouldBe($int, $string) { + $this->test->assertEquals($string, $this->getField("selections/$int/user/avatar")); + } + + protected function getComponentClass() { + return SelectionsComponent::$CLASS; + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/component/order/EditComponentFixture.php b/spec/rtens/lacarte/fixtures/component/order/EditComponentFixture.php new file mode 100644 index 0000000..1a7633a --- /dev/null +++ b/spec/rtens/lacarte/fixtures/component/order/EditComponentFixture.php @@ -0,0 +1,110 @@ +order = $test->useFixture(OrderFixture::$CLASS); + $this->menuStore = $menuStore; + $this->dishStore = $dishStore; + } + + public function whenIOpenThePageToEdit($orderName) { + $this->model = $this->component->doGet($this->order->getOrder($orderName)->id); + } + + public function whenISaveTheOrder() { + $this->model = $this->component->doPost($this->currentOrder->id, $this->dishTexts); + } + + public function thenThereShouldBeNoErrorMessage() { + $this->thenTheErrorMessageShouldBe(null); + } + + public function thenTheErrorMessageShouldBe($string) { + $this->test->assertEquals($string, $this->getField('error')); + } + + public function thenThereShouldBeNoSuccessMessage() { + $this->thenTheSuccessMessageShouldBe(null); + } + + public function thenTheSuccessMessageShouldBe($string) { + $this->test->assertEquals($string, $this->getField('success')); + } + + public function thenTheNameOfTheOrderShouldBe($string) { + $this->test->assertEquals($string, $this->getField('order/name')); + $this->test->assertEquals($this->order->getOrder($string)->id, $this->getField('order/id/value')); + } + + public function thenThereShouldBe_Menus($int) { + $this->test->assertCount($int, $this->getField('order/menu')); + } + + public function thenTheDateOfMenu_ShouldBe($num, $string) { + $num--; + $this->test->assertEquals($string, $this->getField("order/menu/$num/date")); + } + + public function thenMenu_ShouldHave_Dishes($menuNum, $countDishes) { + $menuNum--; + $this->test->assertCount($countDishes, $this->getField("order/menu/$menuNum/dish")); + } + + public function thenDish_OfMenu_ShouldBe($dishNum, $menuNum, $text) { + $menuNum--; + $dishNum--; + $id = $this->order->getDish($text)->id; + $this->test->assertEquals($text, $this->getField("order/menu/$menuNum/dish/$dishNum/text/_")); + $this->test->assertEquals("dish[$id]", $this->getField("order/menu/$menuNum/dish/$dishNum/text/name")); + } + + public function givenIHaveEntered_ForDish_OfMenu($text, $dishNum, $menuNum) { + $menus = $this->menuStore->readAllByOrderId($this->currentOrder->id); + $dishes = $this->dishStore->readAllByMenuId($menus[$menuNum - 1]->id); + $this->dishTexts[$dishes[$dishNum - 1]->id] = $text; + } + + public function givenIHaveOpenedThePageToEdit($orderName) { + $this->currentOrder = $this->order->getOrder($orderName); + } + + protected function getComponentClass() { + return EditComponent::$CLASS; + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/component/order/ListComponentFixture.php b/spec/rtens/lacarte/fixtures/component/order/ListComponentFixture.php new file mode 100644 index 0000000..7016547 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/component/order/ListComponentFixture.php @@ -0,0 +1,108 @@ +model = $this->component->doGet(); + } + + public function thenThereShouldBe_OrdersListed($int) { + $this->test->assertCount($int, $this->getField('order')); + } + + public function thenTheNameOfOrder_ShouldBe($int, $string) { + $this->then_OfOrder_ShouldBe('name', $int, $string); + } + + public function thenTheDeadlineOfOrder_ShouldBe($int, $string) { + $this->then_OfOrder_ShouldBe('deadline', $int, $string); + } + + public function thenTheSelectLinkOfOrder_ShouldBe($int, $string) { + $this->then_OfOrder_ShouldBe('selectLink/href', $int, $string); + } + + public function thenTheEditLinkOfOrder_ShouldBe($int, $string) { + $this->then_OfOrder_ShouldBe('editLink/href', $int, $string); + } + + public function thenTheItemLinkOfOrder_ShouldBe($int, $string) { + $this->then_OfOrder_ShouldBe('itemLink/href', $int, $string); + } + + public function thenOrder_ShouldBeOpen($int) { + $this->then_OfOrder_ShouldBe('isOpen', $int, true); + } + + public function thenOrder_ShouldNotBeOpen($int) { + $this->then_OfOrder_ShouldBe('isOpen', $int, false); + } + + public function thenTheFirstDayFieldShouldContain($string) { + $this->then_ShouldBe('firstDay/value', $string); + } + + public function thenTheLastDayFieldShouldContain($string) { + $this->then_ShouldBe('lastDay/value', $string); + } + + public function thenTheDeadlineFieldShouldContain($string) { + $this->then_ShouldBe('deadline/value', $string); + } + + public function thenThereShouldBeNoErrorMessage() { + $this->then_ShouldBe('error', null); + } + + public function givenIHaveEnteredTheFirstDay($string) { + $this->firstDay = $string; + } + + public function givenIHaveEnteredTheLastDay($string) { + $this->lastDay = $string; + } + + public function givenIHaveEnteredTheDeadline($string) { + $this->deadline = $string; + } + + public function whenICreateANewOrder() { + $this->model = $this->component->doPost($this->firstDay, $this->lastDay, $this->deadline); + } + + public function thenTheErrorMessageShouldBe($string) { + $this->test->assertEquals($string, $this->getField('error')); + } + + public function thenTheErrorMessageShouldContain($string) { + $this->test->assertContains($string, $this->getField('error')); + } + + protected function getComponentClass() { + return ListComponent::$CLASS; + } + + private function then_OfOrder_ShouldBe($field, $i, $string) { + $i--; + $this->then_ShouldBe("order/$i/$field", $string); + } + + private function then_ShouldBe($field, $value) { + $this->test->assertEquals($value, $this->getField($field)); + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/component/order/SelectComponentFixture.php b/spec/rtens/lacarte/fixtures/component/order/SelectComponentFixture.php new file mode 100644 index 0000000..662ba85 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/component/order/SelectComponentFixture.php @@ -0,0 +1,147 @@ +order = $test->useFixture(OrderFixture::$CLASS); + } + + public function whenIOpenThePageForOrder($string) { + $this->model = $this->component->doGet($this->order->getOrder($string)->id); + } + + public function whenIOpenThePageForOrderForTheUser($orderName, $userName) { + $this->model = $this->component->doGet($this->order->getOrder($orderName)->id, $this->user->getUser($userName)); + } + + public function thenTheDisplayedTimeLeftShouldBe($string) { + $this->test->assertEquals($string, $this->getField('order/timeLeft')); + } + + public function thenTheSelectionOf_ShouldBeLoaded($string) { + $this->test->assertEquals($this->user->getUser($string)->id, $this->getField('userId/value')); + } + + public function thenThereShouldBeNoErrorMessage() { + $this->thenTheErrorMessageShouldBe(null); + } + + public function thenThereShouldBeNoSuccessMessage() { + $this->thenTheSuccessMessageShouldBe(null); + } + + public function thenTheOrder_ShouldBeLoaded($string) { + $this->test->assertEquals($this->order->getOrder($string)->id, $this->getField('order/id/value')); + } + + public function thenThereShouldBe_Menus($int) { + $this->test->assertCount($int, $this->getField('order/menu')); + } + + public function thenTheDateOfMenu_ShouldBe($int, $string) { + $this->then_OfMenu_ShouldBe('date', $int, $string); + } + + public function thenTheNoneOptionOfMenu_ShouldNotBeChecked($int) { + $this->then_OfMenu_ShouldBe('none/key/checked', $int, false); + } + + public function thenTheNoneOptionOfMenu_ShouldBeChecked($int) { + $this->then_OfMenu_ShouldBe('none/key/checked', $int, "checked"); + } + + public function thenMenu_ShouldHave_Dishes($menuNum, $dishCount) { + $this->test->assertCount($dishCount, $this->getMenuField('dish', $menuNum)); + } + + public function thenDish_OfMenu_ShouldBe($dishNum, $menuNum, $text) { + $this->then_OfDish_OfMenu_ShouldBe('text', $dishNum, $menuNum, $text); + } + + public function thenDish_OfMenu_ShouldNotBeChecked($dishNum, $menuNum) { + $this->then_OfDish_OfMenu_ShouldBe('key/checked', $dishNum, $menuNum, false); + } + + public function thenDish_OfMenu_ShouldBeChecked($dishNum, $menuNum) { + $this->then_OfDish_OfMenu_ShouldBe('key/checked', $dishNum, $menuNum, "checked"); + } + + public function givenIHaveOpenedThePageForOrder($orderName) { + $this->whenIOpenThePageForOrder($orderName); + $this->currentOrder = $this->order->getOrder($orderName); + } + + public function givenISelectedDish_OfMenu($dishText, $menuNum) { + foreach ($this->getMenuField('dish', $menuNum) as $dish) { + if ($this->getFieldIn('text', $dish) == $dishText) { + $matches = array(); + preg_match('/selection\[(\d+)\]/', $this->getFieldIn('key/name', $dish), $matches); + $this->selections[$matches[1]] = $this->getFieldIn('key/value', $dish); + } + } + } + + public function givenISelectedNoDishOfMenu($int) { + $dish = $this->getMenuField('none', $int); + $matches = array(); + preg_match('/selection\[(\d+)\]/', $this->getFieldIn('key/name', $dish), $matches); + $this->selections[$matches[1]] = $this->getFieldIn('key/value', $dish); + } + + public function whenISaveMySelections() { + $this->model = $this->component->doPost($this->currentOrder->id, new Map($this->selections)); + } + + protected function getComponentClass() { + return SelectComponent::$CLASS; + } + + public function thenTheErrorMessageShouldBe($value) { + $this->test->assertEquals($value, $this->getField('error')); + } + + public function thenTheSuccessMessageShouldBe($value) { + $this->test->assertEquals($value, $this->getField('success')); + } + + private function then_OfMenu_ShouldBe($field, $menuNum, $value) { + $this->test->assertEquals($value, $this->getMenuField($field, $menuNum)); + } + + private function getMenuField($field, $menuNum) { + $menuNum--; + return $this->getField("order/menu/$menuNum/$field"); + } + + private function then_OfDish_OfMenu_ShouldBe($field, $dishNum, $menuNum, $value) { + $dishNum--; + $this->then_OfMenu_ShouldBe("dish/$dishNum/$field", $menuNum, $value); + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/component/order/SelectionComponentFixture.php b/spec/rtens/lacarte/fixtures/component/order/SelectionComponentFixture.php new file mode 100644 index 0000000..3e62f68 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/component/order/SelectionComponentFixture.php @@ -0,0 +1,72 @@ +order = $test->useFixture(OrderFixture::$CLASS); + } + + public function whenIOpenThePageForOrder($orderName) { + $this->model = $this->component->doGet($this->order->getOrder($orderName)->id); + } + + public function thenTheErrorMessageShouldBe($string) { + $this->test->assertEquals($string, $this->getField('error')); + } + + public function thenThereShouldBeNoErrorMessage() { + $this->thenTheErrorMessageShouldBe(null); + } + + public function thenTheNameOfTheOrderShouldBe($string) { + $this->test->assertEquals($string, $this->getField('order/name')); + } + + public function thenThereShouldBe_Selections($int) { + $this->test->assertCount($int, $this->getField('order/selection')); + } + + public function thenTheDateOfSelection_ShouldBe($int, $string) { + $int--; + $this->test->assertEquals($string, $this->getField("order/selection/$int/date")); + } + + public function thenTheSelectedDishOfSelection_ShouldBe($int, $string) { + $int--; + $this->test->assertEquals($string, $this->getField("order/selection/$int/dish")); + } + + public function thenSelection_ShouldHave_NotSelectedDish($int, $int1) { + $int--; + $this->test->assertCount($int1, $this->getField("order/selection/$int/notSelected")); + } + + public function thenNotSelectedDish_OfSelection_ShouldBe($int, $int1, $string) { + $int--; + $int1--; + $this->test->assertEquals($string, $this->getField("order/selection/$int1/notSelected/$int")); + } + + protected function getComponentClass() { + return SelectionComponent::$CLASS; + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/component/order/SelectionsComponentFixture.php b/spec/rtens/lacarte/fixtures/component/order/SelectionsComponentFixture.php new file mode 100644 index 0000000..eadc167 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/component/order/SelectionsComponentFixture.php @@ -0,0 +1,156 @@ +order = $test->useFixture(OrderFixture::$CLASS); + } + + public function whenIOpenThePageForOrder($name) { + $this->model = $this->component->doGet($this->order->getOrder($name)->id); + } + + public function thenThereShouldBeNoSuccessMessage() { + $this->thenTheSuccessMessageShouldBe(null); + } + + public function thenThereShouldBeNoErrorMessage() { + $this->thenTheErrorMessageShouldBe(null); + } + + public function thenTheEditActionShouldGoTo($string) { + $this->test->assertEquals($string, $this->getField('actions/edit/href')); + } + + public function thenTheExportByDishActionShouldGoTo($string) { + $this->test->assertEquals($string, $this->getField('actions/exportByDish/href')); + } + + public function thenThereShouldBeNoExportByUserAction() { + $this->test->assertNull($this->getField('actions/exportByUser')); + } + + public function thenNameOfTheOrderShouldBe($string) { + $this->test->assertEquals($string, $this->getField('order/name')); + $this->test->assertEquals($this->order->getOrder($string)->id, $this->getField('order/id/value')); + } + + public function thenTheOrderShouldHave_Dates($int) { + $this->test->assertCount($int, $this->getField('order/date')); + } + + public function thenDate_ShouldBe($int, $string) { + $int--; + $this->test->assertEquals($string, $this->getField("order/date/$int")); + } + + public function thenThereShouldBe_Users($int) { + $this->test->assertCount($int, $this->getField('order/user')); + } + + public function thenTheNameOfUser_ShouldBe($int, $string) { + $int--; + $this->test->assertEquals($string, $this->getField("order/user/$int/name")); + } + + public function thenTheSelectionLinkOfUser_ShouldBe($int, $string) { + $int--; + $this->test->assertEquals($string, $this->getField("order/user/$int/selectLink/href")); + } + + public function thenUser_ShouldHave_Selections($int, $int1) { + $int--; + $this->test->assertCount($int1, $this->getField("order/user/$int/selection")); + } + + public function thenUser_ShouldHaveNothingSelectedForSelection($userNum, $selectionNum) { + $userNum--; + $selectionNum--; + $this->test->assertFalse($this->getField("order/user/$userNum/selection/$selectionNum/selected")); + } + + public function thenTheSelectionOfUser_ShouldBe_WithTheTitle($userNum, $text, $title) { + $userNum--; + $this->test->assertEquals($title, $this->getField("order/user/$userNum/selection/0/selected/title")); + $this->test->assertEquals($text, $this->getField("order/user/$userNum/selection/0/selected/_")); + } + + public function givenIHaveEnteredTheSubject($string) { + $this->subject = $string; + } + + public function givenIHaveEnteredTheBody($string) { + $this->body = $string; + } + + public function whenISendTheMail() { + $this->model = $this->component->doSendMail($this->currentOrder->id, $this->subject, + $this->body, $this->onlyWithoutSelection); + } + + public function givenIOpenThePageForOrder($string) { + $this->currentOrder = $this->order->getOrder($string); + } + + public function givenIHaveSelectedToSendTheEmailOnlyToUsersWithoutSelection() { + $this->onlyWithoutSelection = true; + } + + public function thenTheSubjectFieldShouldContain($string) { + $this->test->assertEquals($string, $this->getField('email/subject/value')); + } + + public function thenTheCheckboxToSendOnlyToUsersWithoutSelectionShouldBeChecked() { + $this->test->assertEquals('checked', $this->getField('email/onlyWithout/checked')); + } + + public function thenTheBodyFieldShouldContain($string) { + $this->test->assertEquals($string, $this->getField('email/body')); + } + + public function thenTheCheckboxToSendOnlyToUsersWithoutSelectionShouldNotBeChecked() { + $this->test->assertEquals(false, $this->getField('email/onlyWithout/checked')); + } + + protected function getComponentClass() { + return SelectionsComponent::$CLASS; + } + + public function thenTheSuccessMessageShouldBe($value) { + $this->test->assertEquals($value, $this->getField('success')); + } + + public function thenTheErrorMessageShouldBe($value) { + $this->test->assertEquals($value, $this->getField('error')); + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/component/user/ListComponentFixture.php b/spec/rtens/lacarte/fixtures/component/user/ListComponentFixture.php new file mode 100644 index 0000000..5565e92 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/component/user/ListComponentFixture.php @@ -0,0 +1,128 @@ +files = $test->useFixture(FileFixture::$CLASS); + } + + public function givenIHaveEnteredTheName($string) { + $this->newName = $string; + } + + public function givenIHaveEnteredTheEmail($string) { + $this->newEmail = $string; + } + + public function whenICreateANewUser() { + $this->model = $this->component->doPost($this->newName, $this->newEmail); + } + + public function whenIAccessTheUserList() { + $this->model = $this->component->doGet(); + } + + public function whenIDeleteTheUser($name) { + $this->model = $this->component->doDelete($this->user->getUser($name)->id); + } + + public function thenTheSuccessMessageShouldBe($string) { + $this->test->assertEquals($string, $this->getField('success')); + } + + public function thenTheErrorMessageShouldBe($string) { + $this->test->assertEquals($string, $this->getField('error')); + } + + public function thenTheNewNameFieldShouldContain($string) { + $this->test->assertEquals($string, $this->getField('name/value')); + } + + public function thenTheEmailFieldShouldContain($string) { + $this->test->assertEquals($string, $this->getField('email/value')); + } + + public function thenTheUserListShouldBeEmpty() { + $this->test->assertCount(0, $this->getField('user')); + } + + public function thenThereShouldBe_Users($count) { + $this->test->assertCount($count, $this->getField('user')); + } + + public function thenTheAvatarOfUserAtPosition_ShouldBe($position, $imgSrc) { + $i = $position - 1; + $this->test->assertEquals($imgSrc, $this->getField("user/$i/avatar/src")); + } + + public function givenIAmEditingTheUser($userName) { + $this->model = $this->component->doEdit($this->user->getUser($userName)->id); + $this->newEmail = $this->getField('editing/email/value'); + $this->newName = $this->getField('editing/name/value'); + + $_FILES['picture'] = array( + 'name' => '', + 'tmp_name' => '' + ); + } + + public function whenISaveMyChanges() { + $this->model = $this->component->doSave($this->newName, $this->newEmail, $this->getField('editing/id/value')); + } + + public function thenThereShouldBeNoSuccessMessage() { + $this->thenTheSuccessMessageShouldBe(null); + } + + public function thenThereShouldBeNoErrorMessage() { + $this->thenTheErrorMessageShouldBe(null); + } + + public function givenIHaveSelectedAnAvatarFile($fileName) { + $this->files->givenTheFile($fileName); + + $_FILES['picture']['name'] = $fileName; + $_FILES['picture']['tmp_name'] = $this->files->getFullPath($fileName); + } + + public function thenIShouldStillBeEditingTheUser($userName) { + $this->test->assertNotNull($this->getField('editing')); + $this->test->assertEquals($this->user->getUser($userName)->id, $this->getField('editing/id/value')); + } + + public function thenTheEditingNameFieldShouldContain($string) { + $this->test->assertEquals($string, $this->getField('editing/name/value')); + } + + public function thenTheEditingEmailFieldShouldContain($string) { + $this->test->assertEquals($string, $this->getField('editing/email/value')); + } + + protected function getComponentClass() { + return ListComponent::$CLASS; + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/component/user/LoginComponentFixture.php b/spec/rtens/lacarte/fixtures/component/user/LoginComponentFixture.php new file mode 100644 index 0000000..0a599a0 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/component/user/LoginComponentFixture.php @@ -0,0 +1,63 @@ +email = $email; + } + + public function givenIHaveEnteredTheAdminPassword($password) { + $this->password = $password; + } + + public function whenILogInAsAdmin() { + $this->model = $this->component->doLoginAdmin($this->email, $this->password); + } + + public function thenTheErrorMessageShouldBe($msg) { + $this->test->assertEquals($msg, $this->getField('error')); + } + + public function thenTheAdminEmailFieldShouldContain($string) { + $this->test->assertEquals($string, $this->getField('email')); + } + + public function whenIOpenThePage() { + $this->model = $this->component->doGet(); + } + + public function thenThereShouldBeNoErrorMessage() { + $this->test->assertNull($this->getField('error')); + } + + public function whenILogOut() { + $this->model = $this->component->doLogout(); + } + + public function givenIHaveEnterTheKey($string) { + $this->key = $string; + } + + public function whenILogInAsUser() { + $this->model = $this->component->doPost($this->key); + } + + protected function getComponentClass() { + return LoginComponent::$CLASS; + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/model/OrderFixture.php b/spec/rtens/lacarte/fixtures/model/OrderFixture.php new file mode 100644 index 0000000..c964225 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/model/OrderFixture.php @@ -0,0 +1,180 @@ +user = $test->useFixture(UserFixture::$CLASS); + $this->orderStore = $store; + $this->menuStore = $menuStore; + $this->dishStore = $dishStore; + $this->selectionStore = $selectionStore; + } + + public function givenTheOrder_WithDeadline($name, $deadline) { + $order = new Order($this->user->getGroup()->id, $name, new \DateTime($deadline)); + $this->orderStore->create($order); + $this->orders[$name] = $order; + $this->currentOrder = $order; + } + + public function givenAnOrder_With_MenusEach_Dishes($name, $numMenus, $numDishes) { + $this->givenAnOrder_With_MenusEach_DishesStartingOn($name, $numMenus, $numDishes, 'today'); + } + + public function givenAnOrder_With_MenusEach_DishesStartingOn($name, $numMenus, $numDishes, $firstDay) { + $this->givenAnOrder_With_MenusEach_DishesStartingOnWithDeadline($name, $numMenus, $numDishes, $firstDay, 'now'); + } + + public function givenAnOrder_WithDeadlineAnd_MenusEach_DishesStartingOn($name, $deadline, $numMenus, $numDishes, $firstDay) { + $this->givenAnOrder_With_MenusEach_DishesStartingOnWithDeadline($name, $numMenus, $numDishes, $firstDay, $deadline); + } + + public function givenAnOrder_With_MenusEach_DishesStartingOnWithDeadline($name, $numMenus, $numDishes, $firstDay, $deadline) { + $day = new \DateTime($firstDay); + + $this->givenTheOrder_WithDeadline($name, $deadline); + for ($i = 0; $i < $numMenus; $i++ ) { + $menu = new Menu($this->orders[$name]->id, clone $day); + $day->add(new \DateInterval('P1D')); + $this->menuStore->create($menu); + + for ($j = 0; $j < $numDishes; $j++) { + $dish = new Dish($menu->id, "Dish $i $j"); + $this->dishStore->create($dish); + } + } + } + + public function thenThereShouldBe_Orders($int) { + $this->test->assertCount($int, $this->orderStore->readAll()); + } + + public function thenThereShouldBeAnOrderWithTheName($string) { + foreach ($this->orderStore->readAll() as $order) { + if ($order->getName() == $string) { + $this->currentOrder = $order; + return; + } + } + $this->test->fail("Order with name $string not found"); + } + + public function thenThisOrderShouldHaveTheDeadline($string) { + $this->test->assertEquals(new \DateTime($string), $this->currentOrder->getDeadline()); + } + + public function thenThisOrderShouldHave_Menus($int) { + $this->test->assertCount($int, $this->menuStore->readAllByOrderId($this->currentOrder->id)); + } + + public function thenTheDateOfMenu_OfThisOrderShouldBe($int, $string) { + $this->test->assertEquals(new \DateTime($string), $this->getMenuOfCurrentOrder($int)->getDate()); + } + + /** + * @param $index + * @return Menu + */ + private function getMenuOfCurrentOrder($index) { + $menus = $this->menuStore->readAllByOrderId($this->currentOrder->id); + return $menus[$index - 1]; + } + + public function thenMenu_OfThisOrderShouldHave_Dishes($menuIndex, $numDishes) { + $menu = $this->getMenuOfCurrentOrder($menuIndex); + $this->test->assertCount($numDishes, $this->dishStore->readAllByMenuId($menu->id)); + } + + public function getOrder($orderName) { + return $this->orders[$orderName]; + } + + public function givenDish_OfMenu_OfThisOrderIs($dishNum, $menuNum, $dishText) { + $menu = $this->getMenuOfCurrentOrder($menuNum); + $dishes = $this->dishStore->readAllByMenuId($menu->id); + $dish = $dishes[$dishNum - 1]; + $dish->setText($dishText); + + $this->dishes[$dishText] = $dish; + + $this->dishStore->update($dish); + } + + public function getDish($text) { + return $this->dishes[$text]; + } + + public function thenThereShouldBe_Dishes($int) { + $this->test->assertCount($int, $this->dishStore->readAll()); + } + + public function thenThereShouldBeADish($string) { + foreach ($this->dishStore->readAll() as $dish) { + if ($dish->getText() == $string) { + return; + } + } + $this->test->fail("Dish $string not found"); + } + + public function thereShouldBe_Menus($int) { + $this->test->assertCount($int, $this->menuStore->readAll()); + } + + public function given_SelectedDish_ForMenu_OfOrder($userName, $dishName, $menuNum, $orderName) { + $menus = $this->menuStore->readAllByOrderId($this->orders[$orderName]->id); + $menu = $menus[$menuNum - 1]; + $dish = $this->dishes[$dishName]; + + $selection = new Selection($this->user->getUser($userName)->id, $menu->id, $dish->id); + $this->selectionStore->create($selection); + } + + public function given_SelectedNoDishForMenu_OfOrder($userName, $menuNum, $orderName) { + $menus = $this->menuStore->readAllByOrderId($this->orders[$orderName]->id); + $menu = $menus[$menuNum - 1]; + + $selection = new Selection($this->user->getUser($userName)->id, $menu->id, 0); + $this->selectionStore->create($selection); + } + + public function givenTheOrder($string) { + $this->givenTheOrder_WithDeadline($string, 'tomorrow'); + } +} + diff --git a/spec/rtens/lacarte/fixtures/model/SelectionFixture.php b/spec/rtens/lacarte/fixtures/model/SelectionFixture.php new file mode 100644 index 0000000..6f0e481 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/model/SelectionFixture.php @@ -0,0 +1,69 @@ +store = $store; + $this->menuStore = $menuStore; + $this->order = $test->useFixture(OrderFixture::$CLASS); + $this->user = $test->useFixture(UserFixture::$CLASS); + } + + public function thenThereShouldBe_Selections($int) { + $this->test->assertCount($int, $this->store->readAll()); + } + + public function thenThereShouldBeASelectionWithMenu_OfOrder_AndDish_ForUser($menuNum, $order, $dishText, $userName) { + $menus = $this->menuStore->readAllByOrderId($this->order->getOrder($order)->id); + + $menuId = $menus[$menuNum - 1]->id; + $userId = $this->user->getUser($userName)->id; + $dishId = $this->order->getDish($dishText)->id; + + foreach ($this->store->readAll() as $selection) { + if ($selection->getMenuId() == $menuId + && $selection->getUserId() == $userId + && $selection->getDishId() == $dishId + ) { + return; + } + } + $this->test->fail("Could not find selection"); + } + + public function thenThereShouldBeASelectionWithMenu_OfOrder_AndNoDishForUser($menuNum, $order, $userName) { + $menus = $this->menuStore->readAllByOrderId($this->order->getOrder($order)->id); + $menu = $menus[$menuNum - 1]; + foreach ($this->store->readAll() as $selection) { + if ($selection->getMenuId() == $menu->id + && $selection->getUserId() == $this->user->getUser($userName)->id + && !$selection->getDishId() + ) { + return; + } + } + $this->test->fail("Could not find selection"); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/model/UserFixture.php b/spec/rtens/lacarte/fixtures/model/UserFixture.php new file mode 100644 index 0000000..1354a56 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/model/UserFixture.php @@ -0,0 +1,102 @@ +store = $store; + $this->groupStore = $groupStore; + + $this->group = new Group('Test', '', ''); + $this->groupStore->create($this->group); + } + + public function givenTheGroup_WithTheAdminEmail_AndPassword($name, $email, $password) { + $this->group->setName($name); + $this->group->setAdminEmail($email); + $this->group->setAdminPassword($password); + + $this->groupStore->update($this->group); + } + + public function thenThereShouldBe_Users($count) { + $this->test->assertCount($count, $this->store->readAll()); + } + + public function givenTheUser($name) { + $this->givenTheUser_WithTheEmail($name, strtolower(str_replace(' ', '.', $name)) . '@example.com'); + } + + public function getGroup() { + return $this->group; + } + + public function getUser($name) { + return $this->users[$name]; + } + + public function givenTheUser_WithTheEmail($name, $email) { + $this->givenTheUser_WithTheEmail_AndKey($name, $email, 'key_' . str_replace(' ', '_', $name)); + } + + public function givenTheUser_WithTheEmail_AndKey($name, $email, $key) { + $user = new User($this->group->id, $name, $email, $key); + $this->store->create($user); + + $this->users[$name] = $user; + } + + public function thenThereShouldBeAUserWithTheName_TheEmailAndTheKey($name, $email, $key) { + foreach ($this->store->readAll() as $user) { + if ($user->getName() == $name && $user->getEmail() == $email && $user->getKey() == $key) { + return; + } + } + $this->test->fail('User does not exist'); + } + + public function thenThereShouldBeAUserWithTheName_TheEmail($name, $email) { + foreach ($this->store->readAll() as $user) { + if ($user->getName() == $name && $user->getEmail() == $email) { + return; + } + } + $this->test->fail("User with name [$name] and email [$email] does not exist"); + } + + public function thenThereShouldBeAUserWithTheTheName($name) { + foreach ($this->store->readAll() as $user) { + if ($user->getName() == $name) { + return; + } + } + $this->test->fail('User does not exist'); + } + + public function given_WasDeleted($string) { + $this->store->delete($this->getUser($string)); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/service/ConfigFixture.php b/spec/rtens/lacarte/fixtures/service/ConfigFixture.php new file mode 100644 index 0000000..5007f7c --- /dev/null +++ b/spec/rtens/lacarte/fixtures/service/ConfigFixture.php @@ -0,0 +1,28 @@ +config = $factory->getInstance(Configuration::Configuration); + } + + public function givenTheApiTokenIs($string) { + $this->config->__mock()->method('getApiToken')->willReturn($string); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/service/FileFixture.php b/spec/rtens/lacarte/fixtures/service/FileFixture.php new file mode 100644 index 0000000..6c13c32 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/service/FileFixture.php @@ -0,0 +1,61 @@ +user = $test->useFixture(UserFixture::$CLASS); + $this->config = $config; + + $this->file = $test->mockFactory->createTestUnit(FileRepository::$CLASS, array( + 'config' => $config + )); + $factory->setSingleton(FileRepository::$CLASS, $this->file); + + $this->file->__mock()->method('moveUploadedFile')->willCall(function ($from, $to) { + return rename($from, $to); + }); + } + + public function given_HasAnAvatar($userName) { + $this->givenTheFile($this->getAvatarFile($userName)); + } + + public function then_ShouldHaveAnAvatar($userName) { + $filename = $this->getAvatarFile($userName); + $this->test->assertTrue($this->file->exists($filename), "File [$filename] does not exist."); + } + + private function getAvatarFile($userName) { + return 'avatars/' . $this->user->getUser($userName)->id . '.jpg'; + } + + public function givenTheFile($filename) { + $path = $this->file->getFullPath($filename); + @mkdir(dirname($path), 0777, true); + file_put_contents($path, 'n'); + } + + public function getFullPath($fileName) { + return $this->file->getFullPath($fileName); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/service/KeyGeneratorFixture.php b/spec/rtens/lacarte/fixtures/service/KeyGeneratorFixture.php new file mode 100644 index 0000000..8a4dd6c --- /dev/null +++ b/spec/rtens/lacarte/fixtures/service/KeyGeneratorFixture.php @@ -0,0 +1,26 @@ +keyGenerator = $mf->createMock(KeyGenerator::$CLASS); + $factory->setSingleton(KeyGenerator::$CLASS, $this->keyGenerator); + } + + public function givenTheNextGeneratedKeyIs($key) { + $this->keyGenerator->__mock()->method('generateUnique')->willReturn($key)->once(); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/service/MailFixture.php b/spec/rtens/lacarte/fixtures/service/MailFixture.php new file mode 100644 index 0000000..ad1b3f8 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/service/MailFixture.php @@ -0,0 +1,53 @@ +service = $test->mockFactory->createMock(MailService::$CLASS); + $factory->setSingleton(MailService::$CLASS, $this->service); + $this->user = $test->useFixture(UserFixture::$CLASS); + } + + public function thenAMailShouldBeSentTo_WithTheSubject_AndTheBody($userName, $subject, $body) { + $email = $this->user->getUser($userName)->getEmail(); + $send = $this->service->__mock()->method('send'); + + for ($i = 0; $i < $send->getCalledCount(); $i++) { + if ($send->getCalledArgumentAt($i, 'to') == $email) { + $this->test->assertEquals($subject, $send->getCalledArgumentAt($i, 'subject')); + $this->test->assertEquals($body, $send->getCalledArgumentAt($i, 'body')); + return; + } + } + $this->test->fail("No mail was sent to $userName"); + } + + public function then_EmailsShouldBeSent($int) { + $this->test->assertEquals($int, $this->service->__mock()->method('send')->getCalledCount()); + } + + public function givenAnError_OccursWhileSendingTheMail($string) { + $this->service->__mock()->method('send')->willThrow(new \Exception($string)); + } + + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/service/SessionFixture.php b/spec/rtens/lacarte/fixtures/service/SessionFixture.php new file mode 100644 index 0000000..cce5b78 --- /dev/null +++ b/spec/rtens/lacarte/fixtures/service/SessionFixture.php @@ -0,0 +1,69 @@ +user = $test->useFixture(UserFixture::$CLASS); + + $this->session = $test->mockFactory->createMock(Session::$CLASS); + $factory->setSingleton(Session::$CLASS, $this->session); + } + + public function givenIAmLoggedInAsAdmin() { + $this->session->__mock()->method('get')->willReturn($this->user->getGroup()->id)->withArguments('admin'); + $this->session->__mock()->method('has')->willReturn(true)->withArguments('admin'); + } + + public function givenIAmLoggedAsTheUser($name) { + $this->user->givenTheUser($name); + $user = $this->user->getUser($name); + + $this->session->__mock()->method('get')->willReturn($user->getKey())->withArguments('key'); + $this->session->__mock()->method('has')->willReturn(true)->withArguments('key'); + } + + public function thenIShouldBeLoggedInAsAdmin() { + $this->test->assertTrue($this->session->__mock()->method('set')->wasCalledWith(array('key' => 'admin'))); + } + + public function thenIShouldNotBeLoggedInAsUser() { + $this->test->assertFalse($this->session->__mock()->method('set')->wasCalledWith(array('key' => 'key'))); + } + + public function thenIShouldNotBeLoggedInAsAdmin() { + $this->test->assertFalse($this->session->__mock()->method('set')->wasCalledWith(array('key' => 'admin'))); + } + + public function thenIShouldBeLoggedInAs($userName) { + $this->test->assertTrue($this->session->__mock()->method('set')->wasCalledWith(array( + 'key' => 'key', + 'value' => $this->user->getUser($userName)->getKey() + ))); + } + + public function thenIShouldBeLoggedOut() { + $remove = $this->session->__mock()->method('remove'); + $this->test->assertTrue($remove->wasCalledWith(array('key' => 'admin'))); + $this->test->assertTrue($remove->wasCalledWith(array('key' => 'key'))); + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/fixtures/service/TimeFixture.php b/spec/rtens/lacarte/fixtures/service/TimeFixture.php new file mode 100644 index 0000000..3250a1f --- /dev/null +++ b/spec/rtens/lacarte/fixtures/service/TimeFixture.php @@ -0,0 +1,27 @@ +time = $test->mockFactory->createTestUnit(TimeService::$CLASS); + $factory->setSingleton(TimeService::$CLASS, $this->time); + } + + public function givenNowIs($string) { + $this->time->__mock()->method('now')->willCall(function () use ($string) { + return new \DateTime($string); + }); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/export/ExportOrderTest.php b/spec/rtens/lacarte/specs/export/ExportOrderTest.php new file mode 100644 index 0000000..3936f73 --- /dev/null +++ b/spec/rtens/lacarte/specs/export/ExportOrderTest.php @@ -0,0 +1,92 @@ +order->givenAnOrder_With_MenusEach_Dishes('Test Order', 3, 2); + + $this->component->whenIExportTheOrder('Test Order'); + + $this->component->thenIShouldBeRedirectedTo('../order/list.html'); + } + + function testNoSelections() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 3, 2, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, '1A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, '1B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 2, '2A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 2, '2B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 3, '3A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 3, '3B'); + + $this->component->whenIExportTheOrder('Test Order'); + + $this->component->thenThereShouldBe_Rows(6); + $this->component->thenTheDateOfRow_ShouldBe(1, '2000-01-03'); + $this->component->thenTheDishOfRow_ShouldBe(1, '1A'); + $this->component->thenTheSumOfRow_ShouldBe(1, 0); + } + + function testSelections() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 1, 2, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'B'); + + $this->user->givenTheUser('Bart'); + $this->user->givenTheUser('Lisa'); + $this->user->givenTheUser('Marge'); + $this->user->givenTheUser('Homer'); + + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'A', 1, 'Test Order'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Lisa', 'B', 1, 'Test Order'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Marge', 'A', 1, 'Test Order'); + $this->order->given_SelectedNoDishForMenu_OfOrder('Homer', 1, 'Test Order'); + + $this->component->whenIExportTheOrder('Test Order'); + + $this->component->thenThereShouldBe_Rows(2); + $this->component->thenTheDishOfRow_ShouldBe(1, 'A'); + $this->component->thenTheSumOfRow_ShouldBe(1, 2); + $this->component->thenTheChoosersOfRow_ShouldBe(1, 'Bart, Marge'); + $this->component->thenTheDishOfRow_ShouldBe(2, 'B'); + $this->component->thenTheSumOfRow_ShouldBe(2, 1); + $this->component->thenTheChoosersOfRow_ShouldBe(2, 'Lisa'); + } + + function testSelectionWithDeletedUser() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenAnOrder_With_MenusEach_Dishes('Test Order', 1, 1); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + + $this->user->givenTheUser('Bart'); + $this->user->givenTheUser('Lisa'); + + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'A', 1, 'Test Order'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Lisa', 'A', 1, 'Test Order'); + + $this->user->given_WasDeleted('Bart'); + + $this->component->whenIExportTheOrder('Test Order'); + + $this->component->thenThereShouldBe_Rows(1); + $this->component->thenTheChoosersOfRow_ShouldBe(1, 'Deleted, Lisa'); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/export/SelectionsOfTheDayTest.php b/spec/rtens/lacarte/specs/export/SelectionsOfTheDayTest.php new file mode 100644 index 0000000..3e15373 --- /dev/null +++ b/spec/rtens/lacarte/specs/export/SelectionsOfTheDayTest.php @@ -0,0 +1,124 @@ +config->givenTheApiTokenIs('token'); + } + + function testNoMenu() { + $this->component->whenIOpenTheSelectionsOf_WithToken('2013-01-04', 'token'); + + $this->component->thenTheMenuShouldBeEmpty(); + $this->component->thenThereShouldBe_Selections(0); + $this->component->thenTheErrorMessageShouldBe('No menu found for given date.'); + } + + function testWrongDateFormat() { + $this->component->whenIOpenTheSelectionsOf_WithToken('not a date', 'token'); + $this->component->thenTheErrorMessageShouldBe('Could not parse date.'); + } + + function testWrongToken() { + $this->component->whenIOpenTheSelectionsOf_WithToken('2013-01-04', 'not the token'); + $this->component->thenTheErrorMessageShouldBe('Wrong token.'); + } + + function testNoSelections() { + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 1, 3, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'German Text / English Text'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'Only english Text'); + $this->order->givenDish_OfMenu_OfThisOrderIs(3, 1, 'Something else'); + + $this->component->whenIOpenTheSelectionsOf_WithToken('2000-01-03', 'token'); + + $this->component->thenTheDateShouldBe('2000-01-03'); + $this->component->thenThereShouldBe_Dishes(3); + $this->component->thenDish_ShouldBe_InEnglish(1, 'English Text'); + $this->component->thenDish_ShouldBe_InGerman(1, 'German Text'); + $this->component->thenDish_ShouldBe_InEnglish(2, 'Only english Text'); + $this->component->thenDish_ShouldBe_InGerman(2, 'Only english Text'); + + $this->component->thenThereShouldBe_Selections(0); + } + + function testAllSelections() { + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 1, 3, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(3, 1, 'C'); + + $this->user->givenTheUser('Bart'); + $this->user->givenTheUser('Lisa'); + $this->user->givenTheUser('Maggie'); + + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'A', 1, 'Test Order'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Lisa', 'B', 1, 'Test Order'); + $this->order->given_SelectedNoDishForMenu_OfOrder('Lisa', 1, 'Test Order'); + + $this->component->whenIOpenTheSelectionsOf_WithToken('2000-01-03', 'token'); + $this->component->thenThereShouldBe_Selections(2); + $this->component->thenSelection_ShouldBeOfUser_ForDish(1, 'Bart', 'A'); + $this->component->thenSelection_ShouldBeOfUser_ForDish(2, 'Lisa', 'B'); + } + + function testDefaultDate() { + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 1, 1, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + $this->time->givenNowIs('2000-01-03'); + + $this->component->whenIOpenTheSelectionsWithToke('token'); + + $this->component->thenDish_ShouldBe_InEnglish(1, 'A'); + } + + function testNoSelection() { + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 1, 1, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + + $this->user->givenTheUser('Bart'); + $this->user->givenTheUser('Lisa'); + + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'A', 1, 'Test Order'); + + $this->component->whenIOpenTheSelectionsOf_WithToken('2000-01-03', 'token'); + + $this->component->thenThereShouldBe_Selections(1); + } + + function testAvatars() { + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 1, 1, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + + $this->user->givenTheUser('Bart'); + $this->user->givenTheUser('Lisa'); + + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'A', 1, 'Test Order'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Lisa', 'A', 1, 'Test Order'); + + $this->file->given_HasAnAvatar('Lisa'); + + $this->component->whenIOpenTheSelectionsOf_WithToken('2000-01-03', 'token'); + + $this->component->thenTheAvatarOfTheUserOfSelection_ShouldBe(1, 'http://lacarte/user/avatars/default.png'); + $this->component->thenTheAvatarOfTheUserOfSelection_ShouldBe(2, 'http://lacarte/user/avatars/2.jpg'); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/order/CreateOrderTest.php b/spec/rtens/lacarte/specs/order/CreateOrderTest.php new file mode 100644 index 0000000..af5c6c6 --- /dev/null +++ b/spec/rtens/lacarte/specs/order/CreateOrderTest.php @@ -0,0 +1,114 @@ +session->givenIAmLoggedInAsAdmin(); + $this->time->givenNowIs('2013-04-01'); + + $this->component->whenIOpenThePage(); + + $this->component->thenTheFirstDayFieldShouldContain('2013-04-08'); + $this->component->thenTheLastDayFieldShouldContain('2013-04-12'); + $this->component->thenTheDeadlineFieldShouldContain('2013-04-04 18:00'); + $this->component->thenThereShouldBeNoErrorMessage(); + } + + function testOneWeek() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->component->givenIHaveEnteredTheFirstDay('2013-04-08'); + $this->component->givenIHaveEnteredTheLastDay('2013-04-12'); + $this->component->givenIHaveEnteredTheDeadline('2013-04-04 18:00'); + + $this->component->whenICreateANewOrder(); + + $this->component->thenIShouldBeRedirectedTo('edit.html?order=1'); + + $this->order->thenThereShouldBe_Orders(1); + $this->order->thenThereShouldBeAnOrderWithTheName('08.04.2013 - 12.04.2013'); + $this->order->thenThisOrderShouldHaveTheDeadline('2013-04-04 18:00'); + $this->order->thenThisOrderShouldHave_Menus(5); + $this->order->thenTheDateOfMenu_OfThisOrderShouldBe(1, '2013-04-08'); + $this->order->thenTheDateOfMenu_OfThisOrderShouldBe(5, '2013-04-12'); + $this->order->thenMenu_OfThisOrderShouldHave_Dishes(1, 3); + $this->order->thenMenu_OfThisOrderShouldHave_Dishes(2, 3); + $this->order->thenMenu_OfThisOrderShouldHave_Dishes(5, 3); + } + + function testOverTheWeekend() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->component->givenIHaveEnteredTheFirstDay('2013-04-03'); + $this->component->givenIHaveEnteredTheLastDay('2013-04-13'); + $this->component->givenIHaveEnteredTheDeadline('2013-04-01 18:00'); + + $this->component->whenICreateANewOrder(); + + $this->order->thenThereShouldBe_Orders(1); + $this->order->thenThereShouldBeAnOrderWithTheName('03.04.2013 - 13.04.2013'); + $this->order->thenThisOrderShouldHave_Menus(8); + $this->order->thenTheDateOfMenu_OfThisOrderShouldBe(1, '2013-04-03'); + $this->order->thenTheDateOfMenu_OfThisOrderShouldBe(2, '2013-04-04'); + $this->order->thenTheDateOfMenu_OfThisOrderShouldBe(3, '2013-04-05'); + $this->order->thenTheDateOfMenu_OfThisOrderShouldBe(4, '2013-04-08'); + $this->order->thenTheDateOfMenu_OfThisOrderShouldBe(5, '2013-04-09'); + $this->order->thenTheDateOfMenu_OfThisOrderShouldBe(6, '2013-04-10'); + $this->order->thenTheDateOfMenu_OfThisOrderShouldBe(7, '2013-04-11'); + $this->order->thenTheDateOfMenu_OfThisOrderShouldBe(8, '2013-04-12'); + } + + function testNotAdmin() { + $this->component->givenIHaveEnteredTheFirstDay('2013-04-03'); + $this->component->givenIHaveEnteredTheLastDay('2013-04-13'); + $this->component->givenIHaveEnteredTheDeadline('2013-04-01 18:00'); + + $this->component->whenICreateANewOrder(); + + $this->component->thenTheErrorMessageShouldBe('Access denied.'); + } + + function testWrongFormat() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->component->givenIHaveEnteredTheFirstDay('not a date'); + + $this->component->whenICreateANewOrder(); + + $this->component->thenTheErrorMessageShouldContain('Failed to parse time string'); + } + + function testEndBeforeStart() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->component->givenIHaveEnteredTheFirstDay('2013-04-13'); + $this->component->givenIHaveEnteredTheLastDay('2013-04-03'); + $this->component->givenIHaveEnteredTheDeadline('2013-04-01 18:00'); + + $this->component->whenICreateANewOrder(); + + $this->component->thenTheErrorMessageShouldBe('First day must be before last day'); + } + + function testDeadlineAfterStart() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->component->givenIHaveEnteredTheFirstDay('2013-04-03'); + $this->component->givenIHaveEnteredTheLastDay('2013-04-13'); + $this->component->givenIHaveEnteredTheDeadline('2013-04-04 18:00'); + + $this->component->whenICreateANewOrder(); + + $this->component->thenTheErrorMessageShouldBe('Deadline must be before or on first day'); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/order/EditOrderTest.php b/spec/rtens/lacarte/specs/order/EditOrderTest.php new file mode 100644 index 0000000..01b5a10 --- /dev/null +++ b/spec/rtens/lacarte/specs/order/EditOrderTest.php @@ -0,0 +1,119 @@ +order->givenAnOrder_With_MenusEach_Dishes('Test Order', 2, 2); + + $this->component->whenIOpenThePageToEdit('Test Order'); + + $this->component->thenIShouldBeRedirectedTo('list.html'); + } + + function testNotAdminWhenSaving() { + $this->order->givenAnOrder_With_MenusEach_Dishes('Test Order', 2, 2); + $this->component->givenIHaveOpenedThePageToEdit('Test Order'); + + $this->component->whenISaveTheOrder(); + + $this->component->thenIShouldBeRedirectedTo('list.html'); + } + + function testLoadDishes() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 2, 2, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 2, 'C'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 2, 'D'); + + $this->component->whenIOpenThePageToEdit('Test Order'); + + $this->component->thenThereShouldBeNoErrorMessage(); + $this->component->thenThereShouldBeNoSuccessMessage(); + + $this->component->thenTheNameOfTheOrderShouldBe('Test Order'); + + $this->component->thenThereShouldBe_Menus(2); + $this->component->thenTheDateOfMenu_ShouldBe(1, 'Monday, 3.1.2000'); + $this->component->thenTheDateOfMenu_ShouldBe(2, 'Tuesday, 4.1.2000'); + $this->component->thenMenu_ShouldHave_Dishes(1, 2); + $this->component->thenDish_OfMenu_ShouldBe(1, 1, 'A'); + $this->component->thenDish_OfMenu_ShouldBe(2, 1, 'B'); + $this->component->thenDish_OfMenu_ShouldBe(1, 2, 'C'); + $this->component->thenDish_OfMenu_ShouldBe(2, 2, 'D'); + } + + function testSaveDishes() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 2, 2, '2000-01-03'); + + $this->component->givenIHaveOpenedThePageToEdit('Test Order'); + $this->component->givenIHaveEntered_ForDish_OfMenu('W', 1, 1); + $this->component->givenIHaveEntered_ForDish_OfMenu('X', 2, 1); + $this->component->givenIHaveEntered_ForDish_OfMenu('Y', 1, 2); + $this->component->givenIHaveEntered_ForDish_OfMenu('Z', 2, 2); + + $this->component->whenISaveTheOrder(); + + $this->order->thenThereShouldBe_Orders(1); + $this->order->thenThereShouldBe_Dishes(4); + $this->order->thenThereShouldBeADish('W'); + $this->order->thenThereShouldBeADish('X'); + $this->order->thenThereShouldBeADish('Y'); + $this->order->thenThereShouldBeADish('Z'); + + $this->component->thenTheSuccessMessageShouldBe('Order saved'); + $this->component->thenThereShouldBeNoErrorMessage(); + $this->component->thenTheNameOfTheOrderShouldBe('Test Order'); + } + + function testDiscardEmptyDishes() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 2, 3, '2000-01-03'); + + $this->component->givenIHaveOpenedThePageToEdit('Test Order'); + $this->component->givenIHaveEntered_ForDish_OfMenu('W', 1, 1); + $this->component->givenIHaveEntered_ForDish_OfMenu('X', 2, 1); + $this->component->givenIHaveEntered_ForDish_OfMenu('', 3, 1); + $this->component->givenIHaveEntered_ForDish_OfMenu('Y', 1, 2); + $this->component->givenIHaveEntered_ForDish_OfMenu('', 2, 2); + $this->component->givenIHaveEntered_ForDish_OfMenu('', 3, 2); + + $this->component->whenISaveTheOrder(); + + $this->order->thereShouldBe_Menus(2); + $this->order->thenThereShouldBe_Dishes(3); + } + + function testDiscardEmptyMenu() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 2, 3, '2000-01-03'); + + $this->component->givenIHaveOpenedThePageToEdit('Test Order'); + $this->component->givenIHaveEntered_ForDish_OfMenu('W', 1, 1); + $this->component->givenIHaveEntered_ForDish_OfMenu('X', 2, 1); + $this->component->givenIHaveEntered_ForDish_OfMenu('', 3, 1); + $this->component->givenIHaveEntered_ForDish_OfMenu('', 1, 2); + $this->component->givenIHaveEntered_ForDish_OfMenu('', 2, 2); + $this->component->givenIHaveEntered_ForDish_OfMenu('', 3, 2); + + $this->component->whenISaveTheOrder(); + + $this->order->thenThisOrderShouldHave_Menus(1); + $this->order->thenThereShouldBe_Dishes(2); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/order/ListOrdersTest.php b/spec/rtens/lacarte/specs/order/ListOrdersTest.php new file mode 100644 index 0000000..3ab0f55 --- /dev/null +++ b/spec/rtens/lacarte/specs/order/ListOrdersTest.php @@ -0,0 +1,54 @@ +time->givenNowIs('2013-04-02 19:00'); + $this->order->givenTheOrder_WithDeadline('Test Order 1', '2013-04-04 18:00'); + $this->order->givenTheOrder_WithDeadline('Test Order 2', '2013-04-03 18:00'); + $this->order->givenTheOrder_WithDeadline('Test Order 3', '2013-04-02 18:00'); + $this->order->givenTheOrder_WithDeadline('Test Order 4', '2013-04-01 18:00'); + + $this->component->whenIOpenThePage(); + + $this->component->thenThereShouldBe_OrdersListed(4); + $this->component->thenTheNameOfOrder_ShouldBe(1, 'Test Order 1'); + $this->component->thenTheDeadlineOfOrder_ShouldBe(1, '04.04.2013 18:00'); + $this->component->thenTheSelectLinkOfOrder_ShouldBe(1, 'select.html?order=1'); + $this->component->thenTheEditLinkOfOrder_ShouldBe(1, 'edit.html?order=1'); + $this->component->thenTheItemLinkOfOrder_ShouldBe(1, 'select.html?order=1'); + $this->component->thenOrder_ShouldBeOpen(1); + + $this->component->thenTheNameOfOrder_ShouldBe(2, 'Test Order 2'); + $this->component->thenTheDeadlineOfOrder_ShouldBe(2, '03.04.2013 18:00'); + $this->component->thenOrder_ShouldBeOpen(2); + + $this->component->thenTheNameOfOrder_ShouldBe(3, 'Test Order 3'); + $this->component->thenTheDeadlineOfOrder_ShouldBe(3, '02.04.2013 18:00'); + $this->component->thenOrder_ShouldNotBeOpen(3); + } + + function testShowSelectionsLinkToAdmin() { + $this->time->givenNowIs('2013-04-02 19:00'); + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenTheOrder_WithDeadline('Test Order 1', '2013-04-03 18:00'); + + $this->component->whenIOpenThePage(); + + $this->component->thenTheItemLinkOfOrder_ShouldBe(1, 'selections.html?order=1'); + } +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/order/MakeSelectionTest.php b/spec/rtens/lacarte/specs/order/MakeSelectionTest.php new file mode 100644 index 0000000..2483a51 --- /dev/null +++ b/spec/rtens/lacarte/specs/order/MakeSelectionTest.php @@ -0,0 +1,200 @@ +time->givenNowIs('2000-01-01 18:00:01'); + $this->order->givenTheOrder_WithDeadline('Test Order', '2000-01-01 18:00'); + + $this->component->whenIOpenThePageForOrder('Test Order'); + + $this->component->thenIShouldBeRedirectedTo('selection.html?order=1'); + } + + function _testAdminAfterDeadline() { + $this->time->givenNowIs('2000-01-01 19:12'); + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenTheOrder_WithDeadline('Test Order', '2000-01-01 18:00'); + $this->user->givenTheUser('Bart'); + + $this->component->whenIOpenThePageForOrderForTheUser('Test Order', 'Bart'); + + $this->component->thenTheDisplayedTimeLeftShouldBe('-0d 1h 12m'); + $this->component->thenTheSelectionOf_ShouldBeLoaded('Bart'); + } + + function testNoSelection() { + $this->time->givenNowIs('1999-12-30 15:38'); + $this->session->givenIAmLoggedAsTheUser('Bart'); + $this->order->givenAnOrder_WithDeadlineAnd_MenusEach_DishesStartingOn('Test Order', '2000-01-01 18:00', 2, 2, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 2, 'C'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 2, 'D'); + + $this->component->whenIOpenThePageForOrder('Test Order'); + + $this->component->thenThereShouldBeNoErrorMessage(); + $this->component->thenThereShouldBeNoSuccessMessage(); + $this->component->thenTheOrder_ShouldBeLoaded('Test Order'); + $this->component->thenTheDisplayedTimeLeftShouldBe('2d 2h 22m'); + $this->component->thenThereShouldBe_Menus(2); + $this->component->thenTheDateOfMenu_ShouldBe(1, 'Monday, 3.1.2000'); + + $this->component->thenTheNoneOptionOfMenu_ShouldNotBeChecked(1); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(1, 1); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(2, 1); + $this->component->thenMenu_ShouldHave_Dishes(1, 2); + $this->component->thenDish_OfMenu_ShouldBe(1, 1, 'A'); + $this->component->thenDish_OfMenu_ShouldBe(2, 1, 'B'); + + $this->component->thenTheDateOfMenu_ShouldBe(2, 'Tuesday, 4.1.2000'); + } + + function testCreateSelection() { + $this->session->givenIAmLoggedAsTheUser('Bart'); + $this->order->givenAnOrder_With_MenusEach_Dishes('Test Order', 3, 2); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 2, 'C'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 2, 'D'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 3, 'E'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 3, 'F'); + + $this->component->givenIHaveOpenedThePageForOrder('Test Order'); + $this->component->givenISelectedDish_OfMenu('A', 1); + $this->component->givenISelectedDish_OfMenu('D', 2); + $this->component->givenISelectedNoDishOfMenu(3); + + $this->component->whenISaveMySelections(); + + $this->selection->thenThereShouldBe_Selections(3); + $this->selection->thenThereShouldBeASelectionWithMenu_OfOrder_AndDish_ForUser(1, 'Test Order', 'A', 'Bart'); + $this->selection->thenThereShouldBeASelectionWithMenu_OfOrder_AndDish_ForUser(2, 'Test Order', 'D', 'Bart'); + $this->selection->thenThereShouldBeASelectionWithMenu_OfOrder_AndNoDishForUser(3, 'Test Order', 'Bart'); + + $this->component->thenTheSuccessMessageShouldBe('Selection saved'); + } + + function testLoadSelections() { + $this->session->givenIAmLoggedAsTheUser('Bart'); + $this->time->givenNowIs('2000-01-01 17:59'); + $this->order->givenAnOrder_WithDeadlineAnd_MenusEach_DishesStartingOn('Test Order', '2000-01-01 18:00', 3, 2, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 2, 'C'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 2, 'D'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 3, 'E'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 3, 'F'); + $this->order->given_SelectedNoDishForMenu_OfOrder('Bart', 1, 'Test Order'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'C', 2, 'Test Order'); + + $this->component->whenIOpenThePageForOrder('Test Order'); + + $this->component->thenThereShouldBe_Menus(3); + $this->component->thenMenu_ShouldHave_Dishes(1, 2); + $this->component->thenTheNoneOptionOfMenu_ShouldBeChecked(1); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(1, 1); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(2, 1); + + $this->component->thenMenu_ShouldHave_Dishes(2, 2); + $this->component->thenTheNoneOptionOfMenu_ShouldNotBeChecked(2); + $this->component->thenDish_OfMenu_ShouldBeChecked(1, 2); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(2, 2); + + $this->component->thenMenu_ShouldHave_Dishes(3, 2); + $this->component->thenTheNoneOptionOfMenu_ShouldNotBeChecked(3); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(1, 3); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(2, 3); + } + + function testUpdateSelections() { + $this->session->givenIAmLoggedAsTheUser('Bart'); + $this->time->givenNowIs('2000-01-01 17:59'); + $this->order->givenAnOrder_WithDeadlineAnd_MenusEach_DishesStartingOn('Test Order', '2000-01-01 18:00', 3, 2, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 2, 'C'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 2, 'D'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 3, 'E'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 3, 'F'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'A', 1, 'Test Order'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'C', 2, 'Test Order'); + $this->order->given_SelectedNoDishForMenu_OfOrder('Bart', 3, 'Test Order'); + + $this->component->givenIHaveOpenedThePageForOrder('Test Order'); + $this->component->givenISelectedNoDishOfMenu(1); + $this->component->givenISelectedDish_OfMenu('D', 2); + $this->component->givenISelectedDish_OfMenu('F', 3); + + $this->component->whenISaveMySelections(); + + $this->selection->thenThereShouldBe_Selections(3); + $this->selection->thenThereShouldBeASelectionWithMenu_OfOrder_AndNoDishForUser(1, 'Test Order', 'Bart'); + $this->selection->thenThereShouldBeASelectionWithMenu_OfOrder_AndDish_ForUser(2, 'Test Order', 'D', 'Bart'); + $this->selection->thenThereShouldBeASelectionWithMenu_OfOrder_AndDish_ForUser(3, 'Test Order', 'F', 'Bart'); + } + + function testNotAllSelected() { + $this->session->givenIAmLoggedAsTheUser('Bart'); + $this->time->givenNowIs('2000-01-01 17:59'); + $this->order->givenAnOrder_WithDeadlineAnd_MenusEach_DishesStartingOn('Test Order', '2000-01-01 18:00', 3, 2, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 2, 'C'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 2, 'D'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 3, 'E'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 3, 'F'); + + $this->component->givenIHaveOpenedThePageForOrder('Test Order'); + $this->component->givenISelectedNoDishOfMenu(1); + $this->component->givenISelectedDish_OfMenu('F', 3); + + $this->component->whenISaveMySelections(); + + $this->selection->thenThereShouldBe_Selections(0); + + $this->component->thenTheErrorMessageShouldBe('Please make a selection for every day'); + + $this->component->thenTheNoneOptionOfMenu_ShouldBeChecked(1); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(1, 1); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(2, 1); + $this->component->thenTheNoneOptionOfMenu_ShouldNotBeChecked(2); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(1, 2); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(2, 2); + $this->component->thenTheNoneOptionOfMenu_ShouldNotBeChecked(3); + $this->component->thenDish_OfMenu_ShouldNotBeChecked(1, 3); + $this->component->thenDish_OfMenu_ShouldBeChecked(2, 3); + } + + function _testNothingSelected() { + $this->session->givenIAmLoggedAsTheUser('Bart'); + $this->time->givenNowIs('2000-01-01 17:59'); + $this->order->givenAnOrder_WithDeadlineAnd_MenusEach_DishesStartingOn('Test Order', '2000-01-01 18:00', 3, 2, '2000-01-03'); + + $this->component->givenIHaveOpenedThePageForOrder('Test Order'); + + $this->component->whenISaveMySelections(); + + $this->component->thenTheErrorMessageShouldBe('Please make a selection for every day'); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/order/SendMailTest.php b/spec/rtens/lacarte/specs/order/SendMailTest.php new file mode 100644 index 0000000..f69dfde --- /dev/null +++ b/spec/rtens/lacarte/specs/order/SendMailTest.php @@ -0,0 +1,118 @@ +order->givenTheOrder('Test Order'); + $this->component->givenIOpenThePageForOrder('Test Order'); + $this->component->givenIHaveEnteredTheSubject('Hello'); + $this->component->givenIHaveEnteredTheBody('What up?'); + + $this->component->whenISendTheMail(); + + $this->component->thenIShouldBeRedirectedTo('list.html'); + } + + function testSendMail() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenTheOrder('Test Order'); + $this->component->givenIOpenThePageForOrder('Test Order'); + $this->component->givenIHaveEnteredTheSubject('Hello'); + $this->component->givenIHaveEnteredTheBody('What up?'); + + $this->user->givenTheUser('Homer'); + $this->user->givenTheUser('Marge'); + + $this->component->whenISendTheMail(); + + $this->mail->then_EmailsShouldBeSent(2); + $this->mail->thenAMailShouldBeSentTo_WithTheSubject_AndTheBody('Homer', 'Hello', 'What up?'); + $this->mail->thenAMailShouldBeSentTo_WithTheSubject_AndTheBody('Marge', 'Hello', 'What up?'); + $this->component->thenTheSuccessMessageShouldBe('Email was sent to users'); + $this->component->thenThereShouldBeNoErrorMessage(); + } + + function testOnlySendToUsersWithoutSelection() { + $this->session->givenIAmLoggedInAsAdmin(); + + $this->order->givenAnOrder_With_MenusEach_Dishes('Test Order', 1, 1); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'A'); + + $this->user->givenTheUser('Marge Simpson'); + $this->user->givenTheUser('Homer Simpson'); + $this->user->givenTheUser('Lisa'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Homer Simpson', 'A', 1, 'Test Order'); + + $this->component->givenIOpenThePageForOrder('Test Order'); + $this->component->givenIHaveEnteredTheSubject('Hello {name}'); + $this->component->givenIHaveEnteredTheBody('Order now: {url}'); + $this->component->givenIHaveSelectedToSendTheEmailOnlyToUsersWithoutSelection(); + + $this->component->whenISendTheMail(); + + $this->component->thenTheSuccessMessageShouldBe('Email was sent to users without selections'); + + $this->mail->then_EmailsShouldBeSent(2); + $this->mail->thenAMailShouldBeSentTo_WithTheSubject_AndTheBody('Marge Simpson', 'Hello Marge', + 'Order now: http://lacarte/order/select.html?order=1&key=key_Marge_Simpson'); + $this->mail->thenAMailShouldBeSentTo_WithTheSubject_AndTheBody('Lisa', 'Hello Lisa', + 'Order now: http://lacarte/order/select.html?order=1&key=key_Lisa'); + } + + function testEmptyField() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenTheOrder('Test Order'); + $this->component->givenIOpenThePageForOrder('Test Order'); + $this->component->givenIHaveEnteredTheSubject('Hello'); + $this->component->givenIHaveEnteredTheBody(''); + $this->component->givenIHaveSelectedToSendTheEmailOnlyToUsersWithoutSelection(); + + $this->user->givenTheUser('Homer'); + + $this->component->whenISendTheMail(); + + $this->mail->then_EmailsShouldBeSent(0); + $this->component->thenThereShouldBeNoSuccessMessage(); + $this->component->thenTheErrorMessageShouldBe('Please fill out subject and body to send an email'); + + $this->component->thenTheSubjectFieldShouldContain('Hello'); + $this->component->thenTheCheckboxToSendOnlyToUsersWithoutSelectionShouldBeChecked(); + } + + function testErrorWhileSending() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenTheOrder('Test Order'); + $this->component->givenIOpenThePageForOrder('Test Order'); + $this->component->givenIHaveEnteredTheSubject('Hello'); + $this->component->givenIHaveEnteredTheBody('What up?'); + + $this->user->givenTheUser('Homer'); + $this->user->givenTheUser('Marge'); + + $this->mail->givenAnError_OccursWhileSendingTheMail('Some bad thing'); + + $this->component->whenISendTheMail(); + + $this->component->thenTheErrorMessageShouldBe('Some bad thing'); + $this->component->thenTheSubjectFieldShouldContain('Hello'); + $this->component->thenTheBodyFieldShouldContain('What up?'); + $this->component->thenTheCheckboxToSendOnlyToUsersWithoutSelectionShouldNotBeChecked(); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/order/ShowAllSelectionsTest.php b/spec/rtens/lacarte/specs/order/ShowAllSelectionsTest.php new file mode 100644 index 0000000..771f9a1 --- /dev/null +++ b/spec/rtens/lacarte/specs/order/ShowAllSelectionsTest.php @@ -0,0 +1,90 @@ +order->givenAnOrder_With_MenusEach_Dishes('Test Order', 0, 0); + $this->component->whenIOpenThePageForOrder('Test Order'); + $this->component->thenIShouldBeRedirectedTo('list.html'); + } + + function testNoUsers() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 3, 2, '2000-01-03'); + + $this->component->whenIOpenThePageForOrder('Test Order'); + + $this->component->thenThereShouldBeNoSuccessMessage(); + $this->component->thenThereShouldBeNoErrorMessage(); + + $this->component->thenTheEditActionShouldGoTo('edit.html?order=1'); + $this->component->thenTheExportByDishActionShouldGoTo('../export/dishes.csv?order=1'); + $this->component->thenThereShouldBeNoExportByUserAction(); + + $this->component->thenNameOfTheOrderShouldBe('Test Order'); + + $this->component->thenTheOrderShouldHave_Dates(3); + $this->component->thenDate_ShouldBe(1, 'Mon'); + + $this->component->thenThereShouldBe_Users(0); + } + + function testNoSelections() { + $this->session->givenIAmLoggedInAsAdmin(); + + $this->order->givenAnOrder_With_MenusEach_Dishes('Test Order', 3, 2); + + $this->user->givenTheUser('Bart Simpson'); + $this->user->givenTheUser('Lisa Simpson'); + $this->user->givenTheUser('Maggie Simpson'); + + $this->component->whenIOpenThePageForOrder('Test Order'); + + $this->component->thenThereShouldBe_Users(3); + $this->component->thenTheNameOfUser_ShouldBe(1, 'Bart Simpson'); + $this->component->thenTheSelectionLinkOfUser_ShouldBe(1, 'select.html?order=1&user=1'); + $this->component->thenUser_ShouldHave_Selections(1, 3); + $this->component->thenUser_ShouldHaveNothingSelectedForSelection(1, 1); + $this->component->thenUser_ShouldHaveNothingSelectedForSelection(1, 2); + $this->component->thenUser_ShouldHaveNothingSelectedForSelection(1, 3); + + $this->component->thenTheNameOfUser_ShouldBe(2, 'Lisa Simpson'); + $this->component->thenTheNameOfUser_ShouldBe(3, 'Maggie Simpson'); + } + + function testUsersWithSelections() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenAnOrder_With_MenusEach_Dishes('Test Order', 1, 2); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'Dish One'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'Dish Two'); + + $this->user->givenTheUser('Bart'); + $this->user->givenTheUser('Lisa'); + $this->user->givenTheUser('Maggie'); + + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'Dish One', 1, 'Test Order'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Lisa', 'Dish Two', 1, 'Test Order'); + $this->order->given_SelectedNoDishForMenu_OfOrder('Maggie', 1, 'Test Order'); + + $this->component->whenIOpenThePageForOrder('Test Order'); + + $this->component->thenTheSelectionOfUser_ShouldBe_WithTheTitle(1, 'Dish...', 'Dish One'); + $this->component->thenTheSelectionOfUser_ShouldBe_WithTheTitle(2, 'Dish...', 'Dish Two'); + $this->component->thenTheSelectionOfUser_ShouldBe_WithTheTitle(3, '-', 'nothing'); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/order/ShowSelectionTest.php b/spec/rtens/lacarte/specs/order/ShowSelectionTest.php new file mode 100644 index 0000000..ad37917 --- /dev/null +++ b/spec/rtens/lacarte/specs/order/ShowSelectionTest.php @@ -0,0 +1,69 @@ +session->givenIAmLoggedAsTheUser('Bart'); + $this->order->givenAnOrder_With_MenusEach_Dishes('Test Order', 1, 1); + + $this->component->whenIOpenThePageForOrder('Test Order'); + + $this->component->thenTheErrorMessageShouldBe('You seem to have no selections for this order.'); + } + + function testMixedSelections() { + $this->session->givenIAmLoggedAsTheUser('Bart'); + $this->order->givenAnOrder_With_MenusEach_DishesStartingOn('Test Order', 3, 2, '2000-01-03'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 1, 'Dish One A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 1, 'Dish One B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 2, 'Dish Two A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 2, 'Dish Two B'); + $this->order->givenDish_OfMenu_OfThisOrderIs(1, 3, 'Dish Three A'); + $this->order->givenDish_OfMenu_OfThisOrderIs(2, 3, 'Dish Three B'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'Dish One A', 1, 'Test Order'); + $this->order->given_SelectedDish_ForMenu_OfOrder('Bart', 'Dish Two B', 2, 'Test Order'); + $this->order->given_SelectedNoDishForMenu_OfOrder('Bart', 3, 'Test Order'); + + $this->component->whenIOpenThePageForOrder('Test Order'); + + $this->component->thenThereShouldBeNoErrorMessage(); + $this->component->thenTheNameOfTheOrderShouldBe('Test Order'); + $this->component->thenThereShouldBe_Selections(3); + $this->component->thenTheDateOfSelection_ShouldBe(1, 'Monday, 3.1.2000'); + $this->component->thenTheSelectedDishOfSelection_ShouldBe(1, 'Dish One A'); + $this->component->thenTheDateOfSelection_ShouldBe(2, 'Tuesday, 4.1.2000'); + $this->component->thenTheSelectedDishOfSelection_ShouldBe(2, 'Dish Two B'); + $this->component->thenTheDateOfSelection_ShouldBe(3, 'Wednesday, 5.1.2000'); + $this->component->thenTheSelectedDishOfSelection_ShouldBe(3, 'You selected no dish'); + + $this->component->thenSelection_ShouldHave_NotSelectedDish(1, 1); + $this->component->thenNotSelectedDish_OfSelection_ShouldBe(1, 1, 'Dish One B'); + $this->component->thenSelection_ShouldHave_NotSelectedDish(2, 1); + $this->component->thenNotSelectedDish_OfSelection_ShouldBe(1, 2, 'Dish Two A'); + $this->component->thenSelection_ShouldHave_NotSelectedDish(3, 2); + $this->component->thenNotSelectedDish_OfSelection_ShouldBe(1, 3, 'Dish Three A'); + $this->component->thenNotSelectedDish_OfSelection_ShouldBe(2, 3, 'Dish Three B'); + } + + function testAsAdmin() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->order->givenAnOrder_With_MenusEach_Dishes('Test Order', 1, 1); + + $this->component->whenIOpenThePageForOrder('Test Order'); + + $this->component->thenIShouldBeRedirectedTo('selections.html?order=1'); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/user/CreateUserTest.php b/spec/rtens/lacarte/specs/user/CreateUserTest.php new file mode 100644 index 0000000..2c7d1eb --- /dev/null +++ b/spec/rtens/lacarte/specs/user/CreateUserTest.php @@ -0,0 +1,100 @@ +session->givenIAmLoggedInAsAdmin(); + $this->component->givenIHaveEnteredTheName('Bart Simpson'); + $this->component->givenIHaveEnteredTheEmail('bart@simpson.com'); + $this->key->givenTheNextGeneratedKeyIs('key'); + + $this->component->whenICreateANewUser(); + + $this->component->thenTheSuccessMessageShouldBe('The user Bart Simpson was created.'); + $this->user->thenThereShouldBe_Users(1); + $this->user->thenThereShouldBeAUserWithTheName_TheEmailAndTheKey('Bart Simpson', 'bart@simpson.com', 'key'); + } + + function testNotLoggedIn() { + $this->component->givenIHaveEnteredTheName('Lisa Simpson'); + $this->component->givenIHaveEnteredTheEmail('lisa@simpson.com'); + + $this->component->whenICreateANewUser(); + + $this->component->thenIShouldBeRedirectedTo('login.html'); + } + + function testNotAdmin() { + $this->session->givenIAmLoggedAsTheUser('Homer'); + $this->component->givenIHaveEnteredTheName('Lisa Simpson'); + $this->component->givenIHaveEnteredTheEmail('lisa@simpson.com'); + + $this->component->whenICreateANewUser(); + + $this->component->thenTheErrorMessageShouldBe('Access denied. Must be administrator.'); + $this->component->thenTheNewNameFieldShouldContain('Lisa Simpson'); + $this->component->thenTheEmailFieldShouldContain('lisa@simpson.com'); + } + + function testEmptyName() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->component->givenIHaveEnteredTheEmail('bart@simpson.com'); + + $this->component->whenICreateANewUser(); + + $this->component->thenTheErrorMessageShouldBe('Please provide name and email.'); + $this->component->thenTheEmailFieldShouldContain('bart@simpson.com'); + } + + function testEmptyEmail() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->component->givenIHaveEnteredTheName('Bart Simpson'); + + $this->component->whenICreateANewUser(); + + $this->component->thenTheErrorMessageShouldBe('Please provide name and email.'); + $this->component->thenTheNewNameFieldShouldContain('Bart Simpson'); + } + + function testAlreadyExistingEmail() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->user->givenTheUser_WithTheEmail('El Barto', 'bart@simpson.com'); + $this->component->givenIHaveEnteredTheName('Bart Simpson'); + $this->component->givenIHaveEnteredTheEmail('Bart@Simpson.com'); + + $this->component->whenICreateANewUser(); + + $this->component->thenTheErrorMessageShouldBe('Error while creating user. The email probably already exists.'); + $this->component->thenTheNewNameFieldShouldContain('Bart Simpson'); + $this->component->thenTheEmailFieldShouldContain('Bart@Simpson.com'); + } + + function testAlreadyExistingKey() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->user->givenTheUser_WithTheEmail_AndKey('Bart Simpson', 'bart@simpson.com', 'abc'); + $this->component->givenIHaveEnteredTheName('Lisa Simpson'); + $this->component->givenIHaveEnteredTheEmail('lisa@simpson.com'); + + $this->key->givenTheNextGeneratedKeyIs('def'); + $this->key->givenTheNextGeneratedKeyIs('abc'); + + $this->component->whenICreateANewUser(); + + $this->user->thenThereShouldBe_Users(2); + $this->user->thenThereShouldBeAUserWithTheName_TheEmailAndTheKey('Lisa Simpson', 'lisa@simpson.com', 'def'); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/user/DeleteUserTest.php b/spec/rtens/lacarte/specs/user/DeleteUserTest.php new file mode 100644 index 0000000..69d9c56 --- /dev/null +++ b/spec/rtens/lacarte/specs/user/DeleteUserTest.php @@ -0,0 +1,36 @@ +user->givenTheUser('Bart Simpson'); + $this->user->givenTheUser('Lisa Simpson'); + $this->session->givenIAmLoggedInAsAdmin(); + + $this->component->whenIDeleteTheUser('Bart Simpson'); + + $this->user->thenThereShouldBe_Users(1); + $this->user->thenThereShouldBeAUserWithTheTheName('Lisa Simpson'); + } + + function testNotAdmin() { + $this->user->givenTheUser('Bart Simpson'); + + $this->component->whenIDeleteTheUser('Bart Simpson'); + + $this->component->thenIShouldBeRedirectedTo('../order/list.html'); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/user/ListUsersTest.php b/spec/rtens/lacarte/specs/user/ListUsersTest.php new file mode 100644 index 0000000..104f000 --- /dev/null +++ b/spec/rtens/lacarte/specs/user/ListUsersTest.php @@ -0,0 +1,52 @@ +session->givenIAmLoggedInAsAdmin(); + $this->component->whenIAccessTheUserList(); + $this->component->thenTheUserListShouldBeEmpty(); + } + + function testThreeUsers() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->user->givenTheUser('Bart Simpson'); + $this->user->givenTheUser('Lisa Simpson'); + $this->user->givenTheUser('Homer Simpson'); + + $this->component->whenIAccessTheUserList(); + + $this->component->thenThereShouldBe_Users(3); + } + + function testNotAdmin() { + $this->component->whenIAccessTheUserList(); + $this->component->thenIShouldBeRedirectedTo('../order/list.html'); + } + + function testAvatars() { + $this->session->givenIAmLoggedInAsAdmin(); + $this->user->givenTheUser('Bart Simpson'); + $this->file->given_HasAnAvatar('Bart Simpson'); + + $this->component->whenIAccessTheUserList(); + + $this->component->thenTheAvatarOfUserAtPosition_ShouldBe(1, 'http://lacarte/user/avatars/1.jpg'); + } + + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/user/LoginTest.php b/spec/rtens/lacarte/specs/user/LoginTest.php new file mode 100644 index 0000000..9f4784e --- /dev/null +++ b/spec/rtens/lacarte/specs/user/LoginTest.php @@ -0,0 +1,93 @@ +user->givenTheGroup_WithTheAdminEmail_AndPassword('Group', 'admin@example.com', 'password'); + } + + public function testOpenPage() { + $this->component->whenIOpenThePage(); + $this->component->thenThereShouldBeNoErrorMessage(); + } + + public function testLoginAsAdminSuccessfully() { + $this->component->givenIHaveEnteredTheAdminEmail('admin@example.com'); + $this->component->givenIHaveEnteredTheAdminPassword('password'); + + $this->component->whenILogInAsAdmin(); + + $this->session->thenIShouldBeLoggedInAsAdmin(); + $this->component->thenIShouldBeRedirectedTo('../order/list.html'); + } + + function testWrongAdminEmail() { + $this->component->givenIHaveEnteredTheAdminEmail('wrong@example.com'); + $this->component->givenIHaveEnteredTheAdminPassword('password'); + + $this->component->whenILogInAsAdmin(); + + $this->component->thenTheErrorMessageShouldBe('Could not find group for given email and password'); + $this->component->thenTheAdminEmailFieldShouldContain('wrong@example.com'); + } + + function testWrongAdminPassword() { + $this->component->givenIHaveEnteredTheAdminEmail('admin@example.com'); + $this->component->givenIHaveEnteredTheAdminPassword('wrong'); + + $this->component->whenILogInAsAdmin(); + + $this->component->thenTheErrorMessageShouldBe('Could not find group for given email and password'); + $this->component->thenTheAdminEmailFieldShouldContain('admin@example.com'); + } + + function testAlreadyLoggedIn() { + $this->session->givenIAmLoggedInAsAdmin(); + + $this->component->whenIOpenThePage(); + + $this->component->thenIShouldBeRedirectedTo('../order/list.html'); + } + + function testLogOut() { + $this->session->givenIAmLoggedInAsAdmin(); + + $this->component->whenILogOut(); + + $this->component->thenIShouldBeRedirectedTo('login.html'); + $this->session->thenIShouldBeLoggedOut(); + } + + function testLogInUser() { + $this->user->givenTheUser_WithTheEmail_AndKey('Bart Simpson', 'bart@simpson.com', 'myKey'); + $this->component->givenIHaveEnterTheKey('myKey'); + + $this->component->whenILogInAsUser(); + + $this->session->thenIShouldBeLoggedInAs('Bart Simpson'); + $this->session->thenIShouldNotBeLoggedInAsAdmin(); + } + + function testWrongKey() { + $this->user->givenTheUser_WithTheEmail_AndKey('Bart Simpson', 'bart@simpson.com', 'myKey'); + $this->component->givenIHaveEnterTheKey('notMyKey'); + + $this->component->whenILogInAsUser(); + + $this->component->thenTheErrorMessageShouldBe('You entered an invalid key'); + } + + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/specs/user/UpdateUserTest.php b/spec/rtens/lacarte/specs/user/UpdateUserTest.php new file mode 100644 index 0000000..6840c1c --- /dev/null +++ b/spec/rtens/lacarte/specs/user/UpdateUserTest.php @@ -0,0 +1,110 @@ +user = $this->useFixture(UserFixture::$CLASS); + $this->session = $this->useFixture(SessionFixture::$CLASS); + $this->files = $this->useFixture(FileFixture::$CLASS); + $this->component = $this->useFixture(ListComponentFixture::$CLASS); + } + + protected function background() { + $this->session->givenIAmLoggedInAsAdmin(); + } + + public function testNoChange() { + $this->user->givenTheUser_WithTheEmail('Homer', 'homer@simpson.com'); + $this->component->givenIAmEditingTheUser('Homer'); + + $this->component->whenISaveMyChanges(); + + $this->component->thenThereShouldBeNoErrorMessage(); + $this->component->thenTheSuccessMessageShouldBe('The user has been updated'); + $this->user->thenThereShouldBe_Users(1); + $this->user->thenThereShouldBeAUserWithTheName_TheEmail('Homer', 'homer@simpson.com'); + } + + public function testChangeNameAndEmail() { + $this->user->givenTheUser_WithTheEmail('Homer', 'homer@simpson.com'); + $this->component->givenIAmEditingTheUser('Homer'); + + $this->component->givenIHaveEnteredTheName('Bart'); + $this->component->givenIHaveEnteredTheEmail('EatMyShorts@burns.com'); + + $this->component->whenISaveMyChanges(); + + $this->component->thenThereShouldBeNoErrorMessage(); + $this->component->thenTheSuccessMessageShouldBe('The user has been updated'); + $this->user->thenThereShouldBe_Users(1); + $this->user->thenThereShouldBeAUserWithTheName_TheEmail('Bart', 'eatmyshorts@burns.com'); + } + + public function testMissingData() { + $this->user->givenTheUser_WithTheEmail('Homer', 'homer@simpson.com'); + $this->component->givenIAmEditingTheUser('Homer'); + + $this->component->givenIHaveEnteredTheName(''); + $this->component->givenIHaveEnteredTheEmail('EatMyShorts@burns.com'); + + $this->component->whenISaveMyChanges(); + + $this->component->thenThereShouldBeNoSuccessMessage(); + $this->component->thenTheErrorMessageShouldBe('Could not update user. Missing data.'); + $this->component->thenIShouldStillBeEditingTheUser('Homer'); + $this->component->thenTheEditingNameFieldShouldContain(''); + $this->component->thenTheEditingEmailFieldShouldContain('EatMyShorts@burns.com'); + } + + public function testChangeAvatar() { + $this->user->givenTheUser_WithTheEmail('Homer', 'homer@simpson.com'); + $this->component->givenIAmEditingTheUser('Homer'); + $this->component->givenIHaveSelectedAnAvatarFile('avatar.JPG'); + + $this->component->whenISaveMyChanges(); + + $this->component->thenThereShouldBeNoErrorMessage(); + $this->component->thenTheSuccessMessageShouldBe('The user has been updated'); + $this->user->thenThereShouldBe_Users(1); + $this->files->then_ShouldHaveAnAvatar('Homer'); + } + + public function testWrongPictureFormat() { + $this->user->givenTheUser_WithTheEmail('Homer', 'homer@simpson.com'); + $this->component->givenIAmEditingTheUser('Homer'); + $this->component->givenIHaveSelectedAnAvatarFile('avatar.png'); + + $this->component->givenIHaveEnteredTheEmail('Some@mail.com'); + $this->component->givenIHaveEnteredTheName('Some Name'); + + $this->component->whenISaveMyChanges(); + + $this->component->thenTheErrorMessageShouldBe('Only jpg-files allowed.'); + $this->component->thenIShouldStillBeEditingTheUser('Homer'); + $this->component->thenTheEditingNameFieldShouldContain('Some Name'); + $this->component->thenTheEditingEmailFieldShouldContain('Some@mail.com'); + } + +} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/ComponentTest.php b/spec/rtens/lacarte/web/ComponentTest.php deleted file mode 100644 index e1c3be9..0000000 --- a/spec/rtens/lacarte/web/ComponentTest.php +++ /dev/null @@ -1,205 +0,0 @@ -when->model; - } - - public function getComponent() { - return $this->when->component; - } - - public function getRoute() { - return Path::parse('../test/index.html'); - } -} - -/** - * @property ComponentTest test - */ -class ComponentTest_Given extends Test_Given { - - /** @var Session|Mock */ - public $session; - - /** @var Group */ - public $group; - - /** @var Mock */ - public $time; - - /** @var User|null */ - public $me; - - /** @var Mock */ - public $userInteractor; - - /** @var array|User[] */ - public $users = array(); - - function __construct(Test $test) { - parent::__construct($test); - - $this->group = new Group('test', '', ''); - $this->group->id = 42; - - $this->mockUserInteractor(); - $this->mockSession(); - $this->mockTime(); - } - - public function iAmLoggedInAsAdmin() { - $this->session->set('admin', $this->group->id); - } - - public function iAmLoggedInAsUser() { - $this->session->set('key', 'something'); - $this->me = new User($this->group->id, 'Test User', 'test@user', 'something'); - $this->me->id = 123; - $this->userInteractor->__mock()->method('readByKey')->willReturn($this->me)->withArguments('something'); - } - - public function nowIs($date) { - $this->time->__mock()->method('now')->willCall(function () use ($date) { - return new \DateTime($date); - }); - } - - public function theUser($name) { - $user = new User($this->group->id, $name, $name . '@test.com', $name); - $user->id = count($this->users) + 41; - $this->users[$name] = $user; - $this->userInteractor->__mock()->method('readAllByGroup')->willReturn(new Liste($this->users)); - $this->userInteractor->__mock()->method('readById')->willReturn($user)->withArguments($user->id); - } - - private function mockSession() { - $this->session = $this->test->mf->createMock(Session::$CLASS); - $this->session->__mock()->mockMethods(Mockster::F_NONE); - $sessionVars = new Map(); - $this->session->__mock()->method('set')->willCall(function ($key, $value) use ($sessionVars) { - $sessionVars->set($key, $value); - }); - $this->session->__mock()->method('get')->willCall(function ($key) use ($sessionVars) { - return $sessionVars->get($key); - }); - $this->session->__mock()->method('has')->willCall(function ($key) use ($sessionVars) { - return $sessionVars->has($key); - }); - $this->session->__mock()->method('remove')->willCall(function ($key) use ($sessionVars) { - if ($sessionVars->has($key)) { - $sessionVars->remove($key); - } - }); - } - - private function mockTime() { - $this->time = $this->test->mf->createTestUnit(TimeService::$CLASS); - } - - private function mockUserInteractor() { - $this->userInteractor = $this->test->mf->createMock(UserInteractor::$CLASS); - } - - public function _HasAnAvatar($userName) { - $dir = $this->test->config->getUserFilesDirectory() . '/avatars'; - @mkdir($dir); - - $file = $dir . '/' . $this->users[$userName]->id . '.jpg'; - file_put_contents($file, 'n'); - } - -} - -/** - * @property ComponentTest test - */ -class ComponentTest_When extends Test_When { - - public $model; - - /** - * @var Response - */ - public $response; - - /** @var Component|Mock */ - public $component; - - protected function createDefaultComponent($class, $args = array()) { - $classReflection = new \ReflectionClass($class); - $templateName = lcfirst(FileRouter::stripControllerName($classReflection->getShortName())); - - $this->component = $this->test->mf->createTestUnit($class, array_merge(array( - 'factory' => $this->test->factory, - 'route' => new Path(new Liste(array($templateName . '.html'))), - 'session' => $this->test->given->session, - 'userInteractor' => $this->test->given->userInteractor - ), $args)); - $this->component->__mock()->method('subComponent')->willReturn(null); - } - -} - -/** - * @property ComponentTest test - */ -class ComponentTest_Then extends Test_Then { - - public function iShouldBeRedirectedTo($url) { - $this->test->assertNull($this->test->when->model); - $this->test->assertEquals($url, - $this->test->when->component->getResponse()->getHeaders()->get(Response::HEADER_LOCATION)); - } - - public function _shouldBe($field, $value) { - $this->test->assertEquals($value, $this->getField($field)); - } - - public function _shouldNotBeEmpty($field) { - $this->test->assertNotEmpty($this->getField($field)); - } - - public function _shouldContain($field, $string) { - $this->test->assertContains($string, $this->getField($field)); - } - - protected function getField($field) { - return $this->getFieldIn($field, $this->test->when->model); - } - - public function theModelShouldBe($json) { - $this->test->assertEquals($json, json_encode($this->test->when->model)); - } - - public function _shouldHaveTheSize($field, $int) { - $this->test->assertEquals($int, count($this->getField($field))); - } - -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/export/DishesTest.php b/spec/rtens/lacarte/web/export/DishesTest.php deleted file mode 100644 index 5eaceb4..0000000 --- a/spec/rtens/lacarte/web/export/DishesTest.php +++ /dev/null @@ -1,104 +0,0 @@ -given->anOrder_With_MenusEach_Dishes('Test', 3, 2); - - $this->when->iGetAndDishesExportForTheOrder(); - - $this->then->iShouldBeRedirectedTo('../order/list.html'); - } - - function testNoSelections() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('Test', 3, 2); - $this->given->dish_OfMenu_Is(1, 1, '1A'); - $this->given->dish_OfMenu_Is(2, 1, '1B'); - $this->given->dish_OfMenu_Is(1, 2, '2A'); - $this->given->dish_OfMenu_Is(2, 2, '2B'); - $this->given->dish_OfMenu_Is(1, 3, '3A'); - $this->given->dish_OfMenu_Is(2, 3, '3B'); - - $this->when->iGetAndDishesExportForTheOrder(); - - $this->then->_shouldHaveTheSize('content', 6); - $this->then->_shouldBe('content/0/date', '2000-01-03'); - $this->then->_shouldBe('content/0/dish', '1A'); - $this->then->_shouldBe('content/0/sum', '0'); - } - - function testSelections() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('Test', 1, 2); - $this->given->dish_OfMenu_Is(1, 1, '1A'); - $this->given->dish_OfMenu_Is(2, 1, '1B'); - - $this->given->theUser('Tom'); - $this->given->theUser('Jerry'); - $this->given->theUser('Max'); - $this->given->theUser('Moritz'); - - $this->given->_SelectedDish_ForMenu('Tom', 1, 1); - $this->given->_SelectedDish_ForMenu('Jerry', 2, 1); - $this->given->_SelectedDish_ForMenu('Max', 1, 1); - $this->given->_SelectedDish_ForMenu('Moritz', 0, 1); - - $this->when->iGetAndDishesExportForTheOrder(); - - $this->then->_shouldHaveTheSize('content', 2); - $this->then->_shouldBe('content/0/dish', '1A'); - $this->then->_shouldBe('content/0/sum', 2); - $this->then->_shouldBe('content/0/by', 'Tom, Max'); - $this->then->_shouldBe('content/1/dish', '1B'); - $this->then->_shouldBe('content/1/sum', 1); - $this->then->_shouldBe('content/1/by', 'Jerry'); - } - - function testSelectionWithDeletedUser() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('Test', 1, 1); - - $this->given->theUser('Tom'); - $this->given->theUser('Jerry'); - $this->given->_SelectedDish_ForMenu('Tom', 1, 1); - $this->given->_SelectedDish_ForMenu('Jerry', 1, 1); - - $this->given->_wasDeleted('Tom'); - - $this->when->iGetAndDishesExportForTheOrder(); - - $this->then->_shouldHaveTheSize('content', 1); - $this->then->_shouldBe('content/0/by', 'Deleted, Jerry'); - } - -} - -/** - * @property DishesTest test - * @property DishesComponent component - */ -class DishesTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(DishesComponent::$CLASS, array( - 'orderInteractor' => $this->test->given->orderInteractor - )); - } - - public function iGetAndDishesExportForTheOrder() { - $this->model = $this->component->doGet($this->test->given->order->id); - } - - -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/export/SelectionsTest.php b/spec/rtens/lacarte/web/export/SelectionsTest.php deleted file mode 100644 index 59455c0..0000000 --- a/spec/rtens/lacarte/web/export/SelectionsTest.php +++ /dev/null @@ -1,156 +0,0 @@ -config->__mock()->method('getApiToken')->willReturn('token'); - } - - function testNoMenu() { - $this->when->iRequestTheSelectionsFor_WithTheToken('2013-01-04', 'token'); - - $this->then->_shouldHaveTheSize('menu', 0); - $this->then->_shouldHaveTheSize('selections', 0); - $this->then->_shouldBe('error', 'No menu found for given date.'); - } - - function testWrongDateFormat() { - $this->when->iRequestTheSelectionsFor_WithTheToken('not a date', 'token'); - $this->then->_shouldBe('error', 'Could not parse date.'); - } - - function testWrongToken() { - $this->when->iRequestTheSelectionsFor_WithTheToken('2013-01-04', 'not the token'); - $this->then->_shouldBe('error', 'Wrong token.'); - } - - function testNoSelections() { - $this->given->anOrder_With_MenusEach_Dishes('Test', 1, 3); - $this->given->dish_OfMenu_Is(1, 1, 'German Text / English Text'); - $this->given->dish_OfMenu_Is(2, 1, ' Only english Text'); - $this->given->dish_OfMenu_Is(3, 1, 'Something Else'); - - $this->when->iRequestTheSelectionsFor_WithTheToken('2000-01-03', 'token'); - - $this->then->_shouldBe('menu/date', '2000-01-03'); - $this->then->_shouldHaveTheSize('menu/dishes', 3); - $this->then->_shouldBe('menu/dishes/1/en', 'English Text'); - $this->then->_shouldBe('menu/dishes/1/de', 'German Text'); - $this->then->_shouldBe('menu/dishes/2/en', 'Only english Text'); - $this->then->_shouldBe('menu/dishes/2/de', 'Only english Text'); - - $this->then->_shouldHaveTheSize('selections', 0); - } - - function testAllSelections() { - $this->given->anOrder_With_MenusEach_Dishes('Test', 1, 3); - $this->given->dish_OfMenu_Is(1, 1, 'German Text/English Text'); - $this->given->dish_OfMenu_Is(2, 1, 'Only english Text'); - $this->given->dish_OfMenu_Is(3, 1, 'Something Else'); - - $this->given->theUser('Tick'); - $this->given->theUser('Trick'); - $this->given->theUser('Track'); - - $this->given->_SelectedDish_ForMenu('Tick', 1, 1); - $this->given->_SelectedDish_ForMenu('Trick', 2, 1); - $this->given->_SelectedDish_ForMenu('Track', 0, 1); - - $this->when->iRequestTheSelectionsFor_WithTheToken('2000-01-03', 'token'); - - $this->then->_shouldHaveTheSize('selections', 2); - - $this->then->_shouldBe('selections/141/user/id', 41); - $this->then->_shouldBe('selections/141/user/name', "Tick"); - $this->then->_shouldBe('selections/141/dish', 1); - - $this->then->_shouldBe('selections/142/user/id', 42); - $this->then->_shouldBe('selections/142/user/name', "Trick"); - $this->then->_shouldBe('selections/142/dish', 2); - } - - function testDefaultDate() { - $this->given->anOrder_With_MenusEach_Dishes('Test', 1, 1); - $this->given->dish_OfMenu_Is(1, 1, 'Something'); - $this->given->nowIs('2000-01-03'); - - $this->when->iRequestTheSelectionsForTheDefaultDateWithTheToke('token'); - - $this->then->_shouldBe('menu/dishes/1/en', 'Something'); - } - - function testNoSelection() { - $this->given->anOrder_With_MenusEach_Dishes('Test', 1, 1); - $this->given->dish_OfMenu_Is(1, 1, 'Something'); - - $this->given->theUser('Tick'); - $this->given->theUser('Trick'); - - $this->given->_SelectedDish_ForMenu('Tick', 1, 1); - - $this->when->iRequestTheSelectionsFor_WithTheToken('2000-01-03', 'token'); - - $this->then->_shouldHaveTheSize('selections', 1); - } - - function testAvatars() { - $this->given->anOrder_With_MenusEach_Dishes('Test', 1, 1); - $this->given->dish_OfMenu_Is(1, 1, 'Something'); - - $this->given->theUser('Anna'); - $this->given->theUser('Bert'); - - $this->given->_SelectedDish_ForMenu('Anna', 1, 1); - $this->given->_SelectedDish_ForMenu('Bert', 1, 1); - - $this->given->_HasAnAvatar('Bert'); - - $this->when->iRequestTheSelectionsFor_WithTheToken('2000-01-03', 'token'); - - $this->then->_shouldBe('selections/141/user/avatar', 'http://lacarte/user/avatars/default.png'); - $this->then->_shouldBe('selections/142/user/avatar', 'http://lacarte/user/avatars/42.jpg'); - } - -} - -/** - * @property SelectionsTest test - * @property SelectionsComponent component - */ -class SelectionsTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - - $this->component = $this->test->mf->createTestUnit(SelectionsComponent::$CLASS, array( - 'factory' => $this->test->factory, - 'route' => Path::parse('/export/selections.json'), - 'config' => $this->test->config, - 'time' => $this->test->given->time, - 'orderInteractor' => $this->test->given->orderInteractor, - 'userInteractor' => $this->test->given->userInteractor, - 'files' => new FileRepository($this->test->config) - )); - } - - public function iRequestTheSelectionsFor_WithTheToken($date, $token) { - $this->model = $this->component->doGet($token, $date); - } - - public function iRequestTheSelectionsForTheDefaultDateWithTheToke($token) { - $this->iRequestTheSelectionsFor_WithTheToken(null, $token); - } -} diff --git a/spec/rtens/lacarte/web/order/CreateOrderTest.php b/spec/rtens/lacarte/web/order/CreateOrderTest.php deleted file mode 100644 index 620a3da..0000000 --- a/spec/rtens/lacarte/web/order/CreateOrderTest.php +++ /dev/null @@ -1,147 +0,0 @@ -given->iAmLoggedInAsAdmin(); - $this->given->nowIs('2013-04-01'); - $this->when->iAccessPage(); - - $this->then->_shouldBe('firstDay/value', '2013-04-08'); - $this->then->_shouldBe('lastDay/value', '2013-04-12'); - $this->then->_shouldBe('deadline/value', '2013-04-04 18:00'); - $this->then->_shouldBe('error', null); - } - - function testSuccess() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->iHaveEnteredTheFirstDay('2013-04-02'); - $this->given->iHaveEnteredTheLastDay('2013-04-10'); - $this->given->iHaveEnteredTheDeadline('2013-04-01 16:00'); - $this->given->theIdOfTheCreatedOrderIs(42); - - $this->when->iCreateANewOrder(); - - $this->then->anOrderShouldBeCreatedForGroup_Between_And_WithDeadline(42, '2013-04-02', '2013-04-10', '2013-04-01 16:00'); - $this->then->iShouldBeRedirectedTo('edit.html?order=42'); - } - - function testNotAdmin() { - $this->when->iCreateANewOrder(); - - $this->then->_shouldContain('error', 'denied'); - } - - function testWrongFormat() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->iHaveEnteredTheFirstDay('not a date'); - - $this->when->iCreateANewOrder(); - - $this->then->_shouldContain('error', 'parse time string'); - } - - function testError() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->somethingGoesWrong('Some error'); - - $this->when->iCreateANewOrder(); - - $this->then->_shouldBe('error','Some error'); - } - -} - -/** - * @property CreateOrderTest test - */ -class CreateOrderTest_Given extends ComponentTest_Given { - - public $firstDay; - - public $lastDay; - - public $deadline; - - function __construct(Test $test) { - parent::__construct($test); - $this->userInteractor = $test->mf->createMock(UserInteractor::$CLASS); - $this->orderInteractor = $test->mf->createMock(OrderInteractor::$CLASS); - } - - public function iHaveEnteredTheFirstDay($date) { - $this->firstDay = $date; - } - - public function iHaveEnteredTheLastDay($date) { - $this->lastDay = $date; - } - - public function iHaveEnteredTheDeadline($date) { - $this->deadline = $date; - } - - public function theIdOfTheCreatedOrderIs($id) { - $order = new Order(1, 'bla', new \DateTime()); - $order->id = $id; - $this->orderInteractor->__mock()->method('createOrder')->willReturn($order); - } - - public function somethingGoesWrong($string) { - $this->orderInteractor->__mock()->method('createOrder')->willThrow(new \Exception($string)); - } -} - -/** - * @property CreateOrderTest test - * @property ListComponent component - */ -class CreateOrderTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(ListComponent::$CLASS, array( - 'userInteractor' => $this->test->given->userInteractor, - 'orderInteractor' => $this->test->given->orderInteractor, - 'time' => $this->test->given->time - )); - } - - public function iAccessPage() { - $this->model = $this->component->doGet(); - } - - public function iCreateANewOrder() { - $this->model = $this->component->doPost($this->test->given->firstDay, - $this->test->given->lastDay, $this->test->given->deadline); - } -} - -/** - * @property CreateOrderTest test - */ -class CreateOrderTest_Then extends ComponentTest_Then { - - public function anOrderShouldBeCreatedForGroup_Between_And_WithDeadline($groupId, $first, $last, $deadline) { - $this->test->assertTrue($this->test->given->orderInteractor->__mock()->method('createOrder') - ->wasCalledWith(array($groupId, new \DateTime($first), new \DateTime($last), new \DateTime($deadline)))); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/order/EditOrderTest.php b/spec/rtens/lacarte/web/order/EditOrderTest.php deleted file mode 100644 index 73753e6..0000000 --- a/spec/rtens/lacarte/web/order/EditOrderTest.php +++ /dev/null @@ -1,153 +0,0 @@ -given->anOrder_With_MenusEach_Dishes('test', 2, 2); - - $this->when->iAccessThePage(); - - $this->then->iShouldBeRedirectedTo('list.html'); - } - - function testNotAdminOnSave() { - $this->given->anOrder_With_MenusEach_Dishes('test2', 2, 3); - - $this->when->iSaveTheDishes(); - - $this->then->iShouldBeRedirectedTo('list.html'); - } - - function testLoadDishes() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('test', 2, 2); - $this->given->dish_OfMenu_Is(1, 1, 'A'); - $this->given->dish_OfMenu_Is(2, 1, 'B'); - $this->given->dish_OfMenu_Is(1, 2, 'C'); - $this->given->dish_OfMenu_Is(2, 2, 'D'); - - $this->when->iAccessThePage(); - - $this->then->_shouldBe('error', null); - $this->then->_shouldBe('success', null); - - $this->then->_shouldBe('order/name', 'test'); - $this->then->_shouldBe('order/id/value', 12); - - $this->then->_shouldHaveTheSize('order/menu', 2); - $this->then->_shouldBe('order/menu/0/date', 'Monday, 3.1.2000'); - $this->then->_shouldBe('order/menu/1/date', 'Tuesday, 4.1.2000'); - $this->then->_shouldHaveTheSize('order/menu/0/dish', 2); - $this->then->_shouldBe('order/menu/0/dish/0/text/_', 'A'); - $this->then->_shouldBe('order/menu/0/dish/1/text/_', 'B'); - $this->then->_shouldBe('order/menu/1/dish/0/text/_', 'C'); - $this->then->_shouldBe('order/menu/1/dish/1/text/_', 'D'); - - $this->then->_shouldBe('order/menu/0/dish/0/text/name', 'dish[1]'); - $this->then->_shouldBe('order/menu/0/dish/1/text/name', 'dish[2]'); - $this->then->_shouldBe('order/menu/1/dish/0/text/name', 'dish[3]'); - $this->then->_shouldBe('order/menu/1/dish/1/text/name', 'dish[4]'); - } - - function testSaveDishes() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('test2', 2, 3); - $this->given->iHaveEntered_ForDish_OfMenu('W', 1, 1); - $this->given->iHaveEntered_ForDish_OfMenu('X', 2, 1); - $this->given->iHaveEntered_ForDish_OfMenu('Y', 1, 2); - $this->given->iHaveEntered_ForDish_OfMenu('Z', 3, 2); - - $this->when->iSaveTheDishes(); - - $this->then->_DishesShouldBeSaved(6); - - $this->then->_shouldBe('success', 'Order saved'); - $this->then->_shouldBe('error', null); - $this->then->_shouldBe('order/name', 'test2'); - } - - function testError() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('error', 1, 1); - $this->given->anErrorOccurs('Something went wrong'); - - $this->when->iSaveTheDishes(); - - $this->then->_shouldBe('error', 'Something went wrong'); - } - -} - -class EditOrderTest_Given extends OrderTest_Given { - - public function iHaveEntered_ForDish_OfMenu($text, $dishNum, $menuNum) { - $this->dish_OfMenu_Is($dishNum, $menuNum, $text); - } - - public function anErrorOccurs($string) { - $this->orderInteractor->__mock()->method('updateDishes')->willThrow(new \Exception($string)); - } -} - -/** - * @property EditOrderTest test - * @property EditComponent component - */ -class EditOrderTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(EditComponent::$CLASS, array( - 'orderInteractor' => $this->test->given->orderInteractor - )); - } - - public function iAccessThePage() { - $this->model = $this->component->doGet($this->test->given->order->id); - } - - public function iSaveTheDishes() { - $dishTexts = array(); - foreach ($this->test->given->dishes as $id => $dish) { - $dishTexts[$id] = $dish->getText(); - } - $this->model = $this->component->doPost($this->test->given->order->id, $dishTexts); - } -} - -/** - * @property EditOrderTest test - */ -class EditOrderTest_Then extends ComponentTest_Then { - - public function _DishesShouldBeSaved($count) { - $method = $this->test->given->orderInteractor->__mock()->method('updateDishes'); - $this->test->assertTrue($method->wasCalled(), 'updateDishes was not called'); - - /** @var Collection $dishes */ - $dishes = $method->getCalledArgumentAt(0, 0); - $this->test->assertEquals($count, $dishes->count()); - } -} diff --git a/spec/rtens/lacarte/web/order/ListTest.php b/spec/rtens/lacarte/web/order/ListTest.php deleted file mode 100644 index a2c3808..0000000 --- a/spec/rtens/lacarte/web/order/ListTest.php +++ /dev/null @@ -1,199 +0,0 @@ -when->iAccessThePage(); - $this->then->_shouldHaveTheSize('order', 0); - } - - function testListAll() { - $this->given->nowIs('2013-04-02 19:00'); - $this->given->theOrder_WithDeadline('Test Order 1', '2013-04-04 18:00'); - $this->given->theOrder_WithDeadline('Test Order 2', '2013-04-03 18:00'); - $this->given->theOrder_WithDeadline('Test Order 3', '2013-04-02 18:00'); - $this->given->theOrder_WithDeadline('Test Order 4', '2013-04-01 18:00'); - - $this->when->iAccessThePage(); - - $this->then->_shouldHaveTheSize('order', 4); - $this->then->_shouldBe('order/0/name', 'Test Order 1'); - $this->then->_shouldBe('order/0/deadline', '04.04.2013 18:00'); - $this->then->_shouldBe('order/0/selectLink/href', 'select.html?order=1'); - $this->then->_shouldBe('order/0/editLink/href', 'edit.html?order=1'); - $this->then->_shouldBe('order/0/itemLink/href', 'select.html?order=1'); - $this->then->_shouldBe('order/0/isOpen', true); - - $this->then->_shouldBe('order/1/name', 'Test Order 2'); - $this->then->_shouldBe('order/1/deadline', '03.04.2013 18:00'); - $this->then->_shouldBe('order/1/isOpen', true); - - $this->then->_shouldBe('order/2/name', 'Test Order 3'); - $this->then->_shouldBe('order/2/deadline', '02.04.2013 18:00'); - $this->then->_shouldBe('order/2/isOpen', false); - } - - function testWhenAdmin() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->theOrder_WithDeadline('Test Order 1', '2013-04-03 18:00'); - - $this->when->iAccessThePage(); - - $this->then->_shouldBe('order/0/itemLink/href', 'selections.html?order=1'); - } - - function testShowTodaysSelection() { - - $this->given->iAmLoggedInAsUser(); - $this->given->nowIs('2013-04-04 18:00'); - $this->given->theOrder_WithDeadline('order1', '2013-04-03 18:00'); - $this->given->theMenu_OfTheOrder_ForTheDay('Menu 1', 'order1', '2013-04-04'); - $this->given->theMenu_HasADish('Menu 1', 'Dish 1'); - $this->given->iHaveSelectedDish_ForMenu('Dish 1', 'Menu 1'); - - $this->when->iAccessThePage(); - - $this->then->itShouldDisplayTodaysOrder('Dish 1'); - } - - function testNoTodaysSelectionIfNotUser() { - - $this->given->iAmLoggedInAsAdmin(); - $this->given->nowIs('2013-04-04 18:00'); - $this->given->theOrder_WithDeadline('order1', '2013-04-03 18:00'); - $this->given->theMenu_OfTheOrder_ForTheDay('Menu 1', 'order1', '2013-04-04'); - $this->given->theMenu_HasADish('Menu 1', 'Dish 1'); - - $this->when->iAccessThePage(); - - $this->then->noTodaysOrderShouldBeDisplayed(); - } - - function testNoTodaysSelectionIfNothingSelected() { - $this->markTestIncomplete(); - $this->given->iAmLoggedInAsUser(); - $this->given->nowIs('2013-04-04 18:00'); - $this->given->theOrder_WithDeadline('order1', '2013-04-03 18:00'); - $this->given->theMenu_OfTheOrder_ForTheDay('Menu 1', 'order1', '2013-04-04'); - $this->given->theMenu_HasADish('Menu 1', 'Dish 1'); - - $this->when->iAccessThePage(); - - $this->then->noTodaysOrderShouldBeDisplayed(); - } - - function testTodaysSelectionWhenSelectedNoDish() { - - $this->given->iAmLoggedInAsUser(); - $this->given->nowIs('2013-04-04 18:00'); - $this->given->theOrder_WithDeadline('order1', '2013-04-03 18:00'); - $this->given->theMenu_OfTheOrder_ForTheDay('Menu 1', 'order1', '2013-04-04'); - $this->given->theMenu_HasADish('Menu 1', 'Dish 1'); - $this->given->iHaveSelectedNoDishForMenu('Menu 1'); - - $this->when->iAccessThePage(); - - $this->then->itShouldDisplayTodaysOrder('Nothing for you today'); - } - -} - -class ListTest_given extends ComponentTest_Given { - - function __construct(Test $test) { - parent::__construct($test); - $this->orders = new Liste(); - $this->menus = new Map(); - $this->dishes = new Map(); - - $this->orderInteractor = $test->mf->createMock(OrderInteractor::$CLASS); - $this->orderInteractor->__mock()->method('readAll')->willReturn($this->orders); - $this->orderInteractor->__mock()->method('readAllMenusByDate')->willReturn($this->menus->values()); - $this->orderInteractor->__mock()->method('readSelectionByMenuIdAndUserId')->willThrow(new NotFoundException()); - } - - public function theOrder_WithDeadline($name, $date) { - $order = new Order($this->group->id, $name, new \DateTime($date)); - $order->id = 1; - $this->orders->append($order); - } - - public function theMenu_OfTheOrder_ForTheDay($menuName, $orderName, $date) { - $menu = new Menu($this->orders->first(), new \DateTime($date)); - $this->menus->set($menuName, $menu); - $this->orderInteractor->__mock()->method('readAllMenusByDate')->willReturn($this->menus->values()); - } - - public function theMenu_HasADish($menu, $dishName) { - $dish = new Dish($this->menus[$menu]->id, $dishName); - $this->dishes->set($dishName, $dish); - $dish->id = $this->dishes->count() + 1; - $this->orderInteractor->__mock()->method('readDishById')->willReturn($dish)->withArguments($dish->id); - } - - public function iHaveSelectedDish_ForMenu($dish, $menu) { - $selection = new Selection($this->me->id, $this->menus[$menu]->id, $this->dishes[$dish]->id); - $this->orderInteractor->__mock()->method('readSelectionByMenuIdAndUserId')->willReturn($selection); - } - - public function iHaveSelectedNoDishForMenu($menu) { - $selection = new Selection($this->me->id, $this->menus[$menu]->id, null); - $this->orderInteractor->__mock()->method('readSelectionByMenuIdAndUserId')->willReturn($selection); - } -} - -/** - * @property ListTest test - * @property ListComponent component - */ -class ListTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(ListComponent::$CLASS, array( - 'orderInteractor' => $this->test->given->orderInteractor, - 'time' => $this->test->given->time - )); - } - - public function iAccessThePage() { - $this->model = $this->component->doGet(); - } -} - -/** - * @property ListTest test - */ -class ListTest_Then extends ComponentTest_Then { - - public function itShouldDisplayTodaysOrder($string) { - $this->test->assertEquals($string, $this->getField('today/dish')); - } - - public function noTodaysOrderShouldBeDisplayed() { - $this->test->assertNull($this->getField('today')); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/order/OrderTest.php b/spec/rtens/lacarte/web/order/OrderTest.php deleted file mode 100644 index 1d15d42..0000000 --- a/spec/rtens/lacarte/web/order/OrderTest.php +++ /dev/null @@ -1,154 +0,0 @@ -orderInteractor = $this->test->mf->createMock(OrderInteractor::$CLASS); - $this->dishes = new Map(); - $this->orderInteractor->__mock()->method('readSelectionByMenuIdAndUserId')->willThrow(new NotFoundException()); - - $that = $this; - $this->orderInteractor->__mock()->method('readAllMenusByDate')->willCall(function (\DateTime $date) use ($that) { - return isset($that->menusByDate[$date->format('Ymd')]) ? $that->menusByDate[$date->format('Ymd')] : new Set(); - }); - } - - public function anOrder_With_MenusEach_Dishes($name, $numMenus, $numDishes) { - $this->order = new Order($this->group->id, $name, new \DateTime('2000-01-01')); - $this->order->id = 12; - - $menus = array( - $this->order->id => new Set() - ); - $dishes = array(); - $this->dishesOfMenus = array(); - - for ($m = 0; $m < $numMenus; $m++) { - $date = new \DateTime('2000-01-' . ($m + 3)); - $menu = new Menu($this->order->id, $date); - $this->menusByDate[$date->format('Ymd')] = new Set(array($menu)); - - $menu->id = $m + 1; - $this->menus[$menu->id] = $menu; - $menus[$this->order->id][] = $menu; - $dishes[$menu->id] = new Set(); - - for ($d = 0; $d < $numDishes; $d++) { - $dish = new Dish($menu->id, ''); - $dish->id = $this->dishes->count() + 1; - $this->dishes->set($dish->id, $dish); - $dishes[$menu->id][] = $dish; - - $this->dishesOfMenus[$menu->id][] = $dish; - } - } - - $this->orderInteractor->__mock()->method('readById')->willReturn($this->order); - $this->orderInteractor->__mock()->method('readMenusByOrderId')->willCall(function ($id) use ($menus) { - return $menus[$id]; - }); - $this->orderInteractor->__mock()->method('readDishesByMenuId')->willCall(function ($id) use ($dishes) { - return $dishes[$id]; - }); - $that = $this; - $this->orderInteractor->__mock()->method('readDishById')->willCall(function ($id) use ($that) { - return $that->dishes[$id]; - }); - $this->orderInteractor->__mock()->method('readMenuById')->willCall(function ($id) use ($that) { - return $that->menus[$id]; - }); - } - - public function dish_OfMenu_Is($dishNum, $menuNum, $text) { - /** @var Dish $dish */ - $dish = $this->dishesOfMenus[$menuNum][$dishNum - 1]; - $dish->setText($text); - } - - public function theDeadlineOfTheOrderIs($date) { - $this->order->setDeadline(new \DateTime($date)); - } - - public function theMenu_HasASelectionForNoDish($menuId) { - $this->theMenu_HasASelectionForDish($menuId, 0); - } - - public function theMenu_HasASelectionForDish($menuId, $dishId) { - $this->selections[$menuId] = new Selection($this->me->id, $menuId, $dishId); - $this->selections[$menuId]->id = count($this->selections); - $this->orderInteractor->__mock()->method('readSelectionByMenuIdAndUserId') - ->willReturn($this->selections[$menuId])->withArguments($menuId, $this->me->id); - } - - public function anErrorOccurs($string) { - $this->orderInteractor->__mock()->method('readById')->willThrow(new \Exception($string)); - } - - public function _wasDeleted($name) { - $this->userInteractor->__mock()->method('readById')->willThrow(new NotFoundException()) - ->withArguments($this->users[$name]->id); - } - - public function _SelectedDish_ForMenu($user, $dishId, $menuId) { - $selection = new Selection($this->users[$user]->id, $menuId, $dishId); - $selection->id = $this->users[$user]->id + 100; - $this->selectionsByDishId[$dishId][] = $selection; - - $this->orderInteractor->__mock()->method('readSelectionByMenuIdAndUserId') - ->willReturn($selection) - ->withArguments($menuId, $this->users[$user]->id); - $this->orderInteractor->__mock()->method('readAllSelectionsByDishId') - ->willReturn(new Set($this->selectionsByDishId[$dishId])) - ->withArguments($dishId); - } - -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/order/SelectTest.php b/spec/rtens/lacarte/web/order/SelectTest.php deleted file mode 100644 index 67d584c..0000000 --- a/spec/rtens/lacarte/web/order/SelectTest.php +++ /dev/null @@ -1,295 +0,0 @@ -given->anOrder_With_MenusEach_Dishes('too late', 2, 2); - $this->given->theDeadlineOfTheOrderIs('2000-01-01 00:00'); - $this->given->nowIs('2000-01-01 00:01'); - - $this->when->iAccessThePageForTheOrder(); - - $this->then->iShouldBeRedirectedTo('selection.html?order=12'); - } - - function testAdminAfterDeadline() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('too late admin', 2, 2); - $this->given->theDeadlineOfTheOrderIs('2000-01-01 00:00'); - $this->given->nowIs('2000-01-01 01:01'); - - $this->when->iAccessThePageForTheOrderForTheUser(123); - - $this->then->_shouldBe('order/timeLeft', '-0d 1h 1m'); - $this->then->_shouldBe('userId/value', 123); - } - - function testNoSelection() { - $this->given->iAmLoggedInAsUser(); - $this->given->anOrder_With_MenusEach_Dishes('test', 2, 2); - $this->given->theDeadlineOfTheOrderIs('2000-01-01 00:00'); - $this->given->nowIs('1999-12-29 21:38'); - $this->given->dish_OfMenu_Is(1, 1, 'A'); - $this->given->dish_OfMenu_Is(2, 1, 'B'); - $this->given->dish_OfMenu_Is(1, 2, 'C'); - $this->given->dish_OfMenu_Is(2, 2, 'D'); - - $this->when->iAccessThePageForTheOrder(); - - $this->then->_shouldBe('error', null); - $this->then->_shouldBe('success', null); - $this->then->_shouldBe('order/id/value', 12); - $this->then->_shouldBe('order/timeLeft', '2d 2h 22m'); - $this->then->_shouldHaveTheSize('order/menu', 2); - $this->then->_shouldBe('order/menu/0/date', 'Monday, 3.1.2000'); - $this->then->_shouldBe('order/menu/0/none/key/name', 'selection[1]'); - $this->then->_shouldBe('order/menu/0/none/key/checked', false); - $this->then->_shouldHaveTheSize('order/menu/0/dish', 2); - $this->then->_shouldBe('order/menu/0/dish/0/key/name', 'selection[1]'); - $this->then->_shouldBe('order/menu/0/dish/0/key/value', '1'); - $this->then->_shouldBe('order/menu/0/dish/0/text', 'A'); - - $this->then->_shouldBe('order/menu/1/date', 'Tuesday, 4.1.2000'); - $this->then->_shouldBe('order/menu/1/none/key/name', 'selection[2]'); - } - - function testCreateSelection() { - $this->given->iAmLoggedInAsUser(); - $this->given->anOrder_With_MenusEach_Dishes('test', 3, 2); - - $this->given->iHaveSelectedDish_OfMenu(1, 1); - $this->given->iHaveSelectedDish_OfMenu(4, 2); - $this->given->iHaveSelectedDish_OfMenu(0, 3); - - $this->when->iSaveTheSelection(); - - $this->then->_SelectionsShouldBeSaved(3); - $this->then->theUserOfSelection_ShouldBeMe(1); - $this->then->theMenuOfSelection_ShouldBe(1, 1); - $this->then->theDishOfSelection_ShouldBe(1, 1); - $this->then->theDishOfSelection_ShouldBe(2, 4); - $this->then->theSelection_ShouldHaveNoDish(3); - - $this->then->_shouldBe('success', 'Selection saved'); - } - - function testLoadSelections() { - $this->given->iAmLoggedInAsUser(); - $this->given->anOrder_With_MenusEach_Dishes('test', 3, 2); - $this->given->theDeadlineOfTheOrderIs('2000-01-01 00:00'); - $this->given->nowIs('1999-12-29 21:38'); - $this->given->theMenu_HasASelectionForNoDish(1); - $this->given->theMenu_HasASelectionForDish(2, 3); - - $this->when->iAccessThePageForTheOrder(); - - $this->then->_shouldHaveTheSize('order/menu', 3); - $this->then->_shouldHaveTheSize('order/menu/0/dish', 2); - $this->then->_shouldBe('order/menu/0/none/key/name', 'selection[1]'); - $this->then->_shouldBe('order/menu/0/none/key/checked', "checked"); - $this->then->_shouldBe('order/menu/0/dish/0/key/checked', false); - $this->then->_shouldBe('order/menu/0/dish/1/key/checked', false); - - $this->then->_shouldHaveTheSize('order/menu/1/dish', 2); - $this->then->_shouldBe('order/menu/1/none/key/name', 'selection[2]'); - $this->then->_shouldBe('order/menu/1/none/key/checked', false); - $this->then->_shouldBe('order/menu/1/dish/0/key/checked', "checked"); - $this->then->_shouldBe('order/menu/1/dish/1/key/checked', false); - - $this->then->_shouldHaveTheSize('order/menu/2/dish', 2); - $this->then->_shouldBe('order/menu/2/none/key/name', 'selection[3]'); - $this->then->_shouldBe('order/menu/2/none/key/checked', false); - $this->then->_shouldBe('order/menu/2/dish/0/key/checked', false); - $this->then->_shouldBe('order/menu/2/dish/1/key/checked', false); - } - - function testUpdateSelections() { - $this->given->iAmLoggedInAsUser(); - $this->given->anOrder_With_MenusEach_Dishes('test', 3, 2); - $this->given->theDeadlineOfTheOrderIs('2000-01-01 00:00'); - $this->given->nowIs('1999-12-29 21:38'); - $this->given->theMenu_HasASelectionForDish(1, 2); - $this->given->theMenu_HasASelectionForDish(2, 3); - $this->given->theMenu_HasASelectionForNoDish(3); - - $this->given->iHaveSelectedDish_OfMenu(0, 1); - $this->given->iHaveSelectedDish_OfMenu(3, 2); - $this->given->iHaveSelectedDish_OfMenu(5, 3); - - $this->when->iSaveTheSelection(); - - $this->then->_SelectionsShouldBeSaved(3); - $this->then->theUserOfSelection_ShouldBeMe(1); - $this->then->theIdOfSelection_ShouldBe(1, 1); - $this->then->theIdOfSelection_ShouldBe(2, 2); - $this->then->theIdOfSelection_ShouldBe(3, 3); - } - - function testNotAllSelected() { - $this->given->iAmLoggedInAsUser(); - $this->given->anOrder_With_MenusEach_Dishes('test', 3, 2); - - $this->given->iHaveSelectedDish_OfMenu(1, 1); - $this->given->iHaveSelectedDish_OfMenu(0, 3); - - $this->when->iSaveTheSelection(); - - $this->then->NoSelectionsShouldBeSaved(); - - $this->then->_shouldBe('error', 'Please make a selection for every day'); - - $this->then->_shouldHaveTheSize('order/menu', 3); - $this->then->_shouldHaveTheSize('order/menu/0/dish', 2); - $this->then->_shouldBe('order/menu/0/none/key/name', 'selection[1]'); - $this->then->_shouldBe('order/menu/0/none/key/checked', false); - $this->then->_shouldBe('order/menu/0/dish/0/key/checked', "checked"); - $this->then->_shouldBe('order/menu/0/dish/1/key/checked', false); - - $this->then->_shouldHaveTheSize('order/menu/1/dish', 2); - $this->then->_shouldBe('order/menu/1/none/key/name', 'selection[2]'); - $this->then->_shouldBe('order/menu/1/none/key/checked', false); - $this->then->_shouldBe('order/menu/1/dish/0/key/checked', false); - $this->then->_shouldBe('order/menu/1/dish/1/key/checked', false); - - $this->then->_shouldHaveTheSize('order/menu/2/dish', 2); - $this->then->_shouldBe('order/menu/2/none/key/name', 'selection[3]'); - $this->then->_shouldBe('order/menu/2/none/key/checked', "checked"); - $this->then->_shouldBe('order/menu/2/dish/0/key/checked', false); - $this->then->_shouldBe('order/menu/2/dish/1/key/checked', false); - } - - function testNothingSelected() { - $this->given->iAmLoggedInAsUser(); - $this->given->anOrder_With_MenusEach_Dishes('test', 3, 2); - - $this->when->iSaveTheSelectionWithoutAnySelection(); - - $this->then->_shouldBe('error', 'Please make a selection for every day'); - - } - -} - -/** - * @property SelectTest test - */ -class SelectTest_Given extends OrderTest_Given { - - /** @var Map */ - public $selected; - - function __construct(Test $test) { - parent::__construct($test); - $this->selected = new Map(); - } - - public function iHaveSelectedDish_OfMenu($dishId, $menuId) { - $this->selected[(string)$menuId] = (string) $dishId; - } -} - -/** - * @property SelectTest test - * @property SelectComponent component - */ -class SelectTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(SelectComponent::$CLASS, array( - 'orderInteractor' => $this->test->given->orderInteractor, - 'time' => $this->test->given->time - )); - } - - public function iAccessThePageForTheOrder() { - $this->model = $this->component->doGet($this->test->given->order->id); - } - - public function iSaveTheSelection() { - $this->model = $this->component->doPost($this->test->given->order->id, $this->test->given->selected); - } - - public function iSaveTheSelectionWithoutAnySelection() { - $this->model = $this->component->doPost($this->test->given->order->id); - } - - public function iAccessThePageForTheOrderForTheUser($userId) { - $this->model = $this->component->doGet($this->test->given->order->id, $userId); - } -} - -/** - * @property SelectTest test - */ -class SelectTest_Then extends ComponentTest_Then { - - function __construct(Test $test) { - parent::__construct($test); - } - - public function thereShouldBe_Selections($count) { - $this->test->markTestIncomplete(); - } - - public function theUserOfSelection_ShouldBeMe($index) { - $selections = $this->getSelections(); - $this->test->assertEquals($this->test->given->me->id, $selections[$index - 1]->getUserId()); - } - - public function theMenuOfSelection_ShouldBe($index, $menuId) { - $selections = $this->getSelections(); - $this->test->assertEquals($menuId, $selections[$index - 1]->getMenuId()); - } - - public function theDishOfSelection_ShouldBe($index, $dishId) { - $selections = $this->getSelections(); - $this->test->assertEquals($dishId, $selections[$index - 1]->getDishId()); - } - - public function theSelection_ShouldHaveNoDish($index) { - $selections = $this->getSelections(); - $this->test->assertFalse($selections[$index - 1]->hasDish()); - } - - public function _SelectionsShouldBeSaved($count) { - $this->test->assertTrue($this->getMethod()->wasCalled()); - $this->test->assertEquals($count, count($this->getMethod()->getCalledArgumentAt(0, 0))); - } - - private function getMethod() { - return $this->test->given->orderInteractor->__mock()->method('saveSelections'); - } - - /** - * @return Selection[] - */ - private function getSelections() { - return $this->getMethod()->getCalledArgumentAt(0, 0); - } - - public function theIdOfSelection_ShouldBe($index, $id) { - $selections = $this->getSelections(); - $this->test->assertEquals($id, $selections[$index - 1]->id); - } - - public function NoSelectionsShouldBeSaved() { - $this->test->assertFalse($this->getMethod()->wasCalled()); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/order/SelectionTest.php b/spec/rtens/lacarte/web/order/SelectionTest.php deleted file mode 100644 index 52975c4..0000000 --- a/spec/rtens/lacarte/web/order/SelectionTest.php +++ /dev/null @@ -1,85 +0,0 @@ -given->iAmLoggedInAsUser(); - $this->given->anOrder_With_MenusEach_Dishes('Test Order', 3, 2); - $this->given->dish_OfMenu_Is(1, 1, 'Dish One A'); - $this->given->dish_OfMenu_Is(2, 1, 'Dish One B'); - $this->given->dish_OfMenu_Is(1, 2, 'Dish Two A'); - $this->given->dish_OfMenu_Is(2, 2, 'Dish Two B'); - $this->given->dish_OfMenu_Is(1, 3, 'Dish Three A'); - $this->given->dish_OfMenu_Is(2, 3, 'Dish Three B'); - $this->given->theMenu_HasASelectionForDish(1, 1); - $this->given->theMenu_HasASelectionForDish(2, 4); - $this->given->theMenu_HasASelectionForDish(3, 0); - - $this->when->iAccessThePage(); - - $this->then->_shouldBe('error', null); - $this->then->_shouldBe('order/name', 'Test Order'); - $this->then->_shouldHaveTheSize('order/selection', 3); - $this->then->_shouldBe('order/selection/0/date', 'Monday, 3.1.2000'); - $this->then->_shouldBe('order/selection/0/dish', 'Dish One A'); - $this->then->_shouldBe('order/selection/1/date', 'Tuesday, 4.1.2000'); - $this->then->_shouldBe('order/selection/1/dish', 'Dish Two B'); - $this->then->_shouldBe('order/selection/2/date', 'Wednesday, 5.1.2000'); - $this->then->_shouldBe('order/selection/2/dish', 'You selected no dish'); - - $this->then->_shouldHaveTheSize('order/selection/0/notSelected', 1); - $this->then->_shouldBe('order/selection/0/notSelected/0', 'Dish One B'); - $this->then->_shouldHaveTheSize('order/selection/1/notSelected', 1); - $this->then->_shouldBe('order/selection/1/notSelected/0', 'Dish Two A'); - $this->then->_shouldHaveTheSize('order/selection/2/notSelected', 2); - $this->then->_shouldBe('order/selection/2/notSelected/0', 'Dish Three A'); - $this->then->_shouldBe('order/selection/2/notSelected/1', 'Dish Three B'); - } - - function testAsAdmin() { - $this->given->anOrder_With_MenusEach_Dishes('Test Order', 3, 2); - $this->given->iAmLoggedInAsAdmin(); - - $this->when->iAccessThePage(); - - $this->then->iShouldBeRedirectedTo('selections.html?order=12'); - } - - function testError() { - $this->given->anOrder_With_MenusEach_Dishes('Test Order', 3, 2); - $this->given->iAmLoggedInAsUser(); - $this->given->anErrorOccurs('Something terrible happened'); - - $this->when->iAccessThePage(); - - $this->then->_shouldBe('error', 'Something terrible happened'); - $this->then->_shouldBe('order', null); - } - -} - -/** - * @property SelectionTest test - * @property SelectionComponent component - */ -class SelectionTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(SelectionComponent::$CLASS, array( - 'orderInteractor' => $this->test->given->orderInteractor - )); - } - - public function iAccessThePage() { - $this->model = $this->component->doGet($this->test->given->order->id); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/order/SelectionsTest.php b/spec/rtens/lacarte/web/order/SelectionsTest.php deleted file mode 100644 index ee22758..0000000 --- a/spec/rtens/lacarte/web/order/SelectionsTest.php +++ /dev/null @@ -1,106 +0,0 @@ -given->anOrder_With_MenusEach_Dishes('My Order', 0, 0); - $this->when->iAccessThePage(); - $this->then->iShouldBeRedirectedTo('list.html'); - } - - function testNoUsers() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('Test Order', 3, 2); - - $this->when->iAccessThePage(); - - $this->then->_shouldBe('success', null); - $this->then->_shouldBe('error', null); - - $this->then->_shouldHaveTheSize('actions', 3); - $this->then->_shouldBe('actions/edit/href', 'edit.html?order=12'); - $this->then->_shouldBe('actions/exportByDish/href', '../export/dishes.csv?order=12'); - $this->then->_shouldBe('actions/exportByUser', null); - - $this->then->_shouldBe('order/name', 'Test Order'); - $this->then->_shouldBe('order/id/value', 12); - - $this->then->_shouldHaveTheSize('order/date', 3); - $this->then->_shouldBe('order/date/0', 'Mon'); - - $this->then->_shouldHaveTheSize('order/user', 0); - } - - function testNoSelections() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('Test Order', 3, 2); - - $this->given->theUser('Clark Kent'); - $this->given->theUser('Donald Duck'); - $this->given->theUser('Peter Parker'); - - $this->when->iAccessThePage(); - - $this->then->_shouldHaveTheSize('order/user', 3); - $this->then->_shouldBe('order/user/0/name', 'Clark Kent'); - $this->then->_shouldBe('order/user/0/selectLink/href', 'select.html?order=12&user=41'); - $this->then->_shouldHaveTheSize('order/user/0/selection', 3); - $this->then->_shouldBe('order/user/0/selection/0/selected', false); - $this->then->_shouldBe('order/user/0/selection/1/selected', false); - $this->then->_shouldBe('order/user/0/selection/2/selected', false); - } - - function testUsersWithSelections() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('Test Order', 1, 2); - $this->given->dish_OfMenu_Is(1, 1, 'Dish One'); - $this->given->dish_OfMenu_Is(2, 1, 'Dish Two'); - - $this->given->theUser('Donald'); - $this->given->theUser('Peter'); - $this->given->theUser('Clark'); - - $this->given->_SelectedDish_ForMenu('Donald', 2, 1); - $this->given->_SelectedDish_ForMenu('Peter', 1, 1); - $this->given->_SelectedDish_ForMenu('Clark', 0, 1); - - $this->when->iAccessThePage(); - - $this->then->_shouldBe('order/user/0/selection/0/selected/title', 'Dish Two'); - $this->then->_shouldBe('order/user/0/selection/0/selected/_', 'Dish...'); - $this->then->_shouldBe('order/user/1/selection/0/selected/title', 'Dish One'); - $this->then->_shouldBe('order/user/1/selection/0/selected/_', 'Dish...'); - $this->then->_shouldBe('order/user/2/selection/0/selected/title', 'nothing'); - $this->then->_shouldBe('order/user/2/selection/0/selected/_', '-'); - } - -} - -/** - * @property SelectionsTest test - * @property SelectionsComponent component - */ -class SelectionsTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(SelectionsComponent::$CLASS, array( - 'orderInteractor' => $this->test->given->orderInteractor - )); - } - - public function iAccessThePage() { - $this->model = $this->component->doGet($this->test->given->order->id); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/order/SendMailTest.php b/spec/rtens/lacarte/web/order/SendMailTest.php deleted file mode 100644 index 1791e94..0000000 --- a/spec/rtens/lacarte/web/order/SendMailTest.php +++ /dev/null @@ -1,152 +0,0 @@ -given->anOrder_With_MenusEach_Dishes('Test', 0, 0); - $this->given->iHaveEnteredTheSubject('Hello'); - $this->given->iHaveEnteredTheBody('What up?'); - - $this->when->iSendTheMail(); - - $this->then->iShouldBeRedirectedTo('list.html'); - } - - function testSuccess() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('Test', 0, 0); - $this->given->iHaveEnteredTheSubject('Hello'); - $this->given->iHaveEnteredTheBody('What up?'); - - $this->when->iSendTheMail(); - - $this->then->aMailShouldBeSentToTheOrderWIthSubject_AndBody('Hello', 'What up?'); - $this->then->_shouldBe('success', 'Email was sent to users'); - $this->then->_shouldBe('error', null); - } - - function testOnlyWithout() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('Test', 0, 0); - $this->given->iHaveEnteredTheSubject('Hello'); - $this->given->iHaveEnteredTheBody('What up?'); - $this->given->iHaveSelectedToSendTheEmailOnlyToUsersWithoutSelection(); - - $this->when->iSendTheMail(); - - $this->then->aMailShouldBeSentToTheOrderWIthSubject_AndBody('Hello', 'What up?'); - $this->then->_shouldBe('success', 'Email was sent to users without selections'); - $this->then->_shouldBe('error', null); - } - - function testEmptyField() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('Test', 0, 0); - $this->given->iHaveEnteredTheSubject(''); - $this->given->iHaveEnteredTheBody('What up?'); - $this->given->iHaveSelectedToSendTheEmailOnlyToUsersWithoutSelection(); - - $this->when->iSendTheMail(); - - $this->then->aNoMailShouldBeSent(); - $this->then->_shouldBe('success', null); - $this->then->_shouldBe('error', 'Please fill out subject and body to send an email'); - - $this->then->_shouldBe('email/body', 'What up?'); - $this->then->_shouldBe('email/onlyWithout/checked', "checked"); - } - - function testError() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->anOrder_With_MenusEach_Dishes('Test', 0, 0); - $this->given->iHaveEnteredTheSubject('Hi'); - $this->given->iHaveEnteredTheBody('What up?'); - - $this->given->anErrorOccursWhileSending('Some bad thing'); - - $this->when->iSendTheMail(); - - $this->then->_shouldBe('error', 'Some bad thing'); - - $this->then->_shouldBe('email/subject/value', 'Hi'); - $this->then->_shouldBe('email/body', 'What up?'); - $this->then->_shouldBe('email/onlyWithout/checked', false); - } - -} - -/** - * @property SendMailTest test - */ -class SendMailTest_Given extends OrderTest_Given { - - public $onlyWithout = false; - public $subject; - public $body; - - public function iHaveEnteredTheSubject($string) { - $this->subject = $string; - } - - public function iHaveEnteredTheBody($string) { - $this->body = $string; - } - - public function iHaveSelectedToSendTheEmailOnlyToUsersWithoutSelection() { - $this->onlyWithout = true; - } - - public function anErrorOccursWhileSending($string) { - $this->orderInteractor->__mock()->method('sendMail')->willThrow(new \Exception($string)); - } -} - -/** - * @property SendMailTest test - * @property SelectionsComponent component - */ -class SendMailTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(SelectionsComponent::$CLASS, array( - 'orderInteractor' => $this->test->given->orderInteractor - )); - } - - public function iSendTheMail() { - $g = $this->test->given; - $this->model = $this->component->doSendMail($g->order->id, $g->subject, $g->body, $g->onlyWithout); - } -} - -/** - * @property SendMailTest test - */ -class SendMailTest_Then extends ComponentTest_Then { - - public function aMailShouldBeSentToTheOrderWIthSubject_AndBody($subject, $body) { - $method = $this->test->given->orderInteractor->__mock()->method('sendMail'); - $this->test->assertEquals(1, $method->getCalledCount()); - - $args = $method->getCalledArgumentsAt(0); - $this->test->assertEquals($subject, $args['subject']); - $this->test->assertEquals($body, $args['body']); - $this->test->assertEquals($this->test->given->order, $args['order']); - } - - public function aNoMailShouldBeSent() { - $this->test->assertFalse($this->test->given->orderInteractor->__mock()->method('sendMail')->wasCalled()); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/user/CreateUserTest.php b/spec/rtens/lacarte/web/user/CreateUserTest.php deleted file mode 100644 index 6f77cc3..0000000 --- a/spec/rtens/lacarte/web/user/CreateUserTest.php +++ /dev/null @@ -1,129 +0,0 @@ -given->iAmLoggedInAsAdmin(); - $this->given->iEnteredTheName('A Name'); - $this->given->iEnteredTheEmail('some@example.com'); - - $this->when->iCreateANewUser(); - - $this->then->aUserWithName_AndEmail_ShouldBeCreated('A Name', 'some@example.com'); - $this->then->_shouldBe('success', 'The user A Name was created.'); - } - - function testNotLoggedIn() { - $this->given->iEnteredTheName('A Name'); - $this->given->iEnteredTheEmail('some@example.com'); - - $this->when->iCreateANewUser(); - - $this->then->iShouldBeRedirectedTo('login.html'); - } - - function testNotAdmin() { - $this->given->iAmLoggedInAsUser(); - $this->given->iEnteredTheName('A Name'); - $this->given->iEnteredTheEmail('some@example.com'); - - $this->when->iCreateANewUser(); - - $this->then->thereShouldBeAnError('Access denied'); - } - - function testError() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->iEnteredTheName('My Name'); - $this->given->iEnteredTheEmail('some@Example.com'); - $this->given->anErrorOccurs('Some error'); - - $this->when->iCreateANewUser(); - - $this->then->_shouldBe('name/value', 'My Name'); - $this->then->_shouldBe('email/value', 'some@Example.com'); - $this->then->thereShouldBeAnError('Some error'); - } - -} - -/** - * @property CreateUserTest test - */ -class CreateUserTest_Given extends ComponentTest_Given { - - public $name; - public $email; - - /** @var \rtens\mockster\Mock|UserInteractor */ - public $userInteractor; - - function __construct(Test $test) { - parent::__construct($test); - $this->userInteractor = $test->mf->createMock(UserInteractor::$CLASS); - } - - public function iEnteredTheName($name) { - $this->name = $name; - } - - public function iEnteredTheEmail($email) { - $this->email = $email; - } - - public function anErrorOccurs($msg) { - $this->userInteractor->__mock()->method('createUser')->willThrow(new \Exception($msg)); - } -} - -/** - * @property CreateUserTest test - */ -class CreateUserTest_When extends ComponentTest_When { - - /** @var ListComponent */ - public $component; - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(ListComponent::$CLASS, array( - 'userInteractor' => $this->test->given->userInteractor - )); - } - - public function iCreateANewUser() { - $this->model = $this->component->doPost($this->test->given->name, $this->test->given->email); - } -} - -/** - * @property CreateUserTest test - */ -class CreateUserTest_Then extends ComponentTest_Then { - - public function thereShouldBeAnError($msg) { - $this->test->assertContains($msg, $this->getField('error')); - } - - public function aUserWithName_AndEmail_ShouldBeCreated($name, $email) { - $this->test->assertTrue( - $this->test->given->userInteractor->__mock()->method('createUser')->wasCalledWith(array( - $this->test->given->group->id, $name, $email - )), 'No user was created'); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/user/DeleteUserTest.php b/spec/rtens/lacarte/web/user/DeleteUserTest.php deleted file mode 100644 index 92ece64..0000000 --- a/spec/rtens/lacarte/web/user/DeleteUserTest.php +++ /dev/null @@ -1,59 +0,0 @@ -given->theUser('X'); - $this->when->iDeleteUser('X'); - $this->then->iShouldBeRedirectedTo('../order/list.html'); - } - - function testDelete() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->theUser('X'); - - $this->when->iDeleteUser('X'); - - $this->then->theUser_ShouldBeDeleted('X'); - } - -} - -/** - * @property DeleteUserTest test - * @property ListComponent component - */ -class DeleteUserTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(ListComponent::$CLASS); - } - - public function iDeleteUser($name) { - $this->component->doDelete($this->test->given->users[$name]->id); - } -} - -/** - * @property DeleteUserTest test - */ -class DeleteUserTest_Then extends ComponentTest_Then { - - public function theUser_ShouldBeDeleted($name) { - $method = $this->test->given->userInteractor->__mock()->method('delete'); - $this->test->assertTrue($method->wasCalled()); - $this->test->assertEquals($this->test->given->users[$name]->id, $method->getCalledArgumentAt(0, 0)->id); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/user/ListUsersTest.php b/spec/rtens/lacarte/web/user/ListUsersTest.php deleted file mode 100644 index d0b7792..0000000 --- a/spec/rtens/lacarte/web/user/ListUsersTest.php +++ /dev/null @@ -1,88 +0,0 @@ -given->iAmLoggedInAsAdmin(); - $this->when->iAccessThePage(); - $this->then->_shouldBe('user', array()); - } - - function testNonZeroUsers() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->theUser('UserA'); - $this->given->theUser('UserC'); - $this->given->theUser('UserB'); - - $this->when->iAccessThePage(); - - $this->then->_shouldHaveTheSize('user', 3); - } - - function testNotAdmin() { - $this->when->iAccessThePage(); - $this->then->iShouldBeRedirectedTo('../order/list.html'); - } - - function testAvatars() { - $this->given->iAmLoggedInAsAdmin(); - $this->given->theUser('UserA'); - $this->given->_HasAnAvatar('UserA'); - - $this->when->iAccessThePage(); - - $this->then->_shouldBe('user/0/avatar/src', 'http://lacarte/user/avatars/1.jpg'); - } - -} - -/** - * @property ListUsersTest test - */ -class ListUsersTest_Given extends ComponentTest_Given { - - /** @var UserInteractor */ - public $userInteractor; - - function __construct(Test $test) { - parent::__construct($test); - $this->userInteractor = $test->factory->getInstance(UserInteractor::$CLASS); - } - - public function theUser($string) { - $this->users[$string] = $this->userInteractor->createUser(1, $string, $string . '@example.com'); - } -} - -/** - * @property ListUsersTest test - * @property ListComponent component - */ -class ListUsersTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(ListComponent::$CLASS, array( - 'userInteractor' => $this->test->given->userInteractor, - 'files' => new FileRepository($this->test->config) - )); - } - - public function iAccessThePage() { - $this->model = $this->component->doGet(); - } -} \ No newline at end of file diff --git a/spec/rtens/lacarte/web/user/LoginTest.php b/spec/rtens/lacarte/web/user/LoginTest.php deleted file mode 100644 index f1c4806..0000000 --- a/spec/rtens/lacarte/web/user/LoginTest.php +++ /dev/null @@ -1,192 +0,0 @@ -given->iEnteredTheCorrectCredentialsForGroup('Group One'); - - $this->when->iLoginAsAdmin(); - - $this->then->theSessionShouldContain_WithValue('admin', 1); - $this->then->iShouldBeRedirectedTo('../order/list.html'); - } - - function testFail() { - $this->given->iHaveEnteredTheWrongCredentials('my@email.com', 'bla'); - - $this->when->iLoginAsAdmin(); - - $this->then->_shouldNotBeEmpty('error'); - $this->then->_shouldBe('email', 'my@email.com'); - } - - function testAccessPage() { - $this->when->iGoToTheLoginPage(); - $this->then->theModelShouldBe('{"error":null}'); - } - - function testAlreadyLoggedIn() { - $this->given->iAmAlreadyLoggedInForGroup('test'); - - $this->when->iGoToTheLoginPage(); - - $this->then->iShouldBeRedirectedTo('../order/list.html'); - } - - function testLogOut() { - $this->given->iAmAlreadyLoggedInForGroup('test'); - - $this->when->iLogOut(); - - $this->then->iShouldBeRedirectedTo('login.html'); - $this->then->theSessionShouldNotContain('admin'); - $this->then->theSessionShouldNotContain('key'); - } - - function testLogInWithKey() { - $this->given->theUser_WithKey_InGroup('Mark', 'myKey', 44); - $this->given->iHaveEnteredTheCorrectKey(); - - $this->when->iLoginAsUser(); - - $this->then->theSessionShouldContain_WithValue('key', 'myKey'); - $this->then->theSessionShouldNotContain('admin'); - } - - function testWrongKey() { - $this->given->iHaveEnteredAnIncorrectKey(); - $this->when->iLoginAsUser(); - $this->then->_shouldNotBeEmpty('error'); - } -} - -/** - * @property LoginTest test - */ -class LoginTest_Given extends ComponentTest_Given { - - /** - * @var UserInteractor|Mock - */ - public $userInteractor; - - public $email; - - public $password; - - /** - * @var Session|Mock - */ - public $session; - - /** @var User */ - public $user; - - function __construct(Test $test) { - parent::__construct($test); - $this->userInteractor = $this->test->mf->createMock(UserInteractor::$CLASS); - } - - public function iEnteredTheCorrectCredentialsForGroup($groupName) { - $group = new Group($groupName, '', ''); - $group->id = 1; - $this->userInteractor->__mock()->method('authorizeAdmin')->willReturn($group); - } - - public function iHaveEnteredTheWrongCredentials($email, $password) { - $this->userInteractor->__mock()->method('authorizeAdmin')->willReturn(null); - $this->email = $email; - $this->password = $password; - } - - public function iAmAlreadyLoggedInForGroup($groupName) { - $group = new Group($groupName, '', ''); - $group->id = 1; - $this->session->set('admin', $group->id); - } - - public function theUser_WithKey_InGroup($name, $key, $groupId) { - $this->user = new User($groupId, $name, "$name@example.com", $key); - } - - public function iHaveEnteredTheCorrectKey() { - $this->userInteractor->__mock()->method('authorizeUser')->willReturn($this->user); - } - - public function iHaveEnteredAnIncorrectKey() { - $this->userInteractor->__mock()->method('authorizeUser')->willReturn(null); - } -} - -/** - * @property LoginTest test - * @property LoginComponent component - */ -class LoginTest_When extends ComponentTest_When { - - function __construct(Test $test) { - parent::__construct($test); - $this->createDefaultComponent(LoginComponent::$CLASS, array( - 'userInteractor' => $this->test->given->userInteractor - )); - } - - public function iLoginAsAdmin() { - $this->model = $this->component->doLoginAdmin( - $this->test->given->email, $this->test->given->password); - } - - public function iGoToTheLoginPage() { - $this->model = $this->component->doGet(); - } - - public function iLogOut() { - $this->model = $this->component->doLogout(); - } - - public function iLoginAsUser() { - $this->model = $this->component->doPost('whatever'); - } -} - -/** - * @property LoginTest test - */ -class LoginTest_Then extends ComponentTest_Then { - - public function theSessionShouldContain_WithValue($field, $value) { - $this->test->assertEquals($value, $this->test->given->session->get($field)); - } - - public function theSessionShouldNotContain($key) { - $this->test->assertFalse($this->test->given->session->has($key)); - } -} \ No newline at end of file diff --git a/src/rtens/lacarte/UserInteractor.php b/src/rtens/lacarte/UserInteractor.php index d93cc10..16843b4 100644 --- a/src/rtens/lacarte/UserInteractor.php +++ b/src/rtens/lacarte/UserInteractor.php @@ -55,8 +55,16 @@ public function createUser($groupId, $name, $email) { $this->userStore->create($user); return $user; } catch (\PDOException $e) { - throw new \InvalidArgumentException('Error while creating user. The email probably already exists: ' - . $e->getMessage()); + throw new \InvalidArgumentException('Error while creating user. The email probably already exists.'); + } + } + + + public function updateUser(User $user) { + try { + $this->userStore->update($user); + } catch (\PDOException $e) { + throw new \InvalidArgumentException('Error while updating user. The email "' . $user->getEmail() . '" probably already exists.'); } } diff --git a/src/rtens/lacarte/core/FileRepository.php b/src/rtens/lacarte/core/FileRepository.php index fe0f563..5d15359 100644 --- a/src/rtens/lacarte/core/FileRepository.php +++ b/src/rtens/lacarte/core/FileRepository.php @@ -21,9 +21,17 @@ public function getFullPath($file) { return $this->config->getUserFilesDirectory() . '/' . $file; } + public function getUserFilesDirectory() { + return $this->config->getUserFilesDirectory(); + } + public function getUserAvatarUrl($user, Module $root) { $file = $this->exists('avatars/' . $user->id . '.jpg') ? $user->id . '.jpg' : 'default.png'; return $this->config->getHost(). $root->getRoute()->toString() . '/user/avatars/' . $file; } + public function moveUploadedFile($from, $to) { + return move_uploaded_file($from, $to); + } + } diff --git a/src/rtens/lacarte/model/User.php b/src/rtens/lacarte/model/User.php index d91fce7..66ae017 100644 --- a/src/rtens/lacarte/model/User.php +++ b/src/rtens/lacarte/model/User.php @@ -33,7 +33,7 @@ public function getEmail() { } public function setEmail($email) { - $this->email = $email; + $this->email = strtolower($email); } public function getGroupId() { diff --git a/src/rtens/lacarte/model/stores/DishStore.php b/src/rtens/lacarte/model/stores/DishStore.php index f09cf1c..d93d5b7 100644 --- a/src/rtens/lacarte/model/stores/DishStore.php +++ b/src/rtens/lacarte/model/stores/DishStore.php @@ -8,10 +8,17 @@ class DishStore extends Store { public static $CLASS = __CLASS__; + /** + * @param $id + * @return Set|Dish[] + */ public function readAllByMenuId($id) { return $this->inflateAll($this->db->readAll('SELECT * FROM dishes WHERE menuId = ?', array($id))); } + /** + * @return Set|Dish[] + */ public function readAll() { return $this->inflateAll($this->db->readAll('SELECT * FROM dishes')); } diff --git a/src/rtens/lacarte/model/stores/GroupStore.php b/src/rtens/lacarte/model/stores/GroupStore.php index 31be6d3..a05849e 100644 --- a/src/rtens/lacarte/model/stores/GroupStore.php +++ b/src/rtens/lacarte/model/stores/GroupStore.php @@ -28,4 +28,8 @@ public function readById($id) { array($id))); } + public function update(Group $group) { + $this->updateEntity($group, 'groups'); + } + } diff --git a/src/rtens/lacarte/model/stores/OrderStore.php b/src/rtens/lacarte/model/stores/OrderStore.php index adba31f..b2cfadd 100644 --- a/src/rtens/lacarte/model/stores/OrderStore.php +++ b/src/rtens/lacarte/model/stores/OrderStore.php @@ -12,6 +12,9 @@ public function create($order) { $this->createEntity($order, 'orders'); } + /** + * @return Set|Order[] + */ public function readAll() { return $this->inflateAll($this->db->readAll('SELECT * FROM orders')); } diff --git a/src/rtens/lacarte/model/stores/SelectionStore.php b/src/rtens/lacarte/model/stores/SelectionStore.php index c6cc2d4..d493a98 100644 --- a/src/rtens/lacarte/model/stores/SelectionStore.php +++ b/src/rtens/lacarte/model/stores/SelectionStore.php @@ -2,6 +2,7 @@ namespace rtens\lacarte\model\stores; use rtens\lacarte\model\Selection; +use watoki\collections\Set; class SelectionStore extends Store { @@ -16,6 +17,9 @@ protected function inflate($row) { return $selection; } + /** + * @return Set|Selection[] + */ public function readAll() { return $this->inflateAll($this->db->readAll('SELECT * FROM selections')); } diff --git a/src/rtens/lacarte/model/stores/UserStore.php b/src/rtens/lacarte/model/stores/UserStore.php index b2bca21..1d6f1c9 100644 --- a/src/rtens/lacarte/model/stores/UserStore.php +++ b/src/rtens/lacarte/model/stores/UserStore.php @@ -1,7 +1,6 @@ createEntity($user, 'users'); } + public function update(User $user) { + $this->updateEntity($user, 'users'); + } + + /** + * @param string $email + * @return User + */ public function readByEmail($email) { return $this->inflate($this->db->readOne("SELECT * FROM users WHERE email = ?", array($email))); } + /** + * @param string $key + * @return User + */ public function readByKey($key) { return $this->inflate($this->db->readOne("SELECT * FROM users WHERE \"key\" = ?", array($key))); @@ -35,19 +46,26 @@ public function isKeyExisting($key) { return $result['count'] != 0; } + /** + * @return Liste|User[] + */ public function readAll() { return $this->inflateAll($this->db->readAll("SELECT * FROM users ORDER BY name ASC"), new Liste()); } /** * @param Group $group - * @return array|\watoki\collections\Set|User[] + * @return Liste|User[] */ public function readAllByGroup(Group $group) { return $this->inflateAll($this->db->readAll('SELECT * FROM users WHERE groupId = ? ORDER BY name', array($group->id)), new Liste()); } + /** + * @param int $id + * @return User + */ public function readById($id) { return $this->inflate($this->db->readOne('SELECT * FROM users WHERE id = ?', array($id))); } diff --git a/src/rtens/lacarte/web/common/css/bootstrap.css b/src/rtens/lacarte/web/common/css/bootstrap.css index f83f7c2..f64c23b 100644 --- a/src/rtens/lacarte/web/common/css/bootstrap.css +++ b/src/rtens/lacarte/web/common/css/bootstrap.css @@ -2286,7 +2286,7 @@ table th[class*="span"], *margin-right: .3em; line-height: 14px; vertical-align: text-top; - background-image: url("../img/glyphicons-halflings.png"); + background-image: url("img/glyphicons-halflings.png"); background-position: 14px 14px; background-repeat: no-repeat; } @@ -2310,7 +2310,7 @@ table th[class*="span"], .dropdown-submenu:focus > a > [class^="icon-"], .dropdown-submenu:hover > a > [class*=" icon-"], .dropdown-submenu:focus > a > [class*=" icon-"] { - background-image: url("../img/glyphicons-halflings-white.png"); + background-image: url("img/glyphicons-halflings-white.png"); } .icon-glass { @@ -3323,6 +3323,11 @@ button.close { border-radius: 3px; } +.btn-upload { + width: 30px; + height: 30px; +} + .btn-block { display: block; width: 100%; @@ -3479,6 +3484,10 @@ input[type="button"].btn-block { *background-color: #499249; } +.btn-doubleWidth { + width: 78px; +} + .btn-success:active, .btn-success.active { background-color: #408140 \9; diff --git a/src/rtens/lacarte/web/common/css/img/glyphicons-halflings-white.png b/src/rtens/lacarte/web/common/css/img/glyphicons-halflings-white.png new file mode 100644 index 0000000..3bf6484 Binary files /dev/null and b/src/rtens/lacarte/web/common/css/img/glyphicons-halflings-white.png differ diff --git a/src/rtens/lacarte/web/common/css/img/glyphicons-halflings.png b/src/rtens/lacarte/web/common/css/img/glyphicons-halflings.png new file mode 100644 index 0000000..a996999 Binary files /dev/null and b/src/rtens/lacarte/web/common/css/img/glyphicons-halflings.png differ diff --git a/src/rtens/lacarte/web/order/SelectionComponent.php b/src/rtens/lacarte/web/order/SelectionComponent.php index 92bd998..1584a0b 100644 --- a/src/rtens/lacarte/web/order/SelectionComponent.php +++ b/src/rtens/lacarte/web/order/SelectionComponent.php @@ -1,6 +1,7 @@ $this->assembleOrder($this->orderInteractor->readById($order)), 'error' => null )); + } catch (NotFoundException $nfe) { + return $this->assembleModel(array( + 'order' => null, + 'error' => 'You seem to have no selections for this order.' + )); } catch (\Exception $e) { return $this->assembleModel(array( 'order' => null, diff --git a/src/rtens/lacarte/web/user/ListComponent.php b/src/rtens/lacarte/web/user/ListComponent.php index 8fa293f..76f39cb 100644 --- a/src/rtens/lacarte/web/user/ListComponent.php +++ b/src/rtens/lacarte/web/user/ListComponent.php @@ -30,10 +30,16 @@ public function doGet() { if (!$this->isAdmin()) { return $this->redirect(Url::parse('../order/list.html')); } - return $this->assembleModel(); } + public function doEdit($user) { + if (!$this->isAdmin()) { + return $this->redirect(Url::parse('../order/list.html')); + } + return $this->assembleModel(array(), $user); + } + public function doPost($name, $email) { if (!$this->isLoggedIn()) { return $this->redirect(Url::parse('login.html')); @@ -41,7 +47,9 @@ public function doPost($name, $email) { if (!$this->isAdmin()) { return $this->assembleModel(array( - 'error' => 'Access denied. Must be administrator.' + 'error' => 'Access denied. Must be administrator.', + 'email' => array('value' => $email), + 'name' => array('value' => $name) )); } @@ -75,11 +83,64 @@ public function doDelete($user) { )); } - protected function assembleModel($model = array()) { + public function doSave($name, $email, $userId) { + if (!$this->isAdmin()) { + return $this->redirect(Url::parse('../order/list.html')); + } + + if (isset($_FILES['picture']) && $_FILES['picture']['name']) { + $picture = $_FILES['picture']['name']; + $pictureTmp = $_FILES['picture']['tmp_name']; + + if ('jpg' != strtolower(substr($picture, strrpos($picture, '.') + 1))) { + return $this->assembleModel(array( + 'error' => 'Only jpg-files allowed.', + 'notEditing' => null, + 'editing' => $this->assembleEditingUser($userId, $name, $email) + )); + }; + + $avatarDir = $this->files->getUserFilesDirectory() . '/avatars'; + $avatarPath = $avatarDir . '/' . $userId . '.jpg'; + + @mkdir($avatarDir, 0777, true); + if(!$this->files->moveUploadedFile($pictureTmp, $avatarPath)) { + return $this->assembleModel(array( + 'error' => 'There was an error uploading the file, please try again!' + )); + } + } + + $user = $this->userInteractor->readById($userId); + if(!$email || !$name) { + return $this->assembleModel(array( + 'error' => 'Could not update user. Missing data.', + 'notEditing' => null, + 'editing' => $this->assembleEditingUser($userId, $name, $email) + ), $userId); + } + $user->setEmail($email); + $user->setName($name); + try { + $this->userInteractor->updateUser($user); + return $this->assembleModel(array( + 'success' => 'The user has been updated' + )); + } catch (\Exception $e) { + return $this->assembleModel(array( + 'error' => $e->getMessage() + )); + } + } + + protected function assembleModel($model = array(), $userId = null) { + $editing = $this->assembleEditing($userId); return parent::assembleModel(array_merge(array( 'user' => $this->assembleUsers(), 'error' => null, - 'success' => null + 'success' => null, + 'notEditing' => !$editing, + 'editing' => $editing ), $model)); } @@ -106,4 +167,26 @@ private function assembleUsers() { return $users; } + private function assembleEditing($userId) { + if (!$userId) { + return null; + } + $user = $this->userInteractor->readById($userId); + return $this->assembleEditingUser($userId, $user->getName(), $user->getEmail()); + } + + private function assembleEditingUser($userId, $name, $email) { + return array( + 'name' => array( + 'value' => $name + ), + 'email' => array( + 'value' => $email, + ), + 'id' => array( + 'value' => $userId, + ), + ); + } + } diff --git a/src/rtens/lacarte/web/user/list.html b/src/rtens/lacarte/web/user/list.html index 308949c..69f3c20 100644 --- a/src/rtens/lacarte/web/user/list.html +++ b/src/rtens/lacarte/web/user/list.html @@ -23,7 +23,7 @@

Users

An error occurred.
An error occurred.
-
+ @@ -36,8 +36,9 @@

Users

- - + + + + + + + + + @@ -63,6 +86,7 @@

Users

+
@@ -50,7 +51,29 @@

Users

will be generated - + +
+ + +
+ +
+
+
+ +
+
+ + can't be edited + +
max@mustermann.de f65627783606164dc3fde108b791c + edit delete