Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added alias field, callback and tags_title inserttag #6

Closed
wants to merge 13 commits into from
Closed

added alias field, callback and tags_title inserttag #6

wants to merge 13 commits into from

Conversation

Defcon0
Copy link

@Defcon0 Defcon0 commented Sep 4, 2017

Hi @qzminski ,

we just added an alias field to your tags_bundle and would very much appreciate it if you could merge the commit into the main project. The commit in detail contains:

  • an alias field
  • the necessary callbacks
  • the global select option for batch generating aliases
  • localization for English
  • an insert tag called "tags_title" that outputs a tag's title by inserting a source name and the id or the alias of a tag

We also added the translation for German for all existing strings.

@coveralls
Copy link

Coverage Status

Coverage decreased (-35.9%) to 64.078% when pulling 0638264 on heimrichhannot:alias into 09e31d9 on codefog:master.

@Defcon0
Copy link
Author

Defcon0 commented Sep 4, 2017

@qzminski Is there something I can do about the coveralls issue?

@coveralls
Copy link

Coverage Status

Coverage decreased (-35.9%) to 64.078% when pulling 5b2aeaf on heimrichhannot:alias into 09e31d9 on codefog:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-35.9%) to 64.078% when pulling e71156c on heimrichhannot:alias into 09e31d9 on codefog:master.

Copy link
Member

@qzminski qzminski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to comments in the review please provide unit tests that will keep the code coverage at the same level and apply the code style (php-cs-fixer is a dev requirement already).

composer.json Outdated
@@ -1,5 +1,5 @@
{
"name": "codefog/tags-bundle",
"name": "heimrichhannot/tags-bundle",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

*
* @throws \Exception
*/
public function generateAlias($value, DataContainer $dc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole method needs to be reworked to use strict types and comparisons, database service, etc.

*
* @return array
*/
public function addAliasButton($buttons, \DataContainer $dc)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole method needs to be reworked to use strict types and comparisons, database service, etc.

switch ($insertTag) {
case 'tags_title':
return $tags->first()->name;
break;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This break statement is not needed here.

break;
}

return '';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should throw an exception here and not return an empty string.

@@ -190,7 +190,7 @@ private function createTag(string $value): Tag
*
* @return array
*/
private function getCriteria(array $criteria = []): array
protected function getCriteria(array $criteria = []): array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason you changed the properties and methods visibility?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We adjusted it so that inheriting services can use the attributes and methods themselves without needing to redefine them.

throw new NoTagsException();
}

$columns[] = 'alias IN ('.implode(',', array_map(function($alias) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just use "alias IN ('" . implode("','", $criteria['aliases']) . "')".

'inputType' => 'text',
'eval' => ['rgxp' => 'alias', 'unique' => true, 'maxlength' => 128, 'tl_class' => 'w50'],
'save_callback' => [['codefog_tags.listener.data_container.tag', 'generateAlias']],
'sql' => "varchar(128) COLLATE utf8_bin NOT NULL default ''",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please adjust the SQL format just like it is for the other fields.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, I can do that, but at the moment I have no idea how to define the collation:

I tried 'collation' => 'utf8_bin' and 'collate' => 'utf8_bin'. None of them worked out :-(

@coveralls
Copy link

Coverage Status

Coverage decreased (-35.9%) to 64.078% when pulling 7228b6f on heimrichhannot:alias into 09e31d9 on codefog:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-36.2%) to 63.768% when pulling c3adb7f on heimrichhannot:alias into 09e31d9 on codefog:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-29.8%) to 70.192% when pulling 5755bc9 on heimrichhannot:alias into 09e31d9 on codefog:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-29.8%) to 70.192% when pulling 5755bc9 on heimrichhannot:alias into 09e31d9 on codefog:master.

@Defcon0
Copy link
Author

Defcon0 commented Sep 7, 2017

Still working on the tests. I'll write again after finishing the work.

@coveralls
Copy link

Coverage Status

Coverage decreased (-29.8%) to 70.192% when pulling 4e52293 on heimrichhannot:alias into 09e31d9 on codefog:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-29.3%) to 70.673% when pulling 7d6b636 on heimrichhannot:alias into 09e31d9 on codefog:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-28.8%) to 71.154% when pulling bb113f6 on heimrichhannot:alias into 09e31d9 on codefog:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-20.3%) to 79.67% when pulling 16297a1 on heimrichhannot:alias into 09e31d9 on codefog:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.8%) to 98.182% when pulling ef72db2 on heimrichhannot:alias into 09e31d9 on codefog:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.2%) to 98.788% when pulling ad86446 on heimrichhannot:alias into 09e31d9 on codefog:master.

@Defcon0
Copy link
Author

Defcon0 commented Sep 8, 2017

OK, I'm done with the tests. Some thoughts on them:

  1. I didn't do testing that much, escpecially not for Contao 4/Symfony, so it might not be perfect ;-)
  2. The last code coverage issues are a bit obscure to me:

in /src/EventListener/InsertTagsListener.php on

line 89: When debugging the test case in my local phpStorm, the debugger jumps at this line, so it indeed is covered. Might be an issue in coveralls??

line 109: How can I cover this line if it's logically never reached? An unsupported tag is filtered out beforehands. So the interpreter can't reach this line at all.

  1. I ignored "addAliasButton" in TagListener.php since the function contains database, session and version handling. All of this taken from Contao Core and they don't test it either since the code isn't very testable at all. In addition the effort for doing so is much too high in my opinion. If you have any hint for me how to test it in a pragmatic way, you're very welcome ;-)

So is the request now ready for pulling?

@qzminski
Copy link
Member

I guess I will have to tweak this PR a little bit and write the tests in a correct way but in general looks good. Because of the changes I have to make this will be merged in the upcoming weeks. Thanks @Defcon0 !

@Defcon0
Copy link
Author

Defcon0 commented Sep 12, 2017

@qzminski Great to hear that :-) I'll review the tweaked tests to do it better next time ;-)

qzminski added a commit that referenced this pull request Oct 9, 2017
@qzminski
Copy link
Member

Hey @Defcon0 some of the features have been already implemented on the develop branch. It was just easier for me to pick up the necessary code/concept chunks and put individually there instead of merging this big PR, hope that's fine 😉 I am still about to add the insert tags listener there, so please be patient!

@qzminski qzminski closed this Nov 9, 2017
@fatcrobat fatcrobat deleted the alias branch November 23, 2017 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

None yet

3 participants