Skip to content

Commit d2f2ffd

Browse files
authored
Merge pull request #7 from curiosity26/rc-0.2.4
RC0.2.4
2 parents 0ce066b + 7420e6d commit d2f2ffd

File tree

15 files changed

+697
-254
lines changed

15 files changed

+697
-254
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,7 @@ com_crashlytics_export_strings.xml
5252
crashlytics.properties
5353
crashlytics-build.properties
5454
fabric.properties
55+
56+
phpunit.xml
57+
/Tests/logs/
58+
/Tests/cache/

.idea/AngularMaterialBundle.iml

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/codeStyleSettings.xml

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php-test-framework.xml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Controller/TestController.php

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: alexboyce
5+
* Date: 4/2/17
6+
* Time: 12:42 PM
7+
*/
8+
9+
namespace Curiosity26\AngularMaterialBundle\Controller;
10+
11+
12+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
13+
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
14+
use Symfony\Component\Form\Extension\Core\Type\TextType;
15+
16+
/**
17+
* Class TestController
18+
* @package Curiosity26\AngularMaterialBundle\Tests\Controller
19+
*/
20+
class TestController extends Controller
21+
{
22+
/**
23+
* @return \Symfony\Component\HttpFoundation\Response
24+
*/
25+
public function textAction()
26+
{
27+
$builder = $this->createFormBuilder();
28+
29+
$builder->add('test', TextType::class);
30+
31+
$form = $builder->getForm();
32+
33+
return $this->render('form.html.twig', [
34+
'form' => $form->createView()
35+
]);
36+
}
37+
38+
/**
39+
* @return \Symfony\Component\HttpFoundation\Response
40+
*/
41+
public function radioAction()
42+
{
43+
$builder = $this->createFormBuilder();
44+
45+
$builder->add('test', ChoiceType::class, [
46+
'choices' => [
47+
'Test 1' => 'test1',
48+
'Test 2' => 'test2',
49+
],
50+
'choices_as_values' => true,
51+
'multiple' => false,
52+
'expanded' => true,
53+
]);
54+
55+
$form = $builder->getForm();
56+
57+
return $this->render('form.html.twig', [
58+
'form' => $form->createView()
59+
]);
60+
}
61+
62+
/**
63+
* @return \Symfony\Component\HttpFoundation\Response
64+
*/
65+
public function checkboxAction()
66+
{
67+
$builder = $this->createFormBuilder();
68+
69+
$builder->add('test', ChoiceType::class, [
70+
'choices' => [
71+
'Test 1' => 'test1',
72+
'Test 2' => 'test2',
73+
],
74+
'choices_as_values' => true,
75+
'multiple' => true,
76+
'expanded' => true,
77+
]);
78+
79+
$form = $builder->getForm();
80+
81+
return $this->render('form.html.twig', [
82+
'form' => $form->createView()
83+
]);
84+
}
85+
86+
/**
87+
* @return \Symfony\Component\HttpFoundation\Response
88+
*/
89+
public function selectAction()
90+
{
91+
$builder = $this->createFormBuilder();
92+
93+
$builder->add('test', ChoiceType::class, [
94+
'choices' => [
95+
'Test 1' => 'test1',
96+
'Test 2' => 'test2',
97+
],
98+
'choices_as_values' => true,
99+
'multiple' => false,
100+
'expanded' => false,
101+
]);
102+
103+
$form = $builder->getForm();
104+
105+
return $this->render('form.html.twig', [
106+
'form' => $form->createView()
107+
]);
108+
}
109+
}

Resources/Form/material_1_layout.html.twig

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -55,40 +55,32 @@
5555
{%- block choice_widget_expanded -%}
5656
{%- set ng_model = full_name|replace({'[': '.', ']': ''}) -%}
5757
{% if multiple %}
58-
{{ block('checkbox_group', {form: form, ng_model: ng_model}) }}
58+
<md-checkbox-group {{ block('widget_container_attributes') }} layout="column">
59+
{%- for child in form %}
60+
{{- form_widget(child, {ng_model: ng_model}) -}}
61+
{% endfor -%}
62+
</md-checkbox-group>
5963
{% else %}
60-
{{ block('radio_group', {form: form, ng_model: ng_model}) }}
64+
{%- set ng_model = full_name|replace({'[': '.', ']': ''}) -%}
65+
<md-radio-group {{ block('widget_container_attributes') }} layout="column">
66+
{%- for child in form %}
67+
{{- form_widget(child, {form: form, ng_model: ng_model}) -}}
68+
{% endfor -%}
69+
</md-radio-group>
6170
{% endif %}
6271
{%- endblock choice_widget_expanded -%}
6372

64-
{% block checkbox_group %}
65-
<md-checkbox-group {{ block('widget_container_attributes') }} layout="column">
66-
{%- for child in form %}
67-
{{- form_widget(child, {ng_model: ng_model}) -}}
68-
{% endfor -%}
69-
</md-checkbox-group>
70-
{% endblock %}
71-
7273
{%- block checkbox_widget -%}
7374
{%- set model_name = ng_model ?: full_name|replace({'[': '.', ']': ''}) -%}
7475
{%- set ng_value = value matches '/^\\d+$/' ? value : "'" ~ value|replace({"'": "\\'"}) ~ "'" -%}
7576
<md-checkbox {% if ng_model is defined %}ng-checked="isChecked({{ ng_model }}, {{ ng_value }})" ng-click="{{ ng_model }} = toggleCheckbox({{ ng_model }}, {{ ng_value }})"{% else %}ng-model="{{ model_name }}" ng-click="{{ ng_model }} = {{ ng_value }}"{% endif %} {% if value is defined %} ng-yes-value="{{ value }}" {% endif %}{% if checked %} ng-init="{{ model_name }} = toggleCheckbox({{ model_name }}, {{ ng_value }})"{% endif %}>
7677
<span hide>
7778
<input type="checkbox" {% if ng_model is defined %}ng-checked="isChecked({{ ng_model }}, {{ ng_value }})" ng-click="{{ ng_model }} = toggleCheckbox({{ ng_model }}, {{ ng_value }})"{% else %}ng-model="{{ model_name }}"{% endif %} {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %}{% if checked %} checked="checked"{% endif %}>
7879
</span>
79-
{{- form_label(form) -}}
80+
{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}
8081
</md-checkbox>
8182
{%- endblock checkbox_widget -%}
8283

83-
{% block radio_group %}
84-
{%- set ng_model = full_name|replace({'[': '.', ']': ''}) -%}
85-
<md-radio-group {{ block('widget_container_attributes') }} layout="column">
86-
{%- for child in form %}
87-
{{- form_widget(child, {form: form, ng_model: ng_model}) -}}
88-
{% endfor -%}
89-
</md-radio-group>
90-
{% endblock radio_group %}
91-
9284
{%- block radio_widget -%}
9385
{%- set ng_value = value matches '/^\\d+$/' ? value : "'" ~ value|replace({"'": "\\'"}) ~ "'" -%}
9486
{%- if ng_model is not defined %}
@@ -98,7 +90,7 @@
9890
<span hide>
9991
<input type="radio" {{ block('widget_attributes') }}{% if value is defined %} value="{{ value }}"{% endif %} ng-checked="isRadioSelected({{ ng_model }}, {{ ng_value }})">
10092
</span>
101-
{{- form_label(form) -}}
93+
{{ translation_domain is same as(false) ? label : label|trans({}, translation_domain) }}
10294
</md-radio-button>
10395
{%- endblock radio_widget -%}
10496

Tests/AppKernel.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
/**
4+
* Created by PhpStorm.
5+
* User: alexboyce
6+
* Date: 4/2/17
7+
* Time: 12:33 PM
8+
*/
9+
namespace Curiosity26\AngularMaterialBundle\Tests;
10+
11+
use Curiosity26\AngularMaterialBundle\Curiosity26AngularMaterialBundle;
12+
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
13+
use Symfony\Bundle\TwigBundle\TwigBundle;
14+
15+
class AppKernel extends \Symfony\Component\HttpKernel\Kernel
16+
{
17+
public function registerBundles()
18+
{
19+
return [
20+
new FrameworkBundle(),
21+
new TwigBundle(),
22+
new Curiosity26AngularMaterialBundle(),
23+
];
24+
}
25+
26+
public function registerContainerConfiguration(
27+
\Symfony\Component\Config\Loader\LoaderInterface $loader
28+
) {
29+
$loader->load(__DIR__ . '/config/config.yml');
30+
}
31+
32+
public function getRootDir()
33+
{
34+
return __DIR__;
35+
}
36+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<html>
2+
<head>
3+
<link rel="stylesheet" type="text/css" href="{{ asset('bundles/curiosity26angularmaterial/components/angular-material/angular-material.min.css') }}">
4+
</head>
5+
<body ng-app="app">
6+
{{ form(form) }}
7+
<!-- Wire-Up the Angular assets -->
8+
<script src="{{ asset('bundles/curiosity26angularmaterial/components/angular/angular.min.js') }}"></script>
9+
<script src="{{ asset('bundles/curiosity26angularmaterial/components/angular-animate/angular-animate.min.js') }}"></script>
10+
<script src="{{ asset('bundles/curiosity26angularmaterial/components/angular-aria/angular-aria.min.js') }}"></script>
11+
<script src="{{ asset('bundles/curiosity26angularmaterial/components/angular-messages/angular-messages.min.js') }}"></script>
12+
<script src="{{ asset('bundles/curiosity26angularmaterial/components/angular-material/angular-material.min.js') }}"></script>
13+
<script src="{{ asset('bundles/curiosity26angularmaterial/js/mdform.js') }}"></script>
14+
<script src="{{ asset('bundles/curiosity26angularmaterial/js/mdaddons.js') }}"></script>
15+
<script type="text/javascript">
16+
(function() {
17+
angular.module('app', ['symfony.mdForm', 'symfony.mdAddons']);
18+
})();
19+
</script>
20+
</body>
21+
</html>

Tests/TestControllerTest.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Created by PhpStorm.
4+
* User: alexboyce
5+
* Date: 4/2/17
6+
* Time: 12:45 PM
7+
*/
8+
9+
class TestControllerTest extends \Symfony\Bundle\FrameworkBundle\Test\WebTestCase
10+
{
11+
protected static $class = '\Curiosity26\AngularMaterialBundle\Tests\AppKernel';
12+
13+
public function testTextAction()
14+
{
15+
$client = static::createClient();
16+
$crawler = $client->request('GET', '/test/text');
17+
18+
$this->assertEquals('200', $client->getResponse()->getStatusCode());
19+
20+
$container = $crawler->filter("form md-input-container");
21+
22+
$this->assertNotEmpty($container);
23+
24+
$label = $container->filter('label');
25+
26+
$this->assertEquals('Test', $label->text());
27+
28+
$input = $container->filter('input');
29+
30+
$this->assertEquals(['text'], $input->extract(['type']));
31+
}
32+
33+
public function testRadioAction()
34+
{
35+
$client = static::createClient();
36+
$crawler = $client->request('GET', '/test/radio');
37+
38+
$this->assertEquals('200', $client->getResponse()->getStatusCode());
39+
40+
$input = $crawler->filter("form md-radio-group md-radio-button");
41+
$this->assertNotEmpty($input);
42+
$this->assertEquals(['test1'], $input->eq(0)->extract(['value']));
43+
$this->assertEquals('Test 1', trim($input->eq(0)->text()));
44+
$this->assertEquals(['test2'], $input->eq(1)->extract(['value']));
45+
$this->assertEquals('Test 2', trim($input->eq(1)->text()));
46+
}
47+
48+
public function testCheckboxAction()
49+
{
50+
$client = static::createClient();
51+
$crawler = $client->request('GET', '/test/checkbox');
52+
53+
$this->assertEquals('200', $client->getResponse()->getStatusCode());
54+
55+
$input = $crawler->filter("form md-checkbox-group md-checkbox");
56+
$this->assertNotEmpty($input);
57+
$this->assertEquals(['test1'], $input->eq(0)->extract(['ng-yes-value']));
58+
$this->assertEquals('Test 1', trim($input->eq(0)->text()));
59+
$this->assertEquals(['test2'], $input->eq(1)->extract(['ng-yes-value']));
60+
$this->assertEquals('Test 2', trim($input->eq(1)->text()));
61+
}
62+
63+
public function testSelectAction()
64+
{
65+
$client = static::createClient();
66+
$crawler = $client->request('GET', '/test/select');
67+
68+
$this->assertEquals('200', $client->getResponse()->getStatusCode());
69+
70+
$input = $crawler->filter("form md-select md-option");
71+
$this->assertNotEmpty($input);
72+
$this->assertEquals(['test1'], $input->eq(0)->extract(['value']));
73+
$this->assertEquals('Test 1', trim($input->eq(0)->text()));
74+
$this->assertEquals(['test2'], $input->eq(1)->extract(['value']));
75+
$this->assertEquals('Test 2', trim($input->eq(1)->text()));
76+
}
77+
78+
}

0 commit comments

Comments
 (0)